Get a QuerySet of User objects of students in the activity. Needed for the
        EighthScheduledActivitySerializer.

        Returns: QuerySet
511718
def get_viewable_members_serializer(self, request):
        
        ids = []
        user = request.user
        for member in self.members.all():
            show = False
            if member.can_view_eighth:
                show = member.can_view_eighth

            if not show and user and user.is_eighth_admin:
                show = True
            if not show and user and user.is_teacher:
                show = True
            if not show and member == user:
                show = True

            if show:
                ids.append(member.id)

        return User.objects.filter(id__in=ids)
100781
def get_queryset(self):
        ""
        qs = super().get_queryset()

        qs = qs.select_related('publication__series') \
                .prefetch_related('publication__roles__creator')

        return qs
642484
def get_object(self, queryset=None):
        
        if queryset is None:
            queryset = self.get_queryset()

        try:
            return queryset.get(user__pk=self.request.user.pk)
        except ObjectDoesNotExist:
            raise Http404
121775
def get_class_students(self, xqdm, kcdm, jxbh):
        
        return self.query(GetClassStudents(xqdm, kcdm, jxbh))
89396
def get_students(self):
        """"""
        users = User.objects.filter(user_type="student", graduation_year__gte=settings.SENIOR_GRADUATION_YEAR)
        users = users.exclude(id__in=EXTRA)

        return users
1243529
def get_queryset(self):
        
        self.entries_qs = Entry.published.all()
        return Tag.objects.usage_for_queryset(
            self.entries_qs, counts=True)
554817
def get_user_lists(self, course, aggregationid=''):
        
        tutor_list = course.get_staff()

        # Determine student list and if they are grouped
        student_list = list(self.database.aggregations.aggregate([
            {"$match": {"courseid": course.get_id()}},
            {"$unwind": "$students"},
            {"$project": {
                "classroom": "$_id",
                "students": 1,
                "grouped": {
                    "$anyElementTrue": {
                        "$map": {
                            "input": "$groups.students",
                            "as": "group",
                            "in": {
                                "$anyElementTrue": {
                                    "$map": {
                                        "input": "$$group",
                                        "as": "groupmember",
                                        "in": {"$eq": ["$$groupmember", "$students"]}
                                    }
                                }
                            }
                        }
                    }
                }
            }}
        ]))

        student_list = dict([(student["students"], student) for student in student_list])
        users_info = self.user_manager.get_users_info(list(student_list.keys()) + tutor_list)

        if aggregationid:
            # Order the non-registered students
            other_students = [student_list[entry]['students'] for entry in student_list.keys() if
                              not student_list[entry]['classroom'] == ObjectId(aggregationid)]
            other_students = sorted(other_students, key=lambda val: (("0"+users_info[val][0]) if users_info[val] else ("1"+val)))

            return student_list, tutor_list, other_students, users_info
        else:
            return student_list, tutor_list, users_info
1125470
def get_queryset(self):
        
        qs = VersionedQuerySet(self.model, using=self._db)
        if hasattr(self, 'instance') and hasattr(self.instance, '_querytime'):
            qs.querytime = self.instance._querytime
        return qs
240173
def get_queryset(self):
        
        queryset    = super(IndexView, self).get_queryset()
        search_form = self.get_search_form()

        if search_form.is_valid():
            query_str   = search_form.cleaned_data.get('q', '').strip()
            queryset    = self.model.objects.search(query_str)

        return queryset
1300056
def get_queryset(self, request):
        
        if not request.user.has_perm('zinnia.can_view_all'):
            queryset = self.model.objects.filter(authors__pk=request.user.pk)
        else:
            queryset = super(EntryAdmin, self).get_queryset(request)
        return queryset.prefetch_related('categories', 'authors', 'sites')
776061
def get_active_schedulings(self):
        """"""
        blocks = EighthBlock.objects.get_blocks_this_year()
        scheduled_activities = EighthScheduledActivity.objects.filter(activity=self)
        scheduled_activities = scheduled_activities.filter(block__in=blocks)

        return scheduled_activities
1321899
def get_queryset(self):
        
        return self.queryset.all().accessible_to(user=self.request.user)
