def add_contributor(request, document_slug): """Add a contributor to a document.""" document = get_object_or_404(Document, locale=request.LANGUAGE_CODE, slug=document_slug) if not document.allows(request.user, "edit"): raise PermissionDenied form = AddContributorForm(request.POST) if form.is_valid(): for user in form.cleaned_data["users"]: document.contributors.add(user) msg = _("{users} added to the contributors successfully!").format(users=request.POST.get("users")) messages.add_message(request, messages.SUCCESS, msg) return HttpResponseRedirect(reverse("wiki.document_revisions", args=[document_slug])) msg = _("There were errors adding new contributors, see below.") messages.add_message(request, messages.ERROR, msg) return document_revisions(request, document_slug, contributor_form=form)
def add_contributor(request, document_slug): """Add a contributor to a document.""" document = get_object_or_404(Document, locale=request.LANGUAGE_CODE, slug=document_slug) if not document.allows(request.user, 'edit'): raise PermissionDenied form = AddContributorForm(request.POST) if form.is_valid(): for user in form.cleaned_data['users']: document.contributors.add(user) msg = _('{users} added to the contributors successfully!').format( users=request.POST.get('users')) messages.add_message(request, messages.SUCCESS, msg) return HttpResponseRedirect(reverse('wiki.document_revisions', args=[document_slug])) msg = _('There were errors adding new contributors, see below.') messages.add_message(request, messages.ERROR, msg) return document_revisions(request, document_slug, contributor_form=form)
def document_revisions(request, document_slug, contributor_form=None): """List all the revisions of a given document.""" locale = request.GET.get('locale', request.LANGUAGE_CODE) doc = get_object_or_404( Document, locale=locale, slug=document_slug) revs = Revision.objects.filter(document=doc).order_by('-created', '-id') if request.is_ajax(): template = 'wiki/includes/revision_list.html' else: template = 'wiki/history.html' form = contributor_form or AddContributorForm() return render(request, template, { 'revisions': revs, 'document': doc, 'contributor_form': form})