From: Marek Stępniowski Date: Thu, 16 Oct 2008 10:29:20 +0000 (+0200) Subject: Added page "{{ theme }} in {{ book }}". X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/9a8e8a433dfa6d7c3789f6d996fd2e122b461c08?ds=inline Added page "{{ theme }} in {{ book }}". --- diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 81965cec2..483fddab0 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -22,6 +22,7 @@ TAG_CATEGORIES = ( ('genre', _('genre')), ('theme', _('theme')), ('set', _('set')), + ('book', _('book')), ) @@ -109,7 +110,7 @@ class Book(models.Model): if len(self._short_html): return mark_safe(self._short_html) else: - tags = self.tags.filter(~Q(category__in=('set', 'theme'))) + tags = self.tags.filter(~Q(category__in=('set', 'theme', 'book'))) tags = [u'%s' % (tag.get_absolute_url(), tag.name) for tag in tags] formats = [] @@ -188,6 +189,15 @@ class Book(models.Model): tag.category = category tag.save() book_tags.append(tag) + + book_tag, created = Tag.objects.get_or_create(slug=('l-' + book.slug)[:120]) + if created: + book_tag.name = book.title[:50] + book_tag.sort_key = ('l-' + book.slug)[:120] + book_tag.category = 'book' + book_tag.save() + book_tags.append(book_tag) + book.tags = book_tags if hasattr(book_info, 'parts'): @@ -197,7 +207,14 @@ class Book(models.Model): child_book.parent = book child_book.parent_number = n child_book.save() - + + book_descendants = list(book.children.all()) + while len(book_descendants) > 0: + child_book = book_descendants.pop(0) + for fragment in child_book.fragments.all(): + fragment.tags = set(list(fragment.tags) + [book_tag]) + book_descendants += list(child_book.children.all()) + # Save XML and HTML files book.xml_file.save('%s.xml' % book.slug, File(file(xml_file)), save=False) @@ -230,7 +247,7 @@ class Book(models.Model): tag.save() themes.append(tag) new_fragment.save() - new_fragment.tags = list(book.tags) + themes + new_fragment.tags = set(list(book.tags) + themes + [book_tag]) book_themes += themes book_themes = set(book_themes) diff --git a/apps/catalogue/urls.py b/apps/catalogue/urls.py index b24212ea5..dc8cc9bdf 100644 --- a/apps/catalogue/urls.py +++ b/apps/catalogue/urls.py @@ -17,6 +17,8 @@ urlpatterns = patterns('catalogue.views', # Public interface. Do not change this URLs. url(r'^lektura/(?P[a-zA-Z0-9-]+)\.html$', 'book_text', name='book_text'), url(r'^lektura/(?P[a-zA-Z0-9-]+)/$', 'book_detail', name='book_detail'), + url(r'^lektura/(?P[a-zA-Z0-9-]+)/motyw/(?P[a-zA-Z0-9-]+)/$', + 'book_fragments', name='book_fragments'), url(r'^(?P[a-zA-Z0-9-/]*)/$', 'tagged_object_list', name='tagged_object_list'), ) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index f284e0a59..1718d9765 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -67,6 +67,9 @@ def tagged_object_list(request, tags=''): except models.Tag.DoesNotExist: raise Http404 + if len([tag for tag in tags if tag.category == 'book']): + raise Http404 + model = models.Book shelf = [tag for tag in tags if tag.category == 'set'] shelf_is_set = (len(tags) == 1 and tags[0].category == 'set') @@ -76,7 +79,7 @@ def tagged_object_list(request, tags=''): user_is_owner = (len(shelf) and request.user.is_authenticated() and request.user == shelf[0].user) - extra_where = 'NOT catalogue_tag.category = "set"' + extra_where = 'catalogue_tag.category NOT IN ("set", "book")' related_tags = models.Tag.objects.related_for_model(tags, model, counts=True, extra={'where': [extra_where]}) categories = split_tags(related_tags) @@ -93,11 +96,25 @@ def tagged_object_list(request, tags=''): ) +def book_fragments(request, book_slug, theme_slug): + book = get_object_or_404(models.Book, slug=book_slug) + book_tag = get_object_or_404(models.Tag, slug='l-' + book_slug) + theme = get_object_or_404(models.Tag, slug=theme_slug) + fragments = models.Fragment.tagged.with_all([book_tag, theme]) + + form = forms.SearchForm() + return render_to_response('catalogue/book_fragments.html', locals(), + context_instance=RequestContext(request)) + + def book_detail(request, slug): book = get_object_or_404(models.Book, slug=slug) + book_tag = get_object_or_404(models.Tag, slug = 'l-' + slug) tags = list(book.tags.filter(~Q(category='set'))) categories = split_tags(tags) book_children = book.children.all().order_by('parent_number') + extra_where = 'catalogue_tag.category = "theme"' + book_themes = models.Tag.objects.related_for_model(book_tag, models.Fragment, counts=True, extra={'where': [extra_where]}) form = forms.SearchForm() return render_to_response('catalogue/book_detail.html', locals(), @@ -124,9 +141,9 @@ def _tags_starting_with(prefix, user): books = models.Book.objects.filter(title__icontains=prefix) tags = models.Tag.objects.filter(name__icontains=prefix) if user.is_authenticated(): - tags = tags.filter(~Q(category='set') | Q(user=user)) + tags = tags.filter(~Q(category='book') & (~Q(category='set') | Q(user=user))) else: - tags = tags.filter(~Q(category='set')) + tags = tags.filter(~Q(category='book') & ~Q(category='set')) return list(books) + list(tags) diff --git a/wolnelektury/templates/catalogue/book_detail.html b/wolnelektury/templates/catalogue/book_detail.html index 028ac62a8..986605313 100644 --- a/wolnelektury/templates/catalogue/book_detail.html +++ b/wolnelektury/templates/catalogue/book_detail.html @@ -86,14 +86,12 @@
- {% if categories.theme %} -

Motywy w utworze

-
    - {% for theme in categories.theme %} -
  • {{ theme }}
  • - {% endfor %} -
- {% endif %} +

Motywy w utworze

+
diff --git a/wolnelektury/templates/catalogue/book_fragments.html b/wolnelektury/templates/catalogue/book_fragments.html new file mode 100644 index 000000000..4f1c0ebad --- /dev/null +++ b/wolnelektury/templates/catalogue/book_fragments.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} +{% load catalogue_tags pagination_tags %} + +{% block title %}Motyw {{ theme }} w utworze {{ book }} w WolneLektury.pl{% endblock %} + +{% block bodyid %}tagged-object-list{% endblock %} + +{% block body %} +

Motyw {{ theme }} w utworze {{ book }}

+
+

{{ form.q }} lub wróć do strony utworu

+
+ + {% autopaginate fragments 10 %} +
+
    + {% for fragment in fragments %} +
  1. {{ fragment.short_html }}
  2. + {% endfor %} +
+ {% paginate %} +
+
+
+ Zobacz opis utworu {{ book }} +
+
+
+
+
+
+ +
+

* Ładowanie

+
+
+{% endblock %} \ No newline at end of file