From: Radek Czajka Date: Fri, 16 Sep 2011 09:36:02 +0000 (+0200) Subject: nicer footnotes dictionary X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/070d93a055b8dfd594664db308b310785d59af70?ds=sidebyside nicer footnotes dictionary --- diff --git a/apps/dictionary/templates/dictionary/note_list.html b/apps/dictionary/templates/dictionary/note_list.html index 7f3b43690..bc15e9541 100755 --- a/apps/dictionary/templates/dictionary/note_list.html +++ b/apps/dictionary/templates/dictionary/note_list.html @@ -1,9 +1,36 @@ {% extends "base.html" %} -{% load pagination_tags %} +{% load i18n pagination_tags %} {% block body %} +

Przypisy

+
+

{{ form.q }} {%trans "or" %} {% trans "return to the main page" %}

+
+ + +

+{% trans "By first letter" %}: +{% if letter %} + {% trans "all" %} +{% else %} + {% trans "all" %} +{% endif %} + +{% for let in letters %} + | + {% if let == letter %} + {{ let|upper }} + {% else %} + {{ let|upper }} + {% endif %} +{% endfor %} +

+
+ +{% 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 index 000000000..89d2ab9fb --- /dev/null +++ b/apps/dictionary/tests.py @@ -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 = """ + + rose --- kind of a flower. + + """ + + 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.') + diff --git a/apps/dictionary/urls.py b/apps/dictionary/urls.py index 3c59be992..84a30d7e0 100755 --- a/apps/dictionary/urls.py +++ b/apps/dictionary/urls.py @@ -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[a-z])/$', 'letter_notes', name='dictionary_notes'), ) diff --git a/apps/dictionary/views.py b/apps/dictionary/views.py new file mode 100755 index 000000000..9f0022475 --- /dev/null +++ b/apps/dictionary/views.py @@ -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())