nicer footnotes dictionary
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 16 Sep 2011 09:36:02 +0000 (11:36 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 16 Sep 2011 09:36:02 +0000 (11:36 +0200)
apps/dictionary/templates/dictionary/note_list.html
apps/dictionary/tests.py [new file with mode: 0755]
apps/dictionary/urls.py
apps/dictionary/views.py [new file with mode: 0755]

index 7f3b436..bc15e95 100755 (executable)
@@ -1,9 +1,36 @@
 {% 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 %}
@@ -16,4 +43,6 @@
 {% endfor %}
 {% paginate %}
 
+{% endif %}
+
 {% endblock %}
diff --git a/apps/dictionary/tests.py b/apps/dictionary/tests.py
new file mode 100755 (executable)
index 0000000..89d2ab9
--- /dev/null
@@ -0,0 +1,48 @@
+# -*- 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.')
+
index 3c59be9..84a30d7 100755 (executable)
@@ -3,12 +3,10 @@
 # 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'),
 )
 
diff --git a/apps/dictionary/views.py b/apps/dictionary/views.py
new file mode 100755 (executable)
index 0000000..9f00224
--- /dev/null
@@ -0,0 +1,16 @@
+# -*- 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())