{% extends "base.html" %}
-{% load pagination_tags %}
+{% load i18n pagination_tags %}
{% block body %}
+ <h1>Przypisy</h1>
+ <form action="{% url search %}" method="get" accept-charset="utf-8" id="search-form">
+ <p>{{ form.q }} <input type="submit" value="{% trans "Search" %}" /> <strong>{%trans "or" %}</strong> <a href="{% url main_page %}">{% trans "return to the main page" %}</a></p>
+ </form>
+
+
+<p>
+{% trans "By first letter" %}:
+{% if letter %}
+ <a href='{% url dictionary_notes %}'>{% trans "all" %}</a>
+{% else %}
+ <strong>{% trans "all" %}</strong>
+{% endif %}
+
+{% for let in letters %}
+ |
+ {% if let == letter %}
+ <strong>{{ let|upper }}</strong>
+ {% else %}
+ <a href='{% url dictionary_notes let %}'>{{ let|upper }}</a>
+ {% endif %}
+{% endfor %}
+</p>
+<hr/>
+
+{% if object_list %}
+
{% autopaginate object_list 100 %}
{% paginate %}
{% for obj in object_list %}
{% endfor %}
{% paginate %}
+{% endif %}
+
{% endblock %}
--- /dev/null
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from django.core.files.base import ContentFile
+from catalogue.test_utils import *
+from catalogue.models import Book
+from dictionary.models import Note
+
+
+class DictionaryTests(WLTestCase):
+
+ def setUp(self):
+ WLTestCase.setUp(self)
+ self.book_info = BookInfoStub(
+ url=u"http://wolnelektury.pl/example/default-book",
+ about=u"http://wolnelektury.pl/example/URI/default_book",
+ title=u"Default Book",
+ author=PersonStub(("Jim",), "Lazy"),
+ kind="X-Kind",
+ genre="X-Genre",
+ epoch="X-Epoch",
+ )
+
+ def test_book_with_fragment(self):
+ BOOK_TEXT = """<utwor>
+ <opowiadanie>
+ <akap><pe><slowo_obce>rose</slowo_obce> --- kind of a flower.</pe></akap>
+ </opowiadanie></utwor>
+ """
+
+ book = Book.from_text_and_meta(ContentFile(BOOK_TEXT), self.book_info)
+
+ self.assertEqual(
+ len(self.client.get('/przypisy/').context['object_list']),
+ 1,
+ 'There should be a note on the note list.')
+
+ self.assertEqual(
+ len(self.client.get('/przypisy/a/').context['object_list']),
+ 0,
+ 'There should not be a note for the letter A.')
+
+ self.assertEqual(
+ len(self.client.get('/przypisy/r/').context['object_list']),
+ 1,
+ 'There should be a note for the letter R.')
+
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django.conf.urls.defaults import *
-from dictionary.models import Note
-all_notes = Note.objects.all()
-
-urlpatterns = patterns('django.views.generic.list_detail',
- url(r'^$', 'object_list', {'queryset': all_notes}),
+urlpatterns = patterns('dictionary.views',
+ url(r'^$', 'letter_notes', name='dictionary_notes'),
+ url(r'(?P<letter>[a-z])/$', 'letter_notes', name='dictionary_notes'),
)
--- /dev/null
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from django.views.generic.list_detail import object_list
+from catalogue.forms import SearchForm
+from dictionary.models import Note
+
+def letter_notes(request, letter=None):
+ form = SearchForm()
+ letters = [chr(a) for a in range(ord('a'), ord('z')+1)]
+ objects = Note.objects.all()
+ if letter:
+ objects = objects.filter(sort_key__startswith=letter)
+
+ return object_list(request, queryset=objects, extra_context=locals())