-def document_list(request, template_name = 'wiki/document_list.html'):
- # TODO: find a way to cache "Storage All"
- return direct_to_template(request, template_name, extra_context = {
- 'document_list': storage.all(),
- 'last_docs': sorted(request.session.get("wiki_last_docs", {}).items(),
- key=operator.itemgetter(1), reverse = True)
- })
+def get_history(document):
+ revisions = []
+ for i, revision in enumerate(document.history()):
+ revisions.append({
+ "version": i + 1,
+ "description": revision.description,
+ "author": revision.author_str(),
+ "date": localize(revision.created_at),
+ "published": "",
+ "revision": revision.pk,
+ "published": _("Published") + ": " + \
+ localize(revision.publish_log.order_by('-timestamp')[0].timestamp) \
+ if revision.publish_log.exists() else "",
+ })
+ return revisions
+
+
+@never_cache
+#@login_required
+def editor(request, pk, chunk=None, template_name='wiki/bootstrap.html'):
+ doc = get_object_or_404(Document, pk=pk, deleted=False)
+ #~ if not doc.accessible(request):
+ #~ return HttpResponseForbidden("Not authorized.")
+
+ access_time = datetime.now()
+
+ save_form = forms.DocumentTextSaveForm(user=request.user, prefix="textsave")
+ try:
+ version = int(request.GET.get('version', None))
+ except:
+ version = None
+ if version:
+ text = doc.at_revision(version).materialize()
+ else:
+ text = doc.materialize()
+ revision = doc.revision
+ history = get_history(doc)
+ return render(request, template_name, {
+ 'serialized_document_data': json.dumps({
+ 'document': text,
+ 'document_id': doc.pk,
+ 'title': doc.meta().get('title', ''),
+ 'history': history,
+ 'version': len(history), #version or chunk.revision(),
+ 'revision': revision.pk,
+ 'stage': doc.stage,
+ 'assignment': str(doc.assigned_to),
+ }),
+ 'serialized_templates': json.dumps([
+ {'id': t.id, 'name': t.name, 'content': t.content} for t in Template.objects.filter(is_partial=True)
+ ]),
+ 'forms': {
+ "text_save": save_form,
+ "text_revert": forms.DocumentTextRevertForm(prefix="textrevert"),
+ "text_publish": forms.DocumentTextPublishForm(prefix="textpublish"),
+ },
+ 'pk': doc.pk,
+ })