- document = storage.get(name)
- except DocumentNotFound:
- return http.HttpResponseRedirect(reverse("wiki_create_missing", args=[name]))
-
- access_time = datetime.now()
- last_documents = request.session.get("wiki_last_docs", {})
- last_documents[name] = access_time
-
- if len(last_documents) > MAX_LAST_DOCS:
- oldest_key = min(last_documents, key=last_documents.__getitem__)
- del last_documents[oldest_key]
- request.session['wiki_last_docs'] = last_documents
-
- return direct_to_template(request, template_name, extra_context={
- 'document': document,
- 'document_name': document.name,
- 'document_info': document.info,
- 'document_meta': document.meta,
+ 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)
+ ]),