From: Jan Szejko Date: Tue, 26 Jan 2016 15:21:55 +0000 (+0100) Subject: fix #3667: poprawa wyświetlanania losowych przykładów w katalogach tagów X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/4d63dddcde34ef242f0f4283adc39ff04737a9c6 fix #3667: poprawa wyświetlanania losowych przykładów w katalogach tagów --- diff --git a/src/catalogue/templates/catalogue/tag_box.html b/src/catalogue/templates/catalogue/tag_box.html index e16e5534d..b6dc69713 100644 --- a/src/catalogue/templates/catalogue/tag_box.html +++ b/src/catalogue/templates/catalogue/tag_box.html @@ -2,11 +2,11 @@ {% load i18n %} {% load catalogue_tags %}
-

{% trans tag.category as c %}{{ c|capfirst }}: {{ tag }}

- {% if tag.description %} - {{ tag.description|safe|truncatewords_html:40 }} - {% else %} +

{% trans tag.category as c %}{{ c|capfirst }}: {{ tag }}

+ {% if tag.description %} + {{ tag.description|strip_tag:"a"|safe|truncatewords_html:40 }} + {% else %} {% trans "No description." %} - {% endif %} + {% endif %}
{% endspaceless %} diff --git a/src/catalogue/templatetags/catalogue_tags.py b/src/catalogue/templatetags/catalogue_tags.py index 117abba0c..941ab63c7 100644 --- a/src/catalogue/templatetags/catalogue_tags.py +++ b/src/catalogue/templatetags/catalogue_tags.py @@ -490,3 +490,10 @@ def choose_fragment(request, book_id=None, tag_ids=None, unless=False): fragment_count = fragments.count() fragment = fragments[randint(0, fragment_count - 1)] if fragment_count else None return fragment.pk if fragment is not None else None + + +@register.filter +def strip_tag(html, tag_name): + # docelowo może być warto zainstalować BeautifulSoup do takich rzeczy + import re + return re.sub(r"<.?%s\b[^>]*>" % tag_name, "", html) diff --git a/src/catalogue/views.py b/src/catalogue/views.py index e71895f0d..847831d69 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -712,8 +712,10 @@ def tag_catalogue(request, category): else: tags = list(get_top_level_related_tags((), categories=(category,))) - if len(tags) > 3: - best = random.sample(tags, 3) + tags = [tag for tag in tags if tag.description] + + if len(tags) > 4: + best = random.sample(tags, 4) else: best = tags diff --git a/src/wolnelektury/static/scss/main/base.scss b/src/wolnelektury/static/scss/main/base.scss index 2225c0f26..1a25dbdc9 100755 --- a/src/wolnelektury/static/scss/main/base.scss +++ b/src/wolnelektury/static/scss/main/base.scss @@ -156,7 +156,9 @@ ul.plain { @media screen and (min-width: 768px) { display: inline-block; + vertical-align: top; width: 48%; margin-right: 1%; + @include size(margin-bottom, 10px); } }