From: Radek Czajka Date: Mon, 15 Jul 2019 10:58:08 +0000 (+0200) Subject: Cite base X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/019dfd7e87efcf03b08decb7af6552df3e3df215?ds=inline Cite base --- diff --git a/src/social/admin.py b/src/social/admin.py index bceb89008..75c7156ef 100755 --- a/src/social/admin.py +++ b/src/social/admin.py @@ -25,7 +25,7 @@ class CiteAdmin(admin.ModelAdmin): def nonempty_text(self, cite): if cite.text.strip(): return cite.text - return "(%s)" % ((cite.image_title or '').strip() or cite.link) + return "(%s)" % (cite.image_title or cite.link or '-').strip() nonempty_text.short_description = _('text') def has_image(self, cite): diff --git a/src/social/models.py b/src/social/models.py index 588b2eb8e..cd78a3cff 100644 --- a/src/social/models.py +++ b/src/social/models.py @@ -1,6 +1,7 @@ # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from random import randint from django.db import models from django.conf import settings from django.core.exceptions import ValidationError @@ -26,6 +27,13 @@ class BannerGroup(models.Model): """This is used for testing.""" return "%s?banner_group=%d" % (reverse('main_page'), self.id) + def get_banner(self): + banners = self.cite_set.all() + count = banners.count() + if not count: + return None + return banners[randint(0, count-1)] + class Cite(models.Model): book = models.ForeignKey(Book, verbose_name=_('book'), null=True, blank=True) @@ -67,6 +75,26 @@ class Cite(models.Model): """This is used for testing.""" return "%s?choose_cite=%d" % (reverse('main_page'), self.id) + def has_box(self): + return self.video or self.picture + + def has_body(self): + return self.vip or self.text or self.book + + def layout(self): + if self.banner: + # TODO: move all banners to pictures. + return 'banner' + pieces = [] + if self.has_box(): + pieces.append('box') + if self.has_body(): + pieces.append('text') + if self.small: + pieces.append('small') + return '-'.join(pieces) + + def save(self, *args, **kwargs): ret = super(Cite, self).save(*args, **kwargs) self.flush_includes() @@ -114,3 +142,6 @@ class CarouselItem(models.Model): raise ValidationError(_('Either banner or banner group is required.')) elif self.banner and self.banner_group: raise ValidationError(_('Either banner or banner group is required.')) + + def get_banner(self): + return self.banner or self.banner_group.get_banner() diff --git a/src/social/templates/social/carousel.html b/src/social/templates/social/carousel.html new file mode 100644 index 000000000..4d3e4e50c --- /dev/null +++ b/src/social/templates/social/carousel.html @@ -0,0 +1,16 @@ +{% spaceless %} + +{% load i18n %} + + + +{% endspaceless %} diff --git a/src/social/templates/social/cite_promo.html b/src/social/templates/social/cite_promo.html old mode 100755 new mode 100644 index 8c0bddedc..f7c4e4832 --- a/src/social/templates/social/cite_promo.html +++ b/src/social/templates/social/cite_promo.html @@ -1,21 +1,30 @@ {% spaceless %} {% load i18n %} + {% load embed_video from social_tags %} {% if main %} -
+
{% endif %} {% if cite %} - + {% if cite.banner %} {% else %} + {% if cite.video %} + {% embed_video cite.video %} + {% endif %} + {% if cite.picture %} + + {% endif %} {% if cite.vip %}

{{ cite.vip }} {% trans "recommends" %}:

{% endif %} -
- {{ cite.text|linebreaksbr|safe }} -
+ {% if cite.text %} +
+ {{ cite.text|linebreaksbr|safe }} +
+ {% endif %} {% if cite.book %}

{{ cite.book.pretty_title }}

