-def chunk_edit(request, slug, chunk):
- try:
- doc = Chunk.get(slug, chunk)
- except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist):
- raise Http404
- if request.method == "POST":
- form = forms.ChunkForm(request.POST, instance=doc)
- if form.is_valid():
- form.save()
- go_next = request.GET.get('next', None)
- if go_next:
- go_next = urlquote_plus(unquote(iri_to_uri(go_next)), safe='/?=&')
- else:
- go_next = doc.book.get_absolute_url()
- return http.HttpResponseRedirect(go_next)
+@require_POST
+@login_required
+def publish(request, pk):
+ from wiki import forms
+ from .models import PublishRecord
+ from dvcs.models import Revision
+
+ # FIXME: check permissions
+
+ doc = get_object_or_404(Document, pk=pk, deleted=False)
+ form = forms.DocumentTextPublishForm(request.POST, prefix="textpublish")
+ if form.is_valid():
+ rev = Revision.objects.get(pk=form.cleaned_data['revision'])
+ # FIXME: check if in tree
+ # if PublishRecord.objects.filter(revision=rev, document=doc).exists():
+ # return http.HttpResponse('exists')
+ if not doc.published:
+ site = Site.objects.get_current()
+ send_notify_email(
+ 'New published document in MIL/PEER',
+ '''New published document in MIL/PEER: %s. View it in browser: https://%s%s.
+
+--
+MIL/PEER team.''' % (doc.meta()['title'], site.domain, reverse('catalogue_html', args=[doc.pk])))
+ PublishRecord.objects.create(revision=rev, document=doc, user=request.user)
+ doc.published = True
+ doc.save()
+ if request.is_ajax():
+ return http.HttpResponse('ok')
+ else:
+ return redirect('catalogue_html', doc.pk)
+ else:
+ if request.is_ajax():
+ return http.HttpResponse('error')
+ else:
+ try:
+ return redirect('catalogue_preview_rev', doc.pk, form.cleaned_data['revision'])
+ except KeyError:
+ return redirect('catalogue_preview', doc.pk)
+
+
+@require_POST
+@login_required
+def unpublish(request, pk):
+ # FIXME: check permissions
+
+ doc = get_object_or_404(Document, pk=pk, deleted=False)
+ doc.publish_log.all().delete()
+ if request.is_ajax():
+ return http.HttpResponse('ok')