from django.template.loader import render_to_string
from django.shortcuts import get_object_or_404, render, redirect
from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect
from django.urls import reverse
from django.db.models import Q, QuerySet
from django.contrib.auth.decorators import login_required, user_passes_test
from django.template.loader import render_to_string
from django.shortcuts import get_object_or_404, render, redirect
from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect
from django.urls import reverse
from django.db.models import Q, QuerySet
from django.contrib.auth.decorators import login_required, user_passes_test
from annoy.models import DynamicTextInsert
from pdcounter import views as pdcounter_views
from picture.models import Picture, PictureArea
from annoy.models import DynamicTextInsert
from pdcounter import views as pdcounter_views
from picture.models import Picture, PictureArea
from catalogue.models import Book, Collection, Tag, Fragment
from catalogue.utils import split_tags
from catalogue.models.tag import prefetch_relations
from catalogue.models import Book, Collection, Tag, Fragment
from catalogue.utils import split_tags
from catalogue.models.tag import prefetch_relations
return render(request, 'catalogue/catalogue.html', {
'books': Book.objects.filter(findable=True, parent=None),
'pictures': Picture.objects.all(),
return render(request, 'catalogue/catalogue.html', {
'books': Book.objects.filter(findable=True, parent=None),
'pictures': Picture.objects.all(),
def collection(request, slug):
coll = get_object_or_404(Collection, slug=slug)
def collection(request, slug):
coll = get_object_or_404(Collection, slug=slug)
- return render(request, 'catalogue/collection.html', {'collection': coll})
+ return render(request, 'catalogue/collection.html', {
+ 'collection': coll,
+ 'active_menu_item': 'collections',
+ })
+
+ is_author = len(tags) == 1 and tags[0].category == 'author'
+ is_theme = len(tags) == 1 and tags[0].category == 'theme'
+ new_layout = request.EXPERIMENTS['layout']
+ if is_author and new_layout.value:
+ template = 'catalogue/2022/author_detail.html'
+ elif is_theme and new_layout.value:
+ template = 'catalogue/2022/theme_detail.html'
+ else:
+ template = 'catalogue/tagged_object_list.html'
+
# TODO: Pictures on shelves not supported yet.
books = Book.tagged.with_all(shelf_tags).order_by()
fragments = fragments.filter(Q(book__in=books) | Q(book__ancestor__in=books))
# TODO: Pictures on shelves not supported yet.
books = Book.tagged.with_all(shelf_tags).order_by()
fragments = fragments.filter(Q(book__in=books) | Q(book__ancestor__in=books))
fragments = fragments.filter(book__findable=True)
if not fragments and len(tags) == 1 and list_type == 'books':
fragments = fragments.filter(book__findable=True)
if not fragments and len(tags) == 1 and list_type == 'books':
except Book.DoesNotExist:
return pdcounter_views.book_stub_detail(request, slug)
except Book.DoesNotExist:
return pdcounter_views.book_stub_detail(request, slug)
{
'book': book,
'book_children': book.children.all().order_by('parent_number', 'sort_key'),
'active_menu_item': 'books',
{
'book': book,
'book_children': book.children.all().order_by('parent_number', 'sort_key'),
'active_menu_item': 'books',
+ 'club_form': ScheduleForm() if book.preview else None,
+ 'club': Club.objects.first() if book.preview else None,
+
+ 'EXPERIMENTS_SWITCHABLE_layout': True,
def book_text(request, slug):
book = get_object_or_404(Book, slug=slug)
def book_text(request, slug):
book = get_object_or_404(Book, slug=slug)
_("An error occurred: %(exception)s\n\n%(tb)s") % {
'exception': exception, 'tb': tb
},
_("An error occurred: %(exception)s\n\n%(tb)s") % {
'exception': exception, 'tb': tb
},
)
return HttpResponse(_("Book imported successfully"))
return HttpResponse(_("Error importing file: %r") % book_import_form.errors)
)
return HttpResponse(_("Book imported successfully"))
return HttpResponse(_("Error importing file: %r") % book_import_form.errors)
-def download_zip(request, format, slug=None):
- if format in Book.ebook_formats:
- url = Book.zip_format(format)
- elif format in ('mp3', 'ogg') and slug is not None:
+def download_zip(request, file_format=None, media_format=None, slug=None):
+ if file_format:
+ url = Book.zip_format(file_format)
+ elif media_format and slug is not None:
return HttpResponseRedirect(book.get_absolute_url())
return super(CustomPDFFormView, self).validate_object(obj, request)
return HttpResponseRedirect(book.get_absolute_url())
return super(CustomPDFFormView, self).validate_object(obj, request)