('genre', _('genre')),
('theme', _('theme')),
('set', _('set')),
+ ('book', _('book')),
)
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'<a href="%s">%s</a>' % (tag.get_absolute_url(), tag.name) for tag in tags]
formats = []
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'):
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)
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)
# Public interface. Do not change this URLs.
url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)\.html$', 'book_text', name='book_text'),
url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)/$', 'book_detail', name='book_detail'),
+ url(r'^lektura/(?P<book_slug>[a-zA-Z0-9-]+)/motyw/(?P<theme_slug>[a-zA-Z0-9-]+)/$',
+ 'book_fragments', name='book_fragments'),
url(r'^(?P<tags>[a-zA-Z0-9-/]*)/$', 'tagged_object_list', name='tagged_object_list'),
)
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')
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)
)
+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(),
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)
</ul>
</div>
<div id="themes-list">
- {% if categories.theme %}
- <h2>Motywy w utworze</h2>
- <ul>
- {% for theme in categories.theme %}
- <li><a href="{{ theme.get_absolute_url }}">{{ theme }}</a></li>
- {% endfor %}
- </ul>
- {% endif %}
+ <h2>Motywy w utworze</h2>
+ <ul>
+ {% for theme in book_themes %}
+ <li><a href="{% url book_fragments book.slug,theme.slug %}">{{ theme }} ({{ theme.count }})</a></li>
+ {% endfor %}
+ </ul>
</div>
<div class="clearboth"></div>
</div>
--- /dev/null
+{% 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 %}
+ <h1>Motyw {{ theme }} w utworze {{ book }}</h1>
+ <form action="{% url search %}" method="get" accept-charset="utf-8" id="search-form">
+ <p>{{ form.q }} <input type="submit" value="Szukaj" /> <strong>lub</strong> <a href="{{ book.get_absolute_url }}">wróć do strony utworu</a></p>
+ </form>
+
+ {% autopaginate fragments 10 %}
+ <div id="books-list">
+ <ol>
+ {% for fragment in fragments %}
+ <li>{{ fragment.short_html }}</li>
+ {% endfor %}
+ </ol>
+ {% paginate %}
+ </div>
+ <div id="tags-list">
+ <div id="categories-list">
+ Zobacz opis <a href="{{ book.get_absolute_url }}">utworu {{ book }}</a>
+ </div>
+ <div id="themes-list">
+ </div>
+ <div class="clearboth"></div>
+ </div>
+ <div id="set-window">
+ <div class="header"><a href="#" class="jqmClose">Zamknij</a></div>
+ <div class="target">
+ <p><img src="/media/img/indicator.gif" alt="*"/> Ładowanie</p>
+ </div>
+ </div>
+{% endblock %}
\ No newline at end of file