From 69191eddb9e4221d964a7e5b044ff7c5dfe38315 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 24 Jan 2012 16:09:22 +0100 Subject: [PATCH] display changes, mostly in book boxes --- apps/catalogue/models.py | 12 ++++ apps/catalogue/templatetags/catalogue_tags.py | 25 +++++---- apps/catalogue/views.py | 22 +------- apps/lesmianator/models.py | 11 ++-- apps/social/templates/social/shelf_tags.html | 7 +++ apps/social/templatetags/social_tags.py | 12 +++- wolnelektury/settings.py | 3 +- wolnelektury/static/css/base.css | 6 ++ wolnelektury/static/css/book_box.css | 18 +++++- wolnelektury/static/css/social/shelf_tags.css | 18 ++++++ wolnelektury/static/js/dialogs.js | 3 +- .../templates/catalogue/book_short.html | 28 ++++++---- .../templates/catalogue/book_wide.html | 26 ++++++++- .../catalogue/tagged_object_list.html | 56 ++++++++++--------- 14 files changed, 164 insertions(+), 83 deletions(-) create mode 100755 apps/social/templates/social/shelf_tags.html create mode 100755 wolnelektury/static/css/social/shelf_tags.css diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 9f26ae5b2..03cf0c891 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -782,14 +782,26 @@ class Book(models.Model): return self._related_info else: rel = {'tags': {}, 'media': {}} + tags = self.tags.filter(category__in=( 'author', 'kind', 'genre', 'epoch')) tags = split_tags(tags) for category in tags: rel['tags'][category] = [ (t.name, t.get_absolute_url()) for t in tags[category]] + for media_format in BookMedia.formats: rel['media'][media_format] = self.has_media(media_format) + + book = self + parents = [] + while book.parent: + parents.append((book.parent.title, book.parent.slug)) + book = book.parent + parents = parents[::-1] + if parents: + rel['parents'] = parents + if self.pk: type(self).objects.filter(pk=self.pk).update(_related_info=rel) return rel diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 2254299d5..542f1cde2 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -17,8 +17,9 @@ from django.conf import settings from django.template.defaultfilters import stringfilter from django.utils.translation import ugettext as _ +from catalogue import forms from catalogue.utils import split_tags -from catalogue.models import Book, Fragment +from catalogue.models import Book, Fragment, Tag register = template.Library() @@ -282,27 +283,29 @@ def book_info(book): @register.inclusion_tag('catalogue/book_wide.html', takes_context=True) def book_wide(context, book): - formats = {} - # files generated during publication - for ebook_format in book.ebook_formats: - if book.has_media(ebook_format): - formats[ebook_format] = book.get_media(ebook_format) + theme_counter = book.theme_counter + book_themes = Tag.objects.filter(pk__in=theme_counter.keys()) + for tag in book_themes: + tag.count = theme_counter[tag.pk] + extra_info = book.get_extra_info_value() + hide_about = extra_info.get('about', '').startswith('http://wiki.wolnepodreczniki.pl') return { - 'related': book.related_info(), 'book': book, - 'formats': formats, + 'related': book.related_info(), 'extra_info': book.get_extra_info_value(), + 'hide_about': hide_about, + 'themes': book_themes, + 'custom_pdf_form': forms.CustomPDFForm(), 'request': context.get('request'), - 'fragment': book.choose_fragment(), } @register.inclusion_tag('catalogue/book_short.html', takes_context=True) def book_short(context, book): return { - 'related': book.related_info(), 'book': book, + 'related': book.related_info(), 'request': context.get('request'), } @@ -310,8 +313,8 @@ def book_short(context, book): @register.inclusion_tag('catalogue/book_mini_box.html') def book_mini(book): return { - 'related': book.related_info(), 'book': book, + 'related': book.related_info(), } diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 463b3303b..20fecb724 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -213,29 +213,9 @@ def book_detail(request, slug): try: book = models.Book.objects.get(slug=slug) except models.Book.DoesNotExist: - return pdcounter_views.book_stub_detail(request, kwargs['slug']) + return pdcounter_views.book_stub_detail(request, slug) - book_tag = book.book_tag() - tags = list(book.tags.filter(~Q(category='set'))) - categories = split_tags(tags) book_children = book.children.all().order_by('parent_number', 'sort_key') - - _book = book - parents = [] - while _book.parent: - parents.append(_book.parent) - _book = _book.parent - parents = reversed(parents) - - theme_counter = book.theme_counter - book_themes = models.Tag.objects.filter(pk__in=theme_counter.keys()) - for tag in book_themes: - tag.count = theme_counter[tag.pk] - - extra_info = book.get_extra_info_value() - hide_about = extra_info.get('about', '').startswith('http://wiki.wolnepodreczniki.pl') - - custom_pdf_form = forms.CustomPDFForm() return render_to_response('catalogue/book_detail.html', locals(), context_instance=RequestContext(request)) diff --git a/apps/lesmianator/models.py b/apps/lesmianator/models.py index 1d057c2da..1b53efdcd 100644 --- a/apps/lesmianator/models.py +++ b/apps/lesmianator/models.py @@ -123,16 +123,15 @@ class Continuations(models.Model): @classmethod def for_book(cls, book, length=3): - from librarian import text - # count from this book only output = StringIO() - f = open(book.xml_file.path) - text.transform(f, output, False, ('raw-text',)) - f.close() + wldoc = book.wldocument(parse_dublincore=False) + output = wldoc.as_text(('raw-text',)).get_string() + del wldoc + conts = {} last_word = '' - for letter in output.getvalue().decode('utf-8').strip().lower(): + for letter in output.decode('utf-8').strip().lower(): mydict = conts.setdefault(last_word, {}) mydict.setdefault(letter, 0) mydict[letter] += 1 diff --git a/apps/social/templates/social/shelf_tags.html b/apps/social/templates/social/shelf_tags.html new file mode 100755 index 000000000..70108eb93 --- /dev/null +++ b/apps/social/templates/social/shelf_tags.html @@ -0,0 +1,7 @@ +{% if tags %} + +{% endif %} diff --git a/apps/social/templatetags/social_tags.py b/apps/social/templatetags/social_tags.py index deac93df0..e78f20f0a 100755 --- a/apps/social/templatetags/social_tags.py +++ b/apps/social/templatetags/social_tags.py @@ -28,4 +28,14 @@ def cite_promo(ctx=None, fallback=False): 'cite': cites.order_by('?')[0] if cites.exists() else None, 'fallback': fallback, 'ctx': ctx, - } \ No newline at end of file + } + + +@register.inclusion_tag('social/shelf_tags.html', takes_context=True) +def shelf_tags(context, book): + user = context['request'].user + if not user.is_authenticated(): + tags = [] + else: + tags = book.tags.filter(category='set', user=user).exclude(name='') + return {'tags': tags} diff --git a/wolnelektury/settings.py b/wolnelektury/settings.py index be5f32cbf..f5c9cf275 100644 --- a/wolnelektury/settings.py +++ b/wolnelektury/settings.py @@ -198,7 +198,8 @@ COMPRESS_CSS = { 'css/book_box.css', 'css/catalogue.css', 'css/sponsors.css', - + + 'css/social/shelf_tags.css', 'css/ui-lightness/jquery-ui-1.8.16.custom.css', ], 'output_filename': 'css/all.min?.css', diff --git a/wolnelektury/static/css/base.css b/wolnelektury/static/css/base.css index a188285e2..33223b09e 100755 --- a/wolnelektury/static/css/base.css +++ b/wolnelektury/static/css/base.css @@ -35,6 +35,12 @@ h1 { margin-top: .4em } +ul.plain { + list-style:none; + margin: 0; + padding: 0; +} + .left-column { width: 47em; float: left; diff --git a/wolnelektury/static/css/book_box.css b/wolnelektury/static/css/book_box.css index 2df2fa4e4..f54f5ff1e 100755 --- a/wolnelektury/static/css/book_box.css +++ b/wolnelektury/static/css/book_box.css @@ -112,6 +112,9 @@ font-size: 1.1em; color: #707b7a; display: block; + overflow:hidden; + text-overflow: ellipsis; + white-space: nowrap; } .book-mini-box .title { font-size: 1.4em; @@ -126,7 +129,7 @@ } .book-wide-box .book-box-body { - height: 21.8em; + min-height: 17em; } .book-box-head { @@ -134,6 +137,9 @@ margin-top: 1.4em; margin-bottom: 1em; } +.book-box-head a { + color: black; +} .book-box-head .author { font-size: 1.1em; } @@ -194,6 +200,12 @@ margin-left: 14em; } +.book-wide-box #themes-list-wrapper { + margin-left: 14em; +} + + + .book-box-read a:before { content: "\2609"; font-family: WL-Nav; @@ -203,7 +215,7 @@ font-weight: normal; } -.book-box-download a:before { +.book-box-download a.downarrow:before { content: "\21E9"; font-family: WL-Nav; font-size: 2.25em; @@ -263,7 +275,7 @@ ul.inline-items li { .book-wide-box .other-download { float: left; - width: 22.5em; + width: 22em; margin: 6em 1.5em 0em 1.5em; } diff --git a/wolnelektury/static/css/social/shelf_tags.css b/wolnelektury/static/css/social/shelf_tags.css new file mode 100755 index 000000000..b963b1c0c --- /dev/null +++ b/wolnelektury/static/css/social/shelf_tags.css @@ -0,0 +1,18 @@ +.social-shelf-tags { + list-style: none; + padding: 0; + margin: 1em 0; +} + +.social-shelf-tags li { + display: inline-block; + margin-right:1em; +} + +.social-shelf-tags a { + display: block; + padding: .3em 1em; + background: #ABDADE; + color: #0b838d; + border-radius: 1em; +} diff --git a/wolnelektury/static/js/dialogs.js b/wolnelektury/static/js/dialogs.js index 0df6508eb..846331cdd 100755 --- a/wolnelektury/static/js/dialogs.js +++ b/wolnelektury/static/js/dialogs.js @@ -79,6 +79,7 @@ $('.target', $window).text(response.message); setTimeout(function() { $window.jqmHide() }, 1000); $form.submit(); + location.reload(); } else { $('.error', $window).remove(); @@ -145,7 +146,7 @@ }; var ajaxable_callbacks = { - 'social-book-sets': update_star + 'social-book-sets': location.reload }; diff --git a/wolnelektury/templates/catalogue/book_short.html b/wolnelektury/templates/catalogue/book_short.html index 90ac6af01..a6d3028d1 100644 --- a/wolnelektury/templates/catalogue/book_short.html +++ b/wolnelektury/templates/catalogue/book_short.html @@ -38,10 +38,12 @@
{% for name, url in related.tags.author %} - {{ name }}{% if not forloop.last %}, {% endif %} + {{ name }}{% if not forloop.last %}, + {% endif %}{% endfor %}{% for title, slug in related.parents %}, + {{ title }} {% endfor %}
-
{{ book.title }}
+
{% spaceless %} @@ -65,8 +67,13 @@ {% endspaceless %} + + {% shelf_tags book %}
+ + {% block book-box-extra-info %}{% endblock %} + {% block box-append %} {% endblock %} +
diff --git a/wolnelektury/templates/catalogue/book_wide.html b/wolnelektury/templates/catalogue/book_wide.html index ebbea8c02..dfe57b656 100644 --- a/wolnelektury/templates/catalogue/book_wide.html +++ b/wolnelektury/templates/catalogue/book_wide.html @@ -1,9 +1,29 @@ {% extends "catalogue/book_short.html" %} {% load i18n %} +{% load tag_list from catalogue_tags %} {% load cite_promo from social_tags %} + {% block box-class %}book-wide-box{% endblock %} + +{% block book-box-extra-info %} +{% if themes %} +
+

{% trans "motifs and themes" %}

+
+ +
+
+{% endif %} +{% endblock %} + + {% block right-column %}
@@ -12,10 +32,11 @@

{% trans "See" %}

-

{% trans "Download" %}

-
    +
    • {% if related.media.mp3 or related.media.ogg %} {% trans "Download all audiobooks for this book" %}: diff --git a/wolnelektury/templates/catalogue/tagged_object_list.html b/wolnelektury/templates/catalogue/tagged_object_list.html index 0777d84ee..45459f16e 100644 --- a/wolnelektury/templates/catalogue/tagged_object_list.html +++ b/wolnelektury/templates/catalogue/tagged_object_list.html @@ -62,33 +62,11 @@ {% cite_promo tags 1 %}
      + {% if last_tag.gazeta_link or last_tag.wiki_link %}

      {% trans "See also" %}:

      -
      - -
      -

      {% trans "Download" %}:

      - -
      - -
- -
- - - - - + +
+ {% comment %} +

{% trans "Download" %}:

+ + {% endcomment %} +
+ +
+ +
+ + + + +
{% if object_list %} {% work_list object_list %} {% else %} -- 2.20.1