from urllib import unquote
from urlparse import urlsplit, urlunsplit
+from django.conf import settings
from django.contrib import auth
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required, permission_required
from django.utils.http import urlquote_plus
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import require_POST
-from django.views.generic.simple import direct_to_template
from django.template import RequestContext
from apiclient import NotAuthorizedError
from catalogue import helpers
from catalogue.helpers import active_tab
from catalogue.models import Book, Chunk, BookPublishRecord, ChunkPublishRecord
-from catalogue.tasks import publishable_error
+from fileupload.views import UploadView
#
# Quick hack around caching problems, TODO: use ETags
@active_tab('users')
def users(request):
- return direct_to_template(request, 'catalogue/user_list.html', extra_context={
+ return render(request, 'catalogue/user_list.html', {
'users': User.objects.all().annotate(count=Count('chunk')).order_by(
'-count', 'last_name', 'first_name'),
})
"gallery": slug,
})
- return direct_to_template(request, "catalogue/document_create_missing.html", extra_context={
+ return render(request, "catalogue/document_create_missing.html", {
"slug": slug,
"form": form,
title=title,
)
- return direct_to_template(request, "catalogue/document_upload.html", extra_context={
+ return render(request, "catalogue/document_upload.html", {
"form": form,
"ok_list": ok_list,
"skipped_list": skipped_list,
else:
form = forms.DocumentsUploadForm()
- return direct_to_template(request, "catalogue/document_upload.html", extra_context={
+ return render(request, "catalogue/document_upload.html", {
"form": form,
"logout_to": '/',
form = forms.ReadonlyBookForm(instance=book)
editable = False
- publish_error = publishable_error(book)
+ publish_error = book.publishable_error()
publishable = publish_error is None
- return direct_to_template(request, "catalogue/book_detail.html", extra_context={
+ return render(request, "catalogue/book_detail.html", {
"book": book,
"publishable": publishable,
"publishable_error": publish_error,
"title": "cz. %d" % (doc.number + 1, ),
})
- return direct_to_template(request, "catalogue/chunk_add.html", extra_context={
+ return render(request, "catalogue/chunk_add.html", {
"chunk": doc,
"form": form,
})
else:
go_next = ''
- return direct_to_template(request, "catalogue/chunk_edit.html", extra_context={
+ return render(request, "catalogue/chunk_edit.html", {
"chunk": doc,
"form": form,
"go_next": go_next,
return http.HttpResponseRedirect(append_to.get_absolute_url())
else:
form = forms.BookAppendForm(book)
- return direct_to_template(request, "catalogue/book_append_to.html", extra_context={
+ return render(request, "catalogue/book_append_to.html", {
"book": book,
"form": form,
return http.HttpResponse(e)
else:
return http.HttpResponseRedirect(book.get_absolute_url())
+
+
+class GalleryView(UploadView):
+ def get_object(self, request, slug):
+ book = get_object_or_404(Book, slug=slug)
+ if not book.gallery:
+ raise Http404
+ return book
+
+ def breadcrumbs(self):
+ return [
+ (_('books'), reverse('catalogue_document_list')),
+ (self.object.title, self.object.get_absolute_url()),
+ (_('scan gallery'),),
+ ]
+
+ def get_directory(self):
+ return "%s%s/" % (settings.IMAGE_DIR, self.object.gallery)