示例#1
0
        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
示例#2
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
 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
 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
示例#5
0
    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