def show_page(request, slug = None, page = None, history = None): #items_per_page=50 if slug is None: wiki_page = get_object_or_404(Page, parent = None, page_type = 'h') else: wiki_page = get_object_or_404(Page, ~Q(page_type = 'i'), slug = slug) children = [] if history and wiki_page.page_type != 'p': return HttpResponseNotAllowed revision = None if history: revision = get_object_or_404(reversion.get_for_object(wiki_page).select_related('revision', 'revision__user'), pk = history) history_data = reversion.get_for_object(wiki_page).select_related('revision', 'revision__user') template = "wiki/page.html" if wiki_page.page_type == 'h': if wiki_page.parent: template = "wiki/category.html" children = wiki_page.get_descendants().order_by('-updated') else: template = "wiki/home.html" children = wiki_page.get_children().filter(page_type = 'h')[:] for child in children: child.pages = child.get_descendants().order_by('-updated') paginator, page, children, is_paginated = paginate_queryset(children, page or 1, 50) else: children = wiki_page.get_children() paginator, page, history_data, is_paginated = paginate_queryset(history_data, page or 1, 20) context = { 'page': wiki_page, 'children': children, 'paginator': paginator, 'page_obj': page, 'is_paginated': is_paginated, 'pagenum': page, 'tree': wiki_page.get_ancestors(), 'history': history_data, 'revision': revision } return TemplateResponse(request, template, context)
def get_context_data(self, **kwargs): ctx = super(WikiDetailView, self).get_context_data(**kwargs) children = ctx['children'] history = ctx['history'] page = self.kwargs.get('page', None) if self.object.page_type == 'h': paginator, page, children, is_paginated = paginate_queryset(children, page or 1, 50) else: paginator, page, history, is_paginated = paginate_queryset(history, page or 1, 20) ctx.update({ 'children': children, 'paginator': paginator, 'page_obj': page, 'is_paginated': is_paginated, 'pagenum': page, 'history': history, }) return ctx
def get_context_data(self, **kwargs): ctx = super(WikiDetailView, self).get_context_data(**kwargs) children = ctx["children"] history = ctx["history"] page = self.kwargs.get("page", None) if self.object.page_type == "h": paginator, page, children, is_paginated = paginate_queryset(children, page or 1, 50) else: paginator, page, history, is_paginated = paginate_queryset(history, page or 1, 20) ctx.update( { "children": children, "paginator": paginator, "page_obj": page, "is_paginated": is_paginated, "pagenum": page, "history": history, } ) return ctx
def get_context_data(self, **kwargs): ctx = super(WikiDetailView, self).get_context_data(**kwargs) children = ctx['children'] history = ctx['history'] page = self.kwargs.get('page', None) if self.object.page_type == 'h': paginator, page, children, is_paginated = paginate_queryset( children, page or 1, 50) else: paginator, page, history, is_paginated = paginate_queryset( history, page or 1, 20) ctx.update({ 'children': children, 'paginator': paginator, 'page_obj': page, 'is_paginated': is_paginated, 'pagenum': page, 'history': history, }) return ctx
def create_response(self): queryset = self.results paginator, page, queryset, is_paginated = paginate_queryset(queryset, self.request.GET.get('page') or 1, self.paginate_by) context = { 'query': self.query, 'form': self.form, 'suggestion': None, 'paginator': paginator, 'page_obj': page, 'results': queryset, 'is_paginated': is_paginated, } if self.results and hasattr(self.results, 'query') and self.results.query.backend.include_spelling: context['suggestion'] = self.form.get_suggestion() context.update(self.extra_context()) return TemplateResponse(self.request, self.template, context)