コード例 #1
0
ファイル: mixins.py プロジェクト: varunok/gek
    def get_queryset(self):
        qs = MultipleObjectMixin.get_queryset(self)
        if self.q:
            create_field = '{0}__icontains'.format(self.create_field)
            qs = qs.filter(**{create_field: self.q})

        return qs
コード例 #2
0
ファイル: crud_custom.py プロジェクト: interlegis/saap
        def get_context_data(self, **kwargs):
            obj = self.crud if hasattr(self, 'crud') else self
            if hasattr(obj, 'model_set') and obj.model_set:
                count = self.object_list.count()
                context = MultipleObjectMixin.get_context_data(self, **kwargs)
                context['count'] = count
                if self.paginate_by:
                    page_obj = context['page_obj']
                    paginator = context['paginator']
                    context['page_range'] = make_pagination(
                        page_obj.number, paginator.num_pages)

                # rows
                object_list = context['object_list']
                context['headers'] = self.get_headers()
                context['rows'] = self.get_rows(object_list)

                context['NO_ENTRIES_MSG'] = self.no_entries_msg
            else:
                context = ContextMixin.get_context_data(self, **kwargs)
                if self.object:
                    context['object'] = self.object
                    context_object_name = self.get_context_object_name(
                        self.object)
                    if context_object_name:
                        context[context_object_name] = self.object
                context.update(kwargs)

            return context
コード例 #3
0
ファイル: crud_custom.py プロジェクト: lms91/saap
        def get_context_data(self, **kwargs):
            obj = self.crud if hasattr(self, 'crud') else self
            if hasattr(obj, 'model_set') and obj.model_set:
                count = self.object_list.count()
                context = MultipleObjectMixin.get_context_data(self, **kwargs)
                context['count'] = count
                if self.paginate_by:
                    page_obj = context['page_obj']
                    paginator = context['paginator']
                    context['page_range'] = make_pagination(
                        page_obj.number, paginator.num_pages)

                # rows
                object_list = context['object_list']
                context['headers'] = self.get_headers()
                context['rows'] = self.get_rows(object_list)

                context['NO_ENTRIES_MSG'] = self.no_entries_msg
            else:
                context = ContextMixin.get_context_data(self, **kwargs)
                if self.object:
                    context['object'] = self.object
                    context_object_name = self.get_context_object_name(
                        self.object)
                    if context_object_name:
                        context[context_object_name] = self.object
                context.update(kwargs)

            return context
コード例 #4
0
 def get_queryset(self):
     qs = MultipleObjectMixin.get_queryset(self)
     if not self.is_allowed():
         return qs.none()
     if self.q:
         qs = self.filter_qs(qs)
     return qs
コード例 #5
0
 def value(self, view: MultipleObjectMixin) -> Optional[datetime.datetime]:
     if not hasattr(view.model, self.last_modified_field):
         raise ImproperlyConfigured(
             f"{view.model} does not have a field named {self.last_modified_field}."
         )
     last_modified = view.get_queryset().order_by('-' + self.last_modified_field) \
         .values_list(self.last_modified_field, flat=True).first()
     return last_modified
コード例 #6
0
 def get_context_data(self, **kwargs):
     queryset = self.get_queryset()
     # manually build context because in Django 1.4, `TemplateView` does not
     # build it properly (bug #16074, see:
     # https://code.djangoproject.com/ticket/16074). This function can be
     # simplified once Django 1.4 support is dropped.
     context = SimpleWellView.get_context_data(self,
                                               object_list=queryset,
                                               **kwargs)
     context.update(
         MultipleObjectMixin.get_context_data(self,
                                              object_list=queryset,
                                              **kwargs))
     return context
コード例 #7
0
 def get_context_data(self, **kwargs):
     queryset = self.get_queryset()
     # manually build context because in Django 1.4, `TemplateView` does not
     # build it properly (bug #16074, see:
     # https://code.djangoproject.com/ticket/16074). This function can be
     # simplified once Django 1.4 support is dropped.
     context = SimpleWellView.get_context_data(self,
         object_list=queryset,
         **kwargs
     )
     context.update(MultipleObjectMixin.get_context_data(self,
         object_list=queryset,
         **kwargs
     ))
     return context
コード例 #8
0
    def _paginate_queryset(self, queryset, page_size):
        try:
            # Call parent paginate ListView (This could also be from SortableTableMixin which calls parent method)
            paginator, page, queryset, is_paginated = super(
                PaginatorMixin, self).paginate_queryset(queryset, page_size)
        except AttributeError as err:
            if 'paginate_queryset' in str(err):
                # SortableTableMixin paginate_queryset was called, but ListView is not a base class
                paginator, page, queryset, is_paginated = MultipleObjectMixin.paginate_queryset(
                    self, queryset, page_size)
            else:
                # Attribute error did not have to do with a non existing 'paginate_queryset' method.
                raise AttributeError(str(err)) from err

        return paginator, page, queryset, is_paginated
コード例 #9
0
ファイル: views.py プロジェクト: vdedyukhin/newco-legacy
    def get_context_data(self, **kwargs):
        history = self.page_user.content_set.public().prefetch_related(
            "author__reputation", "items")
        fwers_ids = Follow.objects.get_follows(self.page_user).values_list(
            "user_id", flat=True)
        obj_fwed = Follow.objects.filter(user=self.page_user)
        fwees_ids = obj_fwed.values_list("target_user_id", flat=True)
        items_fwed_ids = obj_fwed.values_list("target_item_id", flat=True)

        empty_msg = _("%(page_user_display)s have not contributed yet.") % {
            "page_user_display": user_display(self.page_user)
        }

        context = super(ProfileDetailView, self).get_context_data(**kwargs)
        followers = User.objects.filter(pk__in=fwers_ids)
        followees = User.objects.filter(pk__in=fwees_ids)
        scores, votes = history.get_scores_and_votes(self.request.user, True)
        context.update({
            "empty_msg":
            empty_msg,
            "reputation":
            self.page_user.reputation,
            "fwers":
            followers.order_by("-reputation__reputation_incremented"),
            "fwees":
            followees.order_by("-reputation__reputation_incremented"),
            "items_fwed":
            Item.objects.filter(pk__in=items_fwed_ids),
            "scores":
            scores,
            "votes":
            votes,
        })

        # Next step would be to be able to "merge" the get_context_data of both
        # DetailView (SingleObjectMixin) and MultipleObjectMixin
        m = MultipleObjectMixin()
        m.request = self.request
        m.kwargs = self.kwargs
        m.paginate_by = self.paginate_by

        history = history.select_subclasses()
        context.update(m.get_context_data(object_list=history))

        return context
コード例 #10
0
ファイル: views.py プロジェクト: Francislley/crudDjango170118
 def get_queryset(self):
     try:
         return MultipleObjectMixin.get_queryset(self)
     except AttributeError:
         return self.model.objects()