X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/43116c58e5c56f94ef358a5a17fb13a252e02531..11251f6a7f40d2e941ec63556c77f98d309c1b34:/apps/catalogue/views.py?ds=sidebyside diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index a3978304..981206c8 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from datetime import datetime, date, timedelta import logging import os @@ -25,8 +26,8 @@ from apiclient import NotAuthorizedError from catalogue import forms from catalogue import helpers from catalogue.helpers import active_tab -from catalogue.models import Book, Chunk, BookPublishRecord, ChunkPublishRecord -from fileupload.views import UploadView +from catalogue.models import Book, Chunk, BookPublishRecord, ChunkPublishRecord, Project +from fileupload.views import UploadView, PackageView # # Quick hack around caching problems, TODO: use ETags @@ -114,12 +115,11 @@ def create_missing(request, slug=None): gallery=form.cleaned_data['gallery'], ) - return http.HttpResponseRedirect(reverse("catalogue_book", args=[book.slug])) + return http.HttpResponseRedirect(reverse("wiki_editor", args=[book.slug])) else: form = forms.DocumentCreateForm(initial={ "slug": slug, "title": slug.replace('-', ' ').title(), - "gallery": slug, }) return render(request, "catalogue/document_create_missing.html", { @@ -352,6 +352,7 @@ def chunk_add(request, slug, chunk): }) +@login_required def chunk_edit(request, slug, chunk): try: doc = Chunk.get(slug, chunk) @@ -389,6 +390,7 @@ def chunk_edit(request, slug, chunk): @transaction.commit_on_success +@login_required def chunk_mass_edit(request): if request.method == 'POST': ids = map(int, filter(lambda i: i.strip()!='', request.POST.get('ids').split(','))) @@ -429,6 +431,17 @@ def chunk_mass_edit(request): for b in books_affected: b.touch() # cache + project_id = request.POST.get('project') + if project_id: + try: + project = Project.objects.get(pk=int(project_id)) + except (Project.DoesNotExist, ValueError), e: + project = None + for c in chunks: + book = c.book + book.project = project + book.save() + for c in chunks: c.save() return HttpResponse("", content_type="text/plain") @@ -475,10 +488,26 @@ def publish(request, slug): return http.HttpResponseRedirect(book.get_absolute_url()) -class GalleryView(UploadView): - def get_object(self, request, slug): - return get_object_or_404(Book, slug=slug) - +class GalleryMixin(object): def get_directory(self): return "%s%s/" % (settings.IMAGE_DIR, self.object.gallery) + def get_object(self, request, slug): + book = get_object_or_404(Book, slug=slug) + if not book.gallery: + raise Http404 + return book + +class GalleryView(GalleryMixin, UploadView): + + def breadcrumbs(self): + return [ + (u'moduły', reverse('catalogue_document_list')), + (self.object.title, self.object.get_absolute_url()), + (u'materiały',), + ] + + +class GalleryPackageView(GalleryMixin, PackageView): + def get_redirect_url(self, slug): + return reverse('catalogue_book_gallery', kwargs = dict(slug=slug))