Exemplo n.º 1
0
    def get_context_data(self, *args, **kwargs):

        ctx = super(PostList, self).get_context_data(*args, **kwargs)

        page = self.request.GET.get('p', 1)

        if self.request.user.is_authenticated():
            objects = Post.all().order("-post_date")
        else:
            objects = Post.published().order("-post_date")


        pager = Paginator(objects, PAGE_SIZE)

        try:
            page_obj = pager.page(page)
        except InvalidPageException:
            raise Http404

        ctx.update({
            'paginator': pager,
            'page_obj': page_obj,
        })

        return ctx
Exemplo n.º 2
0
    def get_context_data(self, *args, **kwargs):

        ctx = super(PostArchive, self).get_context_data(*args, **kwargs)

        page = self.request.GET.get('p', 1)
        year = self.kwargs.get('year', None)
        month = self.kwargs.get('month', None)
        day = self.kwargs.get('day', None)
        msg = ""

        try:
            if day and month and year:
                lower_limit = date(int(year), int(month), int(day))
                upper_limit = lower_limit + relativedelta(days=+1)
                msg = "%s" % datefilter(lower_limit, "jS M Y")
            elif month and year:
                lower_limit = date(int(year), int(month), 1)
                upper_limit = lower_limit + relativedelta(months=+1)
                msg = "%s" % datefilter(lower_limit, "F Y")
            elif year:
                lower_limit = date(int(year), 1, 1)
                upper_limit = lower_limit + relativedelta(years=+1)
                msg = "%s" % year
        except ValueError:
            raise Http404

        if self.request.user.is_authenticated():
            gql = "WHERE post_date >= :1 AND post_date <= :2 ORDER BY post_date DESC"
        else:
            gql = "WHERE is_published = true AND post_date >= :1 AND post_date <= :2 ORDER BY post_date DESC"

        objects = Post.gql(gql, lower_limit, upper_limit)

        pager = Paginator(objects, PAGE_SIZE)
        page_obj = pager.page(page)

        ctx.update({
            'display_message': msg,
            'paginator': pager,
            'page_obj': page_obj,
            'year': year,
            'month': month,
            'day': day
        })

        return ctx