X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5780495e13ec2d55bc2dee96dec372a9ea395462..3b2e2e72969a9fa2246774ae2f01bd60a4cd81de:/apps/wiki/views.py diff --git a/apps/wiki/views.py b/apps/wiki/views.py index 69c98365..451034dc 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -12,6 +12,8 @@ from wiki.helpers import (JSONResponse, JSONFormInvalid, JSONServerError, ajax_require_permission, recursive_groupby) from django import http +from django.contrib.auth.decorators import login_required + from wiki.models import getstorage, DocumentNotFound, normalize_name, split_name, join_name from wiki.forms import DocumentTextSaveForm, DocumentTagForm, DocumentCreateForm from datetime import datetime @@ -47,44 +49,6 @@ def normalized_name(view): return decorated -@never_cache -def document_list(request): - return direct_to_template(request, 'wiki/document_list.html', extra_context={ - 'docs': getstorage().all(), - 'last_docs': sorted(request.session.get("wiki_last_docs", {}).items(), - key=operator.itemgetter(1), reverse=True), - }) - - -@never_cache -@normalized_name -def editor(request, name, template_name='wiki/document_details.html'): - storage = getstorage() - - try: - 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, - 'forms': { - "text_save": DocumentTextSaveForm(prefix="textsave"), - "add_tag": DocumentTagForm(prefix="addtag"), - }, - }) @require_GET @@ -124,11 +88,11 @@ def create_missing(request, name): form = DocumentCreateForm(request.POST, request.FILES) if form.is_valid(): doc = storage.create_document( - id=form.cleaned_data['id'], + name=form.cleaned_data['id'], text=form.cleaned_data['text'], ) - return http.HttpResponseRedirect(reverse("wiki_details", args=[doc.name])) + return http.HttpResponseRedirect(reverse("wiki_editor", args=[doc.name])) else: form = DocumentCreateForm(initial={ "id": name.replace(" ", "_"), @@ -194,6 +158,24 @@ def text(request, name): }) +@never_cache +@normalized_name +@require_POST +def revert(request, name): + storage = getstorage() + revision = request.POST['target_revision'] + + try: + document = storage.revert(name, revision) + + return JSONResponse({ + 'text': document.plain_text if revision != document.revision else None, + 'meta': document.meta(), + 'revision': document.revision, + }) + except DocumentNotFound: + raise http.Http404 + @never_cache def gallery(request, directory): try: @@ -284,3 +266,8 @@ def publish(request, name): return JSONResponse({"result": api.publish_book(document)}) except wlapi.APICallException, e: return JSONServerError({"message": str(e)}) + +@login_required +def status_report(request): + pass +