from django.db.models import permalink
from django.dispatch import Signal
from django.utils.translation import ugettext_lazy as _
+
from newtagging.models import TagBase
from ssify import flush_ssi_includes
after_change = Signal(providing_args=['instance', 'languages'])
class UrlDeprecationWarning(DeprecationWarning):
- pass
+ def __init__(self, tags=None):
+ super(Tag.UrlDeprecationWarning, self).__init__()
+ self.tags = tags
categories_rev = {
'autor': 'author',
e.ambiguous_slugs = ambiguous_slugs
raise e
if deprecated:
- e = Tag.UrlDeprecationWarning()
- e.tags = real_tags
- raise e
+ raise Tag.UrlDeprecationWarning(tags=real_tags)
return real_tags
else:
return TagBase.get_tag_list(tags)
{% load i18n %}
{% load catalogue_tags %}
- {% if choices %}
- {% if category_choices %}
- <ul>
- <li class="header">{% trans "Chosen" %}:</li>
- {% for tag in category_choices %}
- <li class="active">{{ tag }} <a href="{% if gallery %}{% catalogue_url_gallery choices -tag %}{% else %}{% catalogue_url choices -tag %}{% endif %}">X</a></li>
- {% endfor %}
- </ul>
- {% endif %}
- {% if tags %}
+
+{% if choices %}
+ {% if category_choices %}
<ul>
- <li class="header">{% trans "Available" %}:</li>
- {% for tag in tags %}
- <li><a href="{% if gallery %}{% catalogue_url_gallery choices tag %}{% else %}{% catalogue_url choices tag %}{% endif %}">{{ tag }}{% if tag.count %} ({{ tag.count }}){% endif %}</a></li>
+ <li class="header">{% trans "Chosen" %}:</li>
+ {% for tag in category_choices %}
+ <li class="active">{{ tag }} <a href="{% catalogue_url list_type choices -tag %}">X</a></li>
{% endfor %}
</ul>
- {% endif %}
- {% else %}
- {% if tags %}
- <ul>
+ {% endif %}
+{% endif %}
+{% if tags %}
+ <ul>
<li class="header">{% trans "Available" %}:</li>
{% for tag in tags %}
- <li><a href="{% if gallery %}{{ tag.get_absolute_gallery_url }}{% else %}{{ tag.get_absolute_url }}{% endif %}">{{ tag }} {% if tag.count %} ({{ tag.count }}){% endif %}</a></li>
+ <li><a href="{% catalogue_url list_type choices tag %}">{{ tag }}{% if tag.count %} ({{ tag.count }}){% endif %}</a></li>
{% endfor %}
- </ul>
- {% endif %}
- {% endif %}
- {% if other %}
- <ul>
+ </ul>
+{% endif %}
+{% if other %}
+ <ul>
<li class="header">{% trans "Other" %}:</li>
{% for tag in other %}
- <li class="other"><a href="{% if gallery %}{{ tag.get_absolute_gallery_url }}{% else %}{{ tag.get_absolute_url }}{% endif %}">{{ tag }}</a></li>
+ <li class="other"><a href="{% catalogue_url list_type tag %}">{{ tag }}</a></li>
{% endfor %}
</ul>
- {% endif %}
+{% endif %}
<p class="header">{{ initial }}</p>
{% endif %}
{% for item in object_list %}
- <p><a href="{% if book %}{% url 'book_fragments' book.slug item.slug %}{% elif choice %}{% if gallery %}{% catalogue_url_gallery choice item %}{% else %}{% catalogue_url choice item %}{% endif %}{% elif gallery %}{{ item.get_absolute_gallery_url }}{% else %}{{ item.get_absolute_url }}{% endif %}">{{ item }}{% if item.count %} ({{ item.count}}){% endif %}</a></p>
+ <p><a href="{% if book %}{% url 'book_fragments' book.slug item.slug %}{% elif choice %}{% catalogue_url list_type choice item %}{% elif list_type == 'gallery' and item.get_absolute_gallery_url %}{{ item.get_absolute_gallery_url }}{% else %}{{ item.get_absolute_url }}{% endif %}">{{ item }}{% if item.count %} ({{ item.count}}){% endif %}</a></p>
{% endfor %}
{% if initial_blocks %}</div>{% endif %}
{% endfor %}
{% load i18n %}
{% load catalogue_tags %}
{% if one_tag %}
- <p>{% trans "See full category" %} <a href="{% catalogue_url one_tag %}">{{ one_tag }}</a></p>
+ <p>{% trans "See full category" %} <a href="{% catalogue_url 'default' one_tag %}">{{ one_tag }}</a></p>
{% else %}
<ul>
{% if choices %}
{% for tag in tags %}
- <li><a href="{% catalogue_url choices tag %}">{{ tag }}{% if tag.count %} ({{ tag.count }}){% endif %}</a></li>
+ <li><a href="{% catalogue_url 'default' choices tag %}">{{ tag }}{% if tag.count %} ({{ tag.count }}){% endif %}</a></li>
{% endfor %}
{% else %}
{% for tag in tags %}
{% load catalogue_tags switch_tag social_tags %}
{% load ssi_include from ssify %}
-{% block titleextra %}{% if tags %}{% title_from_tags tags %}{% elif gallery %}{% trans "Gallery" %}{% else %}{% trans "Literature" %}{% endif %}{% endblock %}
+{% block titleextra %}{% if tags %}{% title_from_tags tags %}{% elif list_type == 'gallery' %}{% trans "Gallery" %}{% elif list_type == 'audiobooks' %}{% trans "Audiobooks" %}{% else %}{% trans "Literature" %}{% endif %}{% endblock %}
{% block bodyid %}tagged-object-list{% endblock %}
<div class="tabbed-filter">
<h1>{% if tags %}
{% html_title_from_tags tags %}
- {% elif gallery %}{% trans "Gallery" %}{% else %}{% trans "Literature" %}
+ {% elif list_type == 'gallery' %}{% trans "Gallery" %}{% elif list_type == 'audiobooks' %}{% trans "Audiobooks" %}{% else %}{% trans "Literature" %}
{% endif %}
</h1>
<a class="tab white-box" data-id="genres">{% trans "Genres" %}</a>
<a class="tab white-box" data-id="kinds">{% trans "Kinds" %}</a>
{% if theme_is_set %}
- <a class="tab white-box" data-id="themes">{% trans "Themes" %}</a>
+ <a class="tab white-box" data-id="themes">{% trans "Themes" %}</a>
{% endif %}
</div>
-
</div>
+
<div class="tabbed-filter-contents">
<div id="authors" class="white-box normal-text tab-content">
- {% inline_tag_list categories.author tags 'author' gallery=gallery %}
+ {% inline_tag_list categories.author tags 'author' list_type=list_type %}
</div>
<div id="epochs" class="white-box normal-text tab-content">
- {% inline_tag_list categories.epoch tags 'epoch' gallery=gallery %}
+ {% inline_tag_list categories.epoch tags 'epoch' list_type=list_type %}
</div>
<div id="genres" class="white-box normal-text tab-content">
- {% inline_tag_list categories.genre tags 'genre' gallery=gallery %}
+ {% inline_tag_list categories.genre tags 'genre' list_type=list_type %}
</div>
<div id="kinds" class="white-box normal-text tab-content">
- {% inline_tag_list categories.kind tags 'kind' gallery=gallery %}
+ {% inline_tag_list categories.kind tags 'kind' list_type=list_type %}
</div>
{% if theme_is_set %}
<div id="themes" class="white-box normal-text tab-content">
- {% inline_tag_list categories.theme tags 'theme' gallery=gallery %}
+ {% inline_tag_list categories.theme tags 'theme' list_type=list_type %}
</div>
{% endif %}
</div>
-
-
-
- {% if theme_is_set %}
- {% work_list object_list %}
- {% else %}
+{% if theme_is_set %}
+ {% work_list object_list %}
+{% else %}
<div id="books-list">
{% if object_list %}
{% work_list best %}
{% if tags %}
<h2>{% trans "All matching works" %}</h2>
{% else %}
- <h2>{% trans "All works" %}</h2>
+ {% if list_type == 'audiobooks' %}
+ <h2>{% trans "Listing of all audiobooks" %}</h2>
+ {% else %}
+ <h2>{% trans "All works" %}</h2>
+ {% endif %}
+ {% endif %}
+ {% plain_list object_list by_author=True list_type=list_type %}
+ {% if daisy %}
+ <h2>{% trans "DAISY files" %}</h2>
+ {% plain_list daisy by_author=True %}
{% endif %}
- {% plain_list object_list by_author=True gallery=gallery %}
{% else %}
{% trans "Sorry! Search cirteria did not match any resources." %}
{% include "info/join_us.html" %}
{% endif %}
</div>
-
-
-
-{% if categories.theme %}
- <h2>{% trans "Motifs and themes" %}</h2>
- {% plain_list categories.theme choice=tags gallery=gallery %}
-{% endif %}
-
-
+ {% if categories.theme and list_type != 'audiobooks' %}
+ <h2>{% trans "Motifs and themes" %}</h2>
+ {% plain_list categories.theme choice=tags list_type=list_type %}
+ {% endif %}
{% endif %}
-
-
- {% for tag in tags %}
+{% for tag in tags %}
{% if tag.category != 'set' %}
- <h2>{% trans tag.category as c %}{{ c|capfirst }}: {{ tag }}</h2>
+ <h2>{% trans tag.category as c %}{{ c|capfirst }}: {{ tag }}</h2>
<div class="white-box">
- {% if tag.has_description %}
- {{ tag.description|safe }}
- {% else %}
- <em>{% trans "No description." %}</em>
- {% endif %}
+ {% if tag.has_description %}
+ {{ tag.description|safe }}
+ {% else %}
+ <em>{% trans "No description." %}</em>
+ {% endif %}
</div>
{% if tag.gazeta_link %}
- <div class="white-box"><a href="{{ tag.gazeta_link }}">
- {{ tag }} {% trans "in Lektury.Gazeta.pl" %}
- </a></div>
+ <div class="white-box"><a href="{{ tag.gazeta_link }}">
+ {{ tag }} {% trans "in Lektury.Gazeta.pl" %}
+ </a></div>
{% endif %}
{% if tag.wiki_link %}
- <div class="white-box">
- <a href="{{ tag.wiki_link }}">
- {{ tag }} {% trans "in Wikipedia" %}
- </a></div>
+ <div class="white-box">
+ <a href="{{ tag.wiki_link }}">
+ {{ tag }} {% trans "in Wikipedia" %}
+ </a></div>
{% endif %}
{% if tag.culturepl_link %}
- <div class="white-box">
- <a href="{{ tag.culturepl_link }}">
- {{ tag }} {% trans "in Culture.pl" %}
- </a></div>
+ <div class="white-box">
+ <a href="{{ tag.culturepl_link }}">
+ {{ tag }} {% trans "in Culture.pl" %}
+ </a></div>
{% endif %}
{% endif %}
- {% endfor %}
-
-
-
-
+{% endfor %}
{% endblock %}
from django.conf import settings
from django import template
+from django.core.cache import cache
from django.template import Node, Variable, Template, Context
from django.core.urlresolvers import reverse
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
tags_to_add = []
tags_to_remove = []
- for bit in bits[1:]:
+ for bit in bits[2:]:
if bit[0] == '-':
tags_to_remove.append(bit[1:])
else:
tags_to_add.append(bit)
- return CatalogueURLNode(tags_to_add, tags_to_remove)
-
-
-@register.tag
-def catalogue_url_gallery(parser, token):
- bits = token.split_contents()
-
- tags_to_add = []
- tags_to_remove = []
- for bit in bits[1:]:
- if bit[0] == '-':
- tags_to_remove.append(bit[1:])
- else:
- tags_to_add.append(bit)
-
- return CatalogueURLNode(tags_to_add, tags_to_remove, gallery=True)
+ return CatalogueURLNode(bits[1], tags_to_add, tags_to_remove)
class CatalogueURLNode(Node):
- def __init__(self, tags_to_add, tags_to_remove, gallery=False):
+ def __init__(self, list_type, tags_to_add, tags_to_remove):
self.tags_to_add = [Variable(tag) for tag in tags_to_add]
self.tags_to_remove = [Variable(tag) for tag in tags_to_remove]
- self.gallery = gallery
+ self.list_type_var = Variable(list_type)
def render(self, context):
+ list_type = self.list_type_var.resolve(context)
tags_to_add = []
tags_to_remove = []
pass
if len(tag_slugs) > 0:
- if self.gallery:
+ if list_type == 'gallery':
return reverse('tagged_object_list_gallery', kwargs={'tags': '/'.join(tag_slugs)})
+ elif list_type == 'audiobooks':
+ return reverse('tagged_object_list_audiobooks', kwargs={'tags': '/'.join(tag_slugs)})
else:
return reverse('tagged_object_list', kwargs={'tags': '/'.join(tag_slugs)})
else:
- return reverse('book_list')
+ if list_type == 'gallery':
+ return reverse('gallery')
+ elif list_type == 'audiobooks':
+ return reverse('audiobook_list')
+ else:
+ return reverse('book_list')
# @register.inclusion_tag('catalogue/tag_list.html')
-def tag_list(tags, choices=None, category=None, gallery=False):
+def tag_list(tags, choices=None, category=None, list_type='default'):
# print(tags, choices, category)
if choices is None:
choices = []
other = Tag.objects.filter(category=category).exclude(pk__in=[t.pk for t in tags])\
.exclude(pk__in=[t.pk for t in category_choices])
# Filter out empty tags.
- ct = ContentType.objects.get_for_model(Picture if gallery else Book)
+ ct = ContentType.objects.get_for_model(Picture if list_type == 'gallery' else Book)
other = other.filter(items__content_type=ct).distinct()
+ if list_type == 'audiobooks':
+ audiobook_tag_ids = cache.get('audiobook_tags')
+ if audiobook_tag_ids is None:
+ books_with_audiobook = Book.objects.filter(media__type__in=('mp3', 'ogg'))\
+ .distinct().values_list('pk', flat=True)
+ audiobook_tag_ids = Tag.objects.filter(
+ items__content_type=ct,
+ items__object_id__in=list(books_with_audiobook)).distinct().values_list('pk', flat=True)
+ audiobook_tag_ids = list(audiobook_tag_ids)
+ cache.set('audiobook_tags', audiobook_tag_ids)
+
+ other = other.filter(id__in=audiobook_tag_ids)
else:
other = []
return {
'one_tag': one_tag,
'choices': choices,
+ 'category_choices': category_choices,
'tags': tags,
'other': other,
+ 'list_type': list_type,
}
@register.inclusion_tag('catalogue/inline_tag_list.html')
-def inline_tag_list(tags, choices=None, category=None, gallery=False):
- return tag_list(tags, choices, category, gallery)
+def inline_tag_list(tags, choices=None, category=None, list_type='default'):
+ return tag_list(tags, choices, category, list_type)
@register.inclusion_tag('catalogue/collection_list.html')
@register.inclusion_tag('catalogue/plain_list.html', takes_context=True)
-def plain_list(context, object_list, with_initials=True, by_author=False, choice=None, book=None, gallery=False,
+def plain_list(context, object_list, with_initials=True, by_author=False, choice=None, book=None, list_type='default',
paged=True, initial_blocks=False):
names = [('', [])]
last_initial = None
'names': names,
'initial_blocks': initial_blocks,
'book': book,
- 'gallery': gallery,
+ 'list_type': list_type,
'choice': choice,
}
url(r'^rodzaj/$', 'tag_catalogue', {'category': 'kind'}, name='kind_catalogue'),
url(r'^motyw/$', 'tag_catalogue', {'category': 'theme'}, name='theme_catalogue'),
- url(r'^galeria/$', 'tagged_object_list', {'gallery': True}, name='gallery'),
+ url(r'^galeria/$', 'tagged_object_list', {'list_type': 'gallery'}, name='gallery'),
url(r'^kolekcje/$', 'collections', name='catalogue_collections'),
url(r'^lektury/$', 'tagged_object_list', name='book_list'),
url(r'^lektury/(?P<slug>[a-zA-Z0-9-]+)/$', 'collection', name='collection'),
- url(r'^audiobooki/$', 'audiobook_list', name='audiobook_list'),
+ url(r'^audiobooki/$', 'tagged_object_list', {'list_type': 'audiobooks'}, name='audiobook_list'),
url(r'^daisy/$', 'daisy_list', name='daisy_list'),
url(r'^tags/$', 'tags_starting_with', name='hint'),
url(r'^jtags/?$', 'json_tags_starting_with', name='jhint'),
url(r'^c/(?P<pk>.+)/box\.(?P<lang>.+)\.html', 'collection_box', name='catalogue_collection_box'),
# This should be the last pattern.
- url(r'^galeria/(?P<tags>[a-zA-Z0-9-/]*)/$', 'tagged_object_list', {'gallery': True},
+ url(r'^galeria/(?P<tags>[a-zA-Z0-9-/]*)/$', 'tagged_object_list', {'list_type': 'gallery'},
name='tagged_object_list_gallery'),
+ url(r'^audiobooki/(?P<tags>[a-zA-Z0-9-/]*)/$', 'tagged_object_list', {'list_type': 'audiobooks'},
+ name='tagged_object_list_audiobooks'),
url(r'^(?P<tags>[a-zA-Z0-9-/]*)/$', 'tagged_object_list', name='tagged_object_list'),
)
# TODO: Rewrite this hellish piece of code which tries to do everything
-def tagged_object_list(request, tags='', gallery=False):
+def tagged_object_list(request, tags='', list_type='default'):
raw_tags = tags
# preliminary tests and conditions
+ gallery = list_type == 'gallery'
+ audiobooks = list_type == 'audiobooks'
try:
tags = Tag.get_tag_list(tags)
except Tag.DoesNotExist:
pass
# beginning of digestion
- theme_is_set = [tag for tag in tags if tag.category == 'theme']
- shelf_is_set = [tag for tag in tags if tag.category == 'set']
+ theme_is_set = any(tag.category == 'theme' for tag in tags)
+ shelf_is_set = any(tag.category == 'set' for tag in tags)
only_shelf = shelf_is_set and len(tags) == 1
- only_my_shelf = only_shelf and request.user.is_authenticated() and request.user == tags[0].user
+ only_my_shelf = only_shelf and request.user == tags[0].user
tags_pks = [tag.pk for tag in tags]
- objects = None
+ if gallery and shelf_is_set:
+ raise Http404
+ daisy = None
if theme_is_set:
# Only fragments (or pirctureareas) here.
shelf_tags = [tag for tag in tags if tag.category == 'set']
fragments = Fragment.tagged.with_all(fragment_tags)
if shelf_tags:
- if gallery:
- # TODO: Pictures on shelves not supported yet.
- raise Http404
- else:
- 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))
categories = split_tags(
Tag.objects.usage_for_queryset(fragments, counts=True).exclude(pk__in=tags_pks),
objects = fragments
else:
if gallery:
- if shelf_is_set:
- # TODO: Pictures on shelves not supported yet.
- raise Http404
+ # TODO: Pictures on shelves not supported yet.
+ if tags:
+ objects = Picture.tagged.with_all(tags)
else:
- if tags:
- objects = Picture.tagged.with_all(tags)
- else:
- objects = Picture.objects.all()
+ objects = Picture.objects.all()
areas = PictureArea.objects.filter(picture__in=objects)
categories = split_tags(
Tag.objects.usage_for_queryset(
# WTF: was outside if, overwriting value assigned if shelf_is_set
related_book_tags = get_top_level_related_tags(tags)
+ if audiobooks:
+ if objects != all_books:
+ all_books = all_books.filter(media__type__in=('mp3', 'ogg')).distinct()
+ objects = objects.filter(media__type__in=('mp3', 'ogg')).distinct()
+ else:
+ all_books = objects = objects.filter(media__type__in=('mp3', 'ogg')).distinct()
+ daisy = objects.filter(media__type='daisy').distinct().order_by('sort_key_author', 'sort_key')
+
fragments = Fragment.objects.filter(book__in=all_books)
categories = split_tags(
if not gallery and not objects and len(tags) == 1:
tag = tags[0]
- if (tag.category in ('theme', 'thing') and PictureArea.tagged.with_any([tag]).exists() or
+ if tag.category in ('theme', 'thing') and (
+ PictureArea.tagged.with_any([tag]).exists() or
Picture.tagged.with_any([tag]).exists()):
return redirect('tagged_object_list_gallery', raw_tags, permanent=False)
'tag_ids': tags_pks,
'theme_is_set': theme_is_set,
'best': best,
- 'gallery': gallery,
+ 'list_type': list_type,
+ 'daisy': daisy,
},
context_instance=RequestContext(request))