- oldest_key = min(last_documents, key = last_documents.__getitem__)
- del last_documents[oldest_key]
- request.session['wiki_last_docs'] = last_documents
-
- if request.method == 'POST':
- form = DocumentForm(request.POST, instance = document)
+ 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,
+ 'forms': {
+ "text_save": DocumentTextSaveForm(prefix="textsave"),
+ "add_tag": DocumentTagForm(prefix="addtag"),
+ },
+ })
+
+
+@require_GET
+@normalized_name
+def editor_readonly(request, name, template_name='wiki/document_details_readonly.html'):
+ name = normalize_name(name)
+ storage = getstorage()
+
+ try:
+ revision = request.GET['revision']
+ document = storage.get(name, revision)
+ except (KeyError, DocumentNotFound):
+ raise http.Http404
+
+ 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': dict(document.info(), readonly=True),
+ 'document_meta': document.meta,
+ })
+
+
+@normalized_name
+def create_missing(request, name):
+ storage = getstorage()
+
+ if request.method == "POST":
+ form = DocumentCreateForm(request.POST, request.FILES)