X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/fdd62169ba22c4c1be2f2306b5339eadd74ffb6d..753e8bf1e2fe3ccc0a21166cc7da1d88c08bbb89:/apps/wiki/views.py diff --git a/apps/wiki/views.py b/apps/wiki/views.py index 75650e09..dc2ec6f1 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -9,7 +9,7 @@ from django.http import Http404 from django.middleware.gzip import GZipMiddleware from django.utils.decorators import decorator_from_middleware from django.utils.encoding import smart_unicode -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext as _ from django.views.decorators.http import require_POST, require_GET from django.views.generic.simple import direct_to_template @@ -114,7 +114,10 @@ def text(request, slug, chunk=None): author = None text = form.cleaned_data['text'] parent_revision = form.cleaned_data['parent_revision'] - parent = doc.at_revision(parent_revision) + if parent_revision is not None: + parent = doc.at_revision(parent_revision) + else: + parent = None stage = form.cleaned_data['stage_completed'] tags = [stage] if stage else [] doc.commit(author=author, @@ -137,12 +140,17 @@ def text(request, slug, chunk=None): try: revision = int(revision) except (ValueError, TypeError): - revision = None + revision = doc.revision() + + if revision is not None: + text = doc.at_revision(revision).materialize() + else: + text = '' return JSONResponse({ - 'text': doc.at_revision(revision).materialize(), + 'text': text, 'meta': {}, - 'revision': revision if revision else doc.revision(), + 'revision': revision, }) @@ -221,7 +229,11 @@ def diff(request, slug, chunk=None): doc = Chunk.get(slug, chunk) except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist): raise Http404 - docA = doc.at_revision(revA).materialize() + # allow diff from the beginning + if revA: + docA = doc.at_revision(revA).materialize() + else: + docA = "" docB = doc.at_revision(revB).materialize() return http.HttpResponse(nice_diff.html_diff_table(docA.splitlines(), @@ -252,14 +264,14 @@ def history(request, slug, chunk=None): "description": change.description, "author": change.author_str(), "date": change.created_at, - "publishable": "Publishable\n" if change.publishable else "", + "publishable": _("Publishable") + "\n" if change.publishable else "", "tag": ',\n'.join(unicode(tag) for tag in change.tags.all()), }) return JSONResponse(changes) @require_POST -@ajax_require_permission('wiki.can_pubmark') +@ajax_require_permission('catalogue.can_pubmark') def pubmark(request, slug, chunk=None): form = forms.DocumentPubmarkForm(request.POST, prefix="pubmark") if form.is_valid(): @@ -272,8 +284,7 @@ def pubmark(request, slug, chunk=None): publishable = form.cleaned_data['publishable'] change = doc.at_revision(revision) if publishable != change.publishable: - change.publishable = publishable - change.save() + change.set_publishable(publishable) return JSONResponse({"message": _("Revision marked")}) else: return JSONResponse({"message": _("Nothing changed")})