796951
def get_queryset(self, request):
        ''' '''
        qs = super(CourseAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        else:
            return qs.filter(Q(tutors__pk=request.user.pk) | Q(owner=request.user)).distinct()
492556
def get_queryset(self, queryset=None):
        
        serializer = self.get_serializer()
        return getattr(self, 'queryset', serializer.Meta.model.objects.all())
1236179
def get_objects_for_user(user, perms, klass=None, use_groups=True, any_perm=False,
                         with_superuser=True, accept_global_perms=True, perms_filter='pk__in'):
    """"""
    if isinstance(perms, str):
        perms = [perms]

    ctype = None
    app_label = None
    codenames = set()

    # Compute codenames set and ctype if possible
    for perm in perms:
        if '.' in perm:
            new_app_label, codename = perm.split('.', 1)
            if app_label is not None and app_label != new_app_label:
                raise MixedContentTypeError(
                    "Given perms must have same app label "
                    "({} != {})".format(app_label, new_app_label))
            else:
                app_label = new_app_label
        else:
            codename = perm
        codenames.add(codename)

        if app_label is not None:
            new_ctype = ContentType.objects.get(app_label=app_label,
                                                permission__codename=codename)
            if ctype is not None and ctype != new_ctype:
                raise MixedContentTypeError(
                    "ContentType was once computed to be {} and another "
                    "one {}".format(ctype, new_ctype))
            else:
                ctype = new_ctype

    # Compute queryset and ctype if still missing
    if ctype is None and klass is not None:
        queryset = _get_queryset(klass)
        ctype = ContentType.objects.get_for_model(queryset.model)
    elif ctype is not None and klass is None:
        queryset = _get_queryset(ctype.model_class())
    elif klass is None:
        raise WrongAppError("Cannot determine content type")
    else:
        queryset = _get_queryset(klass)
        if ctype.model_class() != queryset.model and perms_filter == 'pk__in':
            raise MixedContentTypeError("Content type for given perms and "
                                        "klass differs")

    # At this point, we should have both ctype and queryset and they should
    # match which means: ctype.model_class() == queryset.model
    # we should also have `codenames` list

    # First check if user is superuser and if so, return queryset immediately
    if with_superuser and user.is_superuser:
        return queryset

    # Check if the user is anonymous. The
    # django.contrib.auth.models.AnonymousUser object doesn't work for queries
    # and it's nice to be able to pass in request.user blindly.
    if user.is_anonymous:
        user = get_anonymous_user()

    global_perms = set()
    has_global_perms = False
    # a superuser has by default assigned global perms for any
    if accept_global_perms and with_superuser:
        for code in codenames:
            if user.has_perm(ctype.app_label + '.' + code):
                global_perms.add(code)
        for code in global_perms:
            codenames.remove(code)
        # prerequisite: there must be elements in global_perms otherwise just
        # follow the procedure for object based permissions only AND
        # 1. codenames is empty, which means that permissions are ONLY set
        # globally, therefore return the full queryset.
        # OR
        # 2. any_perm is True, then the global permission beats the object
        # based permission anyway, therefore return full queryset
        if global_perms and (not codenames or any_perm):
            return queryset
        # if we have global perms and still some object based perms differing
        # from global perms and any_perm is set to false, then we have to flag
        # that global perms exist in order to merge object based permissions by
        # user and by group correctly. Scenario: global perm change_xx and
        # object based perm delete_xx on object A for user, and object based
        # permission delete_xx  on object B for group, to which user is
        # assigned.
        # get_objects_for_user(user, [change_xx, delete_xx], use_groups=True,
        # any_perm=False, accept_global_perms=True) must retrieve object A and
        # B.
        elif global_perms and codenames:
            has_global_perms = True

    # Now we should extract list of pk values for which we would filter
    # queryset
    user_model = get_user_obj_perms_model(queryset.model)
    user_obj_perms_queryset = (user_model.objects
                               .filter(Q(user=user) | Q(user=get_anonymous_user()))
                               .filter(permission__content_type=ctype))

    if codenames:
        user_obj_perms_queryset = user_obj_perms_queryset.filter(
            permission__codename__in=codenames)
    direct_fields = ['content_object__pk', 'permission__codename']
    generic_fields = ['object_pk', 'permission__codename']
    if user_model.objects.is_generic():
        user_fields = generic_fields
    else:
        user_fields = direct_fields

    if use_groups:
        group_model = get_group_obj_perms_model(queryset.model)
        group_filters = {
            'permission__content_type': ctype,
            'group__{}'.format(get_user_model().groups.field.related_query_name()): user,
        }
        if codenames:
            group_filters.update({
                'permission__codename__in': codenames,
            })
        groups_obj_perms_queryset = group_model.objects.filter(**group_filters)
        if group_model.objects.is_generic():
            group_fields = generic_fields
        else:
            group_fields = direct_fields
        if not any_perm and codenames and not has_global_perms:
            user_obj_perms = user_obj_perms_queryset.values_list(*user_fields)
            groups_obj_perms = groups_obj_perms_queryset.values_list(*group_fields)
            data = list(user_obj_perms) + list(groups_obj_perms)
            # sorting/grouping by pk (first in result tuple)
            data = sorted(data, key=lambda t: t[0])
            pk_list = []
            for pk, group in groupby(data, lambda t: t[0]):
                obj_codenames = set((e[1] for e in group))
                if codenames.issubset(obj_codenames):
                    pk_list.append(pk)
            objects = queryset.filter(**{perms_filter: pk_list})
            return objects

    if not any_perm and len(codenames) > 1:
        counts = user_obj_perms_queryset.values(
            user_fields[0]).annotate(object_pk_count=Count(user_fields[0]))
        user_obj_perms_queryset = counts.filter(
            object_pk_count__gte=len(codenames))

    values = user_obj_perms_queryset.values_list(user_fields[0], flat=True)
    if user_model.objects.is_generic():
        values = list(values)
    query = Q(**{perms_filter: values})
    if use_groups:
        values = groups_obj_perms_queryset.values_list(group_fields[0], flat=True)
        if group_model.objects.is_generic():
            values = list(values)
        query |= Q(**{perms_filter: values})

    return queryset.filter(query)
480099
def get_users_for_assigned_to():
    
    User = get_user_model()
    return User.objects.filter(is_active=True, is_staff=True)
675963
def get_queryset(self):
        
        kwargs = {}
        if self.start_at:
            kwargs.update({'%s__gte' % self.date_field: self.start_at})
        return super(DateRangeMixin, self).get_queryset().filter(**kwargs)