in pulseapi/entries/views.py [0:0]
def get_queryset(self):
user = self.request.user
# Get all entries: if this is a normal call without a
# specific moderation state, we return the set of
# public entries. However, if moderation state is
# explicitly requrested, and the requesting user has
# permissions to change entries by virtue of being
# either a moderator or superuser, we return all
# entries, filtered for the indicated moderation state.
queryset = False
query_params = self.request.query_params
modstate = query_params.get('moderationstate', None)
if modstate is not None:
is_superuser = user.is_superuser
is_moderator = user.has_perm('entries.change_entry')
if is_superuser is True or is_moderator is True:
mvalue = ModerationState.objects.get(name=modstate)
if mvalue is not None:
queryset = Entry.objects.filter(moderation_state=mvalue)
if queryset is False:
queryset = Entry.objects.public().with_related().by_active_profile()
# If the query was for a set of specific entries,
# filter the query set further.
ids = query_params.get('ids', None)
if ids is not None:
try:
ids = [int(x) for x in ids.split(',')]
queryset = queryset.filter(pk__in=ids)
except ValueError:
pass
creators = query_params.get('creators', None)
# If the query was for a set of entries by specifc creators,
# filter the query set further.
if creators is not None:
creator_names = creators.split(',')
# Filter only those entries by looking at their relationship
# with creators (using the 'related_creators' field, which is
# the OrderedCreatorRecord relation), and then getting each
# relation's associated "creator" and making sure that the
# creator's name is in the list of creator names specified
# in the query string.
#
# This is achieved by Django by relying on namespace manging,
# explained in the python documentation, specifically here:
#
# https://docs.python.org/3/tutorial/classes.html#private-variables-and-class-local-references
queryset = queryset.filter(
Q(related_entry_creators__profile__custom_name__in=creator_names) |
Q(related_entry_creators__profile__related_user__name__in=creator_names)
)
return queryset