fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix in api
[wolnelektury.git]
/
src
/
catalogue
/
views.py
diff --git
a/src/catalogue/views.py
b/src/catalogue/views.py
index
98dafc5
..
6782e53
100644
(file)
--- a/
src/catalogue/views.py
+++ b/
src/catalogue/views.py
@@
-12,7
+12,7
@@
from django.template.loader import render_to_string
from django.shortcuts import render_to_response, get_object_or_404, render, redirect
from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect, JsonResponse
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response, get_object_or_404, render, redirect
from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect, JsonResponse
from django.core.urlresolvers import reverse
-from django.db.models import Q
+from django.db.models import Q
, QuerySet
from django.contrib.auth.decorators import login_required, user_passes_test
from django.utils.http import urlquote_plus
from django.utils import translation
from django.contrib.auth.decorators import login_required, user_passes_test
from django.utils.http import urlquote_plus
from django.utils import translation
@@
-29,6
+29,7
@@
from catalogue import forms
from catalogue.helpers import get_top_level_related_tags
from catalogue.models import Book, Collection, Tag, Fragment
from catalogue.utils import split_tags
from catalogue.helpers import get_top_level_related_tags
from catalogue.models import Book, Collection, Tag, Fragment
from catalogue.utils import split_tags
+from catalogue.models.tag import prefetch_relations
staff_required = user_passes_test(lambda user: user.is_staff)
staff_required = user_passes_test(lambda user: user.is_staff)
@@
-103,11
+104,19
@@
def object_list(request, objects, fragments=None, related_tags=None, tags=None,
else:
fragments = Fragment.objects.filter(book__in=objects)
related_tag_lists.append(
else:
fragments = Fragment.objects.filter(book__in=objects)
related_tag_lists.append(
- Tag.objects.usage_for_queryset(fragments, counts=True).filter(category='theme').exclude(pk__in=tag_ids))
+ Tag.objects.usage_for_queryset(fragments, counts=True).filter(category='theme').exclude(pk__in=tag_ids)
+ .only('name', 'sort_key', 'category', 'slug'))
+ if isinstance(objects, QuerySet):
+ objects = prefetch_relations(objects, 'author')
categories = split_tags(*related_tag_lists)
objects = list(objects)
categories = split_tags(*related_tag_lists)
objects = list(objects)
+
+ if not objects and len(tags) == 1 and list_type == 'books':
+ if PictureArea.tagged.with_any(tags).exists() or Picture.tagged.with_any(tags).exists():
+ return redirect('tagged_object_list_gallery', '/'.join(tag.url_chunk for tag in tags))
+
if len(objects) > 3:
best = random.sample(objects, 3)
else:
if len(objects) > 3:
best = random.sample(objects, 3)
else:
@@
-201,10
+210,7
@@
def theme_list(request, tags, list_type):
fragments = fragments.filter(Q(book__in=books) | Q(book__ancestor__in=books))
if not fragments and len(tags) == 1 and list_type == 'books':
fragments = fragments.filter(Q(book__in=books) | Q(book__ancestor__in=books))
if not fragments and len(tags) == 1 and list_type == 'books':
- tag = tags[0]
- if tag.category == 'theme' and (
- PictureArea.tagged.with_any([tag]).exists() or
- Picture.tagged.with_any([tag]).exists()):
+ if PictureArea.tagged.with_any(tags).exists() or Picture.tagged.with_any(tags).exists():
return redirect('tagged_object_list_gallery', '/'.join(tag.url_chunk for tag in tags))
return object_list(request, fragments, tags=tags, list_type=list_type, extra={
return redirect('tagged_object_list_gallery', '/'.join(tag.url_chunk for tag in tags))
return object_list(request, fragments, tags=tags, list_type=list_type, extra={
@@
-352,7
+358,7
@@
def _no_diacritics_regexp(query):
def repl(m):
l = m.group()
def repl(m):
l = m.group()
- return u"(%s)" % '|'.join(names[l])
+ return u"(
?:
%s)" % '|'.join(names[l])
return re.sub(u'[%s]' % (u''.join(names.keys())), repl, query)
return re.sub(u'[%s]' % (u''.join(names.keys())), repl, query)
@@
-640,13
+646,14
@@
class CustomPDFFormView(AjaxableFormView):
@ssi_included
def book_mini(request, pk, with_link=True):
@ssi_included
def book_mini(request, pk, with_link=True):
- book = get_object_or_404(Book, pk=pk)
- author_str = ", ".join(tag.name for tag in book.tags.filter(category='author'))
+ # book = get_object_or_404(Book, pk=pk)
+ try:
+ book = Book.objects.only('cover_thumb', 'title', 'language', 'slug').get(pk=pk)
+ except Book.DoesNotExist:
+ raise Http404
return render(request, 'catalogue/book_mini_box.html', {
'book': book,
return render(request, 'catalogue/book_mini_box.html', {
'book': book,
- 'author_str': author_str,
- 'with_link': with_link,
- 'show_lang': book.language_code() != settings.LANGUAGE_CODE,
+ 'no_link': not with_link,
})
})
@@
-728,10
+735,10
@@
def tag_box(request, pk):
@ssi_included
def collection_box(request, pk):
@ssi_included
def collection_box(request, pk):
-
obj
= get_object_or_404(Collection, pk=pk)
+
collection
= get_object_or_404(Collection, pk=pk)
return render(request, 'catalogue/collection_box.html', {
return render(request, 'catalogue/collection_box.html', {
- '
obj': obj
,
+ '
collection': collection
,
})
})