def get_tag_list(tags):
if isinstance(tags, basestring):
real_tags = []
+ ambiguous_slugs = []
category = None
- for name in tags.split('/'):
+ tags_splitted = tags.split('/')
+ for index, name in enumerate(tags_splitted):
if name in Tag.categories_rev:
category = Tag.categories_rev[name]
else:
real_tags.append(Tag.objects.get(slug=name, category=category))
category = None
else:
- real_tags.append(Tag.objects.get(slug=name))
+ try:
+ real_tags.append(Tag.objects.exclude(category='book').get(slug=name))
+ except Tag.MultipleObjectsReturned, e:
+ ambiguous_slugs.append(name)
+
if category:
- raise Http404
- return real_tags
+ # something strange left off
+ raise Tag.DoesNotExist()
+ if ambiguous_slugs:
+ # some tags should be qualified
+ e = Tag.MultipleObjectsReturned()
+ e.tags = real_tags
+ e.ambiguous_slugs = ambiguous_slugs
+ raise e
+ else:
+ return real_tags
else:
return TagBase.get_tag_list(tags)
context_instance=RequestContext(request))
+def differentiate_tags(request, tags, ambiguous_slugs):
+ beginning = '/'.join(tag.url_chunk for tag in tags)
+ unparsed = '/'.join(ambiguous_slugs[1:])
+ options = []
+ for tag in models.Tag.objects.exclude(category='book').filter(slug=ambiguous_slugs[0]):
+ options.append({
+ 'url_args': '/'.join((beginning, tag.url_chunk, unparsed)).rstrip('/'),
+ 'tags': tags + [tag]
+ })
+ return render_to_response('catalogue/differentiate_tags.html',
+ {'tags': tags, 'options': options, 'unparsed': unparsed},
+ context_instance=RequestContext(request))
+
+
def tagged_object_list(request, tags=''):
try:
tags = models.Tag.get_tag_list(tags)
except models.Tag.DoesNotExist:
raise Http404
+ except models.Tag.MultipleObjectsReturned, e:
+ return differentiate_tags(request, e.tags, e.ambiguous_slugs)
try:
if len(tags) > settings.MAX_TAG_LIST:
--- /dev/null
+{% extends "base.html" %}
+{% load i18n %}
+{% load catalogue_tags %}
+
+{% block title %}{% title_from_tags tags %} w WolneLektury.pl{% endblock %}
+
+{% block bodyid %}differentiate_tags{% endblock %}
+
+{% block body %}
+ <h1>{% title_from_tags tags %}</h1>
+ {% breadcrumbs tags %}
+
+ <p>{% trans "The criteria are ambiguous. Please select one of the following options:" %}</p>
+ <div id="books-list">
+ {% for option in options %}
+ <div class="book-description"
+ <p><a href="{% url tagged_object_list option.url_args %}">{% title_from_tags option.tags %}{% if unparsed %}, …{% endif %}</a></p>
+ </div>
+ {% endfor %}
+ </div>
+
+ <div id="set-window">
+ <div class="header"><a href="#" class="jqmClose">{% trans "Close" %}</a></div>
+ <div class="target">
+ <p><img src="{{ STATIC_URL }}img/indicator.gif" alt="*"/> {% trans "Loading" %}</p>
+ </div>
+ </div>
+{% endblock %}
\ No newline at end of file