+@require_POST
+@login_required
+def publish(request, pk):
+ from wiki import forms
+ from .models import PublishRecord
+ from dvcs.models import Revision
+
+ doc = get_object_or_404(Document, pk=pk, deleted=False)
+ if not doc.can_edit(request.user):
+ return HttpResponseForbidden("Not authorized.")
+ 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):
+ doc = get_object_or_404(Document, pk=pk, deleted=False)
+ if not doc.can_edit(request.user):
+ return HttpResponseForbidden("Not authorized.")
+
+ doc.publish_log.all().delete()
+ if request.is_ajax():
+ return http.HttpResponse('ok')
+ else:
+ return redirect('catalogue_html', doc.pk)
+
+
+class GalleryMixin(object):
+ def get_directory(self):
+ # return "%s%s/" % (settings.IMAGE_DIR, 'org%d' % self.org.pk if self.org is not None else self.request.user.pk)
+ return "uploads/%d/" % self.doc.pk
+
+
+class GalleryView(GalleryMixin, UploadView):
+
+ def breadcrumbs(self):
+ return [
+ (self.doc.meta()['title'], '/documents/%d/' % self.doc.pk),
+ ]
+
+ def get_object(self, request, pk=None):
+ self.doc = Document.objects.get(pk=pk, deleted=False)
+
+
+@login_required
+def fork(request, pk):
+ doc = get_object_or_404(Document, pk=pk, deleted=False)