{% endif %} @@ -26,4 +35,4 @@ {% if main %}
{% endif %} -{% endspaceless %} \ No newline at end of file +{% endspaceless %} diff --git a/src/social/templates/social/embed_video.html b/src/social/templates/social/embed_video.html new file mode 100644 index 000000000..9810e7f2a --- /dev/null +++ b/src/social/templates/social/embed_video.html @@ -0,0 +1,6 @@ +{% if youtube_id %} + + {% endif %} diff --git a/src/social/templates/social/my_shelf.html b/src/social/templates/social/my_shelf.html old mode 100755 new mode 100644 diff --git a/src/social/templates/social/sets_form.html b/src/social/templates/social/sets_form.html old mode 100755 new mode 100644 diff --git a/src/social/templates/social/shelf_tags.html b/src/social/templates/social/shelf_tags.html old mode 100755 new mode 100644 diff --git a/src/social/templatetags/social_tags.py b/src/social/templatetags/social_tags.py old mode 100755 new mode 100644 index 898d3ba4a..8f67bdfcb --- a/src/social/templatetags/social_tags.py +++ b/src/social/templatetags/social_tags.py @@ -1,7 +1,7 @@ -# -*- 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. # +import re from django import template from django.utils.functional import lazy from django.utils.cache import add_never_cache_headers @@ -9,6 +9,7 @@ from catalogue.models import Book from ssify import ssi_variable from ssify.utils import ssi_vary_on_cookie from social.utils import likes, get_or_choose_cite +from ..models import Carousel register = template.Library() @@ -47,3 +48,24 @@ def book_shelf_tags(request, book_id): ctx = {'tags': tags} return template.loader.render_to_string('social/shelf_tags.html', ctx) return lazy(get_value, str)() + + +@register.inclusion_tag('social/carousel.html') +def carousel(slug): + # TODO: cache + try: + carousel = Carousel.objects.get(slug=slug) + except Carousel.DoesNotExist: + # TODO: add sanity check for install. + carousel = None + return { + 'carousel': carousel + } + + +@register.inclusion_tag('social/embed_video.html') +def embed_video(url): + m = re.match(r'https://www.youtube.com/watch\?v=([^&;]+)', url) + return { + 'youtube_id': m.group(1) if m else None, + } diff --git a/src/wolnelektury/settings/apps.py b/src/wolnelektury/settings/apps.py index 1ddd97907..213f2e7ce 100644 --- a/src/wolnelektury/settings/apps.py +++ b/src/wolnelektury/settings/apps.py @@ -62,6 +62,8 @@ INSTALLED_APPS_CONTRIB = [ 'raven.contrib.django.raven_compat', 'club.apps.ClubConfig', + 'debug_toolbar', + # allauth stuff 'allauth', 'allauth.account', diff --git a/src/wolnelektury/settings/basic.py b/src/wolnelektury/settings/basic.py index ebadbb8e0..2684cc4cf 100644 --- a/src/wolnelektury/settings/basic.py +++ b/src/wolnelektury/settings/basic.py @@ -1,4 +1,3 @@ -# -*- 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. # @@ -60,6 +59,7 @@ TEMPLATES = [{ }] MIDDLEWARE_CLASSES = [ + 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'ssify.middleware.SsiMiddleware', 'django.middleware.cache.UpdateCacheMiddleware', diff --git a/src/wolnelektury/settings/contrib.py b/src/wolnelektury/settings/contrib.py index 978b6db44..308353afc 100644 --- a/src/wolnelektury/settings/contrib.py +++ b/src/wolnelektury/settings/contrib.py @@ -41,3 +41,8 @@ REST_FRAMEWORK = { 'api.drf_auth.PistonOAuthAuthentication', ) } + + +DEBUG_TOOLBAR_CONFIG = { + 'RESULTS_CACHE_SIZE': 100, +} diff --git a/src/wolnelektury/static/scss/main/cite.scss b/src/wolnelektury/static/scss/main/cite.scss index eb3a51139..1e64cd316 100755 --- a/src/wolnelektury/static/scss/main/cite.scss +++ b/src/wolnelektury/static/scss/main/cite.scss @@ -1,4 +1,14 @@ -.cite { +.big-cite { + height: 270px; + + .cite-box,.cite-text { + display: block; + height: 100%; + position: relative; + } +} + +.cite-text, .cite-text-small { display: block; color: black; background: white; diff --git a/src/wolnelektury/static/scss/main/main_page.scss b/src/wolnelektury/static/scss/main/main_page.scss index 7a9ab6a1e..ddd3e0bde 100755 --- a/src/wolnelektury/static/scss/main/main_page.scss +++ b/src/wolnelektury/static/scss/main/main_page.scss @@ -1,4 +1,4 @@ -#big-cite { +.big-cite { background-color: #444; color: white; padding: 0; @@ -17,7 +17,7 @@ background: none; } - .cite { + .cite-text, .cite-text-small { @include size(padding, 46px 10px 48px 0); background: none; color: white; @@ -93,7 +93,7 @@ } /* a long cite displays smaller */ - .cite-small .cite-body { + .cite-text-small .cite-body { @include size(font-size, 16px); @media screen and (min-width: 30em) { @include size(font-size, 20px); @@ -245,7 +245,7 @@ section { .white-box { position: relative; - .cite { + .cite-text, .cite-text-small { display: none; @media screen and (min-width: 768px) { diff --git a/src/wolnelektury/templates/main_page.html b/src/wolnelektury/templates/main_page.html index 4a627e6c3..c3064127f 100644 --- a/src/wolnelektury/templates/main_page.html +++ b/src/wolnelektury/templates/main_page.html @@ -1,4 +1,5 @@ {% extends "base/base.html" %} +{% load carousel from social_tags %} {% load static from staticfiles %} {% load i18n catalogue_tags infopages_tags %} {% load ssi_include from ssify %} @@ -17,11 +18,7 @@ {% block body %} {% spaceless %} - {% if cite %} - {% cache 3600 main_cite cite.pk %} - {% include "social/cite_promo.html" with main=True %} - {% endcache %} - {% endif %} + {% carousel 'main' %}

{% trans "In our digital library you will find" %}

diff --git a/src/wolnelektury/urls.py b/src/wolnelektury/urls.py index 0ebc4891d..f284857c4 100644 --- a/src/wolnelektury/urls.py +++ b/src/wolnelektury/urls.py @@ -99,6 +99,12 @@ urlpatterns += [ ] +if settings.DEBUG: + import debug_toolbar + urlpatterns = [ + url(r'^__debug__/', include(debug_toolbar.urls)), + ] + urlpatterns + if settings.DEBUG: urlpatterns += [ # Static files