From: Radek Czajka Date: Mon, 30 Jan 2012 11:43:46 +0000 (+0100) Subject: display fixes X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/3748094efcd5ed3b89408ece388a6e94ea42990c?ds=inline;hp=-c display fixes --- 3748094efcd5ed3b89408ece388a6e94ea42990c diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index cf80bebb5..e8bc13899 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -7,6 +7,7 @@ import feedparser from django import template from django.template import Node, Variable, Template, Context +from django.core.cache import cache from django.core.urlresolvers import reverse from django.contrib.auth.forms import UserCreationForm, AuthenticationForm from django.utils.translation import ugettext as _ @@ -266,17 +267,14 @@ def latest_blog_posts(feed_url, posts_to_show=5): def tag_list(tags, choices=None): if choices is None: choices = [] - if len(tags) == 1: + if len(tags) == 1 and tags[0].category not in [t.category for t in choices]: one_tag = tags[0] return locals() + @register.inclusion_tag('catalogue/inline_tag_list.html') def inline_tag_list(tags, choices=None): - if choices is None: - choices = [] - if len(tags) == 1: - one_tag = tags[0] - return locals() + return tag_list(tags, choices) @register.inclusion_tag('catalogue/book_info.html') @@ -348,14 +346,23 @@ def fragment_promo(arg=None): @register.inclusion_tag('catalogue/related_books.html') -def related_books(book, limit=6): - related = list(Book.objects.filter( - common_slug=book.common_slug).exclude(pk=book.pk)[:limit]) - limit -= len(related) - if limit: - related += Book.tagged.related_to(book, - Book.objects.exclude(common_slug=book.common_slug), - ignore_by_tag=book.book_tag())[:limit] +def related_books(book, limit=6, random=1): + cache_key = "catalogue.related_books.%d.%d" % (book.id, limit - random) + related = cache.get(cache_key) + if related is None: + print 'not in cache' + related = list(Book.objects.filter( + common_slug=book.common_slug).exclude(pk=book.pk)[:limit]) + limit -= len(related) + if limit > random: + related += Book.tagged.related_to(book, + Book.objects.exclude(common_slug=book.common_slug), + ignore_by_tag=book.book_tag())[:limit-random] + cache.set(cache_key, related, 1800) + if random: + related += list(Book.objects.exclude( + pk__in=[b.pk for b in related] + [book.pk] + ).order_by('?')[:random]) return { 'books': related, } diff --git a/apps/search/forms.py b/apps/search/forms.py index 60521f96a..9e0a07880 100755 --- a/apps/search/forms.py +++ b/apps/search/forms.py @@ -9,7 +9,7 @@ from search.fields import JQueryAutoCompleteSearchField class SearchForm(forms.Form): - q = JQueryAutoCompleteSearchField() # {'minChars': 2, 'selectFirst': True, 'cacheLength': 50, 'matchContains': "word"}) + q = JQueryAutoCompleteSearchField(label=_('Search')) # {'minChars': 2, 'selectFirst': True, 'cacheLength': 50, 'matchContains': "word"}) def __init__(self, source, *args, **kwargs): kwargs['auto_id'] = False @@ -18,4 +18,4 @@ class SearchForm(forms.Form): self.fields['q'].widget.attrs['autocomplete'] = 'off' self.fields['q'].widget.attrs['data-source'] = source if not 'q' in self.data: - self.fields['q'].widget.attrs['title'] = _('title, author, theme/topic, epoch, kind, genre, phrase') + self.fields['q'].widget.attrs['placeholder'] = _('title, author, theme/topic, epoch, kind, genre, phrase') diff --git a/apps/social/forms.py b/apps/social/forms.py index bbdc43ce5..cfa963177 100755 --- a/apps/social/forms.py +++ b/apps/social/forms.py @@ -19,7 +19,8 @@ class UserSetsForm(forms.Form): class ObjectSetsForm(forms.Form): - tags = forms.CharField(label=_('Tags (comma-separated)'), required=False) + tags = forms.CharField(label=_('Tags (comma-separated)'), required=False, + widget=forms.Textarea()) def __init__(self, obj, user, *args, **kwargs): self._obj = obj diff --git a/apps/social/templates/social/sets_form.html b/apps/social/templates/social/sets_form.html index ab982fe42..2ea1a867d 100755 --- a/apps/social/templates/social/sets_form.html +++ b/apps/social/templates/social/sets_form.html @@ -6,7 +6,8 @@ -
+
    {{ form.as_ul }} diff --git a/apps/social/templates/social/shelf_tags.html b/apps/social/templates/social/shelf_tags.html index 70108eb93..eabc961aa 100755 --- a/apps/social/templates/social/shelf_tags.html +++ b/apps/social/templates/social/shelf_tags.html @@ -1,4 +1,4 @@ -{% if tags %} +{% if tags.exists %}