def changelog(request): if request.user.is_superuser: revisions = Revision.objects.all()[:50] else: q1 = Q(page__restrict_read_to__user=request.user) q2 = Q(page__restrict_read_to__isnull=True) revisions = Revision.objects.filter(q1 | q2).order_by('-timestamp')[:50] return render(request, 'wiki/changelog.html', get_context_wiki(request, 'wiki-changelog', {'revisions': revisions}))
def revision_detail(request, page_slug, revision_pk): try: page = Page.objects.get_by_read(page_slug, request) except PermissionDenied: return redirect('wiki-home') except Page.DoesNotExist: return redirect('wiki-page', page_slug=page_slug) revision = Revision.objects.get(page=page, pk=revision_pk) return render(request, 'wiki/revision-detail.html', get_context_wiki(request, 'wiki-revision-detail', {'page': page, 'revision': revision}))
def revision_list(request, page_slug): try: page = Page.objects.get_by_read(page_slug, request) except PermissionDenied: return redirect('wiki-home') except Page.DoesNotExist: return redirect('wiki-page', page_slug=page_slug) revisions = Revision.objects.filter(page=page) return render(request, 'wiki/revision-list.html', get_context_wiki(request, 'wiki-revision-list', {'page': page, 'revisions': revisions}))
def page_edit(request, page_slug): try: page = Page.objects.get_by_write(page_slug, request) except PermissionDenied: return redirect('wiki-page', page_slug=page_slug) except Page.DoesNotExist: page = None form_page = None if request.POST: form = RevisionForm(request.POST) if form.is_valid(): # adding new page if page is None: form_page = PageAddForm(request.POST, user=request.user) if form_page.is_valid(): page = form_page.save() if Page.objects.count() == 1: # first wiki page created configuration = Configuration.objects.current() configuration.wiki_homepage = page configuration.save() messages.info(request, _(u'Diese Wiki-Seite wurde nun als Startseite des Wikis eingerichtet. ' u'Du kannst das in der Konfiguration ändern.')) if page: revision = form.save(commit=False) revision.user = request.user.actor revision.page = page revision.save() message_object_updated(request, page) return redirect(page) else: form_page = PageAddForm(request.POST, user=request.user, initial={'title': page_slug.capitalize}) else: if page is None: form = RevisionForm() form_page = PageAddForm(user=request.user, initial={'title': page_slug.capitalize}) else: revision = page.get_current() revision.summary = '' form = RevisionForm(instance=revision) if page is not None: is_owner = page.is_owner(request.user.actor) else: is_owner = None return render(request, 'wiki/page-edit.html', get_context_wiki(request, 'wiki-page-edit', {'form': form, 'page': page, 'form_page': form_page, 'tpl__is_owner': is_owner}))
def page_detail(request, page_slug): try: page = Page.objects.get_by_read(page_slug, request) except PermissionDenied: return redirect('wiki-hompage') except Page.DoesNotExist: return page_edit(request, page_slug) can_edit = page.can_write(request.user.actor) return render(request, 'wiki/page-detail.html', get_context_wiki(request, 'wiki-page', {'page': page, 'tpl__can_edit': can_edit}))
def page_form(request, page_slug): try: page = Page.objects.get_by_owner(page_slug, request) except PermissionDenied: return redirect(Page.objects.get(slug=page_slug)) except Page.DoesNotExist: return redirect('wiki-page', page_slug=page_slug) if request.POST: form = PageForm(request.POST, instance=page) if form.is_valid(): form.save() message_object_updated(request, page) return redirect(page) else: form = PageForm(instance=page) return render(request, 'wiki/page-form.html', get_context_wiki(request, 'wiki-page-form', {'form': form, 'page': page}))