X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/6a259b96cff47e1fd64cbfd6f3d1e1d8e8b6486c..a7540f09e312d61f5fb9fd86ef89a863c8b74591:/apps/catalogue/views.py diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index aa214de7..487307d5 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -19,6 +19,7 @@ from django.views.generic.simple import direct_to_template import librarian.html import librarian.text +from apiclient import NotAuthorizedError from catalogue import forms from catalogue import helpers from catalogue.helpers import active_tab @@ -88,12 +89,12 @@ def create_missing(request, slug=None): creator = request.user else: creator = None - book = Book.objects.create( + book = Book.create( + text=form.cleaned_data['text'], + creator=creator, slug=form.cleaned_data['slug'], title=form.cleaned_data['title'], ) - book.chunk_set.all().update(creator=creator) - book[0].commit(text=form.cleaned_data['text'], author=creator) return http.HttpResponseRedirect(reverse("wiki_editor", args=[book.slug])) else: @@ -147,10 +148,11 @@ def upload(request): if not error_list: for filename, slug, title in ok_list: - Book.create(creator=creator, + book = Book.create( + text=zip.read(filename).decode('utf-8'), + creator=creator, slug=slug, title=title, - text=zip.read(filename).decode('utf-8'), ) return direct_to_template(request, "catalogue/document_upload.html", extra_context={ @@ -293,8 +295,19 @@ def book(request, slug): else: form = None + try: + book.assert_publishable() + except AssertionError, e: + publishable = False + publishable_error = e + else: + publishable = True + publishable_error = None + return direct_to_template(request, "catalogue/book_detail.html", extra_context={ "book": book, + "publishable": publishable, + "publishable_error": publishable_error, "chunks": chunks, "need_fixing": need_fixing, "choose_master": choose_master, @@ -389,6 +402,8 @@ def publish(request, slug): book = get_object_or_404(Book, slug=slug) try: book.publish(request.user) + except NotAuthorizedError: + return http.HttpResponseRedirect(reverse('apiclient_oauth')) except BaseException, e: return http.HttpResponse(e) else: