Cite base
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 15 Jul 2019 10:58:08 +0000 (12:58 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 15 Jul 2019 10:58:08 +0000 (12:58 +0200)
16 files changed:
src/social/admin.py
src/social/models.py
src/social/templates/social/carousel.html [new file with mode: 0644]
src/social/templates/social/cite_promo.html [changed mode: 0755->0644]
src/social/templates/social/embed_video.html [new file with mode: 0644]
src/social/templates/social/my_shelf.html [changed mode: 0755->0644]
src/social/templates/social/sets_form.html [changed mode: 0755->0644]
src/social/templates/social/shelf_tags.html [changed mode: 0755->0644]
src/social/templatetags/social_tags.py [changed mode: 0755->0644]
src/wolnelektury/settings/apps.py
src/wolnelektury/settings/basic.py
src/wolnelektury/settings/contrib.py
src/wolnelektury/static/scss/main/cite.scss
src/wolnelektury/static/scss/main/main_page.scss
src/wolnelektury/templates/main_page.html
src/wolnelektury/urls.py

index bceb890..75c7156 100755 (executable)
@@ -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):
index 588b2eb..cd78a3c 100644 (file)
@@ -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 (file)
index 0000000..4d3e4e5
--- /dev/null
@@ -0,0 +1,16 @@
+{% spaceless %}
+
+{% load i18n %}
+
+<div class="carousel carousel-{{ carousel.slug }}">
+  {% for item in carousel.carouselitem_set.all %}
+    {% with banner=item.get_banner %}
+    <!-- {{ banner.id }} -->
+      {% if banner %}
+        {% include 'social/cite_promo.html' with cite=banner main=True %}
+      {% endif %}
+    {% endwith %}
+  {% endfor %}
+</div>
+
+{% endspaceless %}
old mode 100755 (executable)
new mode 100644 (file)
index 8c0bdde..f7c4e48
@@ -1,21 +1,30 @@
 {% spaceless %}
   {% load i18n %}
+  {% load embed_video from social_tags %}
 
   {% if main %}
-    <section id="big-cite"{% if cite.image and not cite.banner %} style="background-image: url('{{ cite.image.url }}'); background-position: 50% {{ cite.image_shift|default_if_none:50 }}%;"{% endif %} {% if cite.banner %}class="banner"{% endif %}>
+    <section class="big-cite"{% if cite.image and not cite.banner %} style="background-image: url('{{ cite.image.url }}'); background-position: 50% {{ cite.image_shift|default_if_none:50 }}%;"{% endif %} {% if cite.banner %}class="banner"{% endif %}>
   {% endif %}
 
   {% if cite %}
-    <a href="{{ cite.link }}" {% if not cite.banner %}class="cite{% if cite.small %} cite-small{% endif %}{% endif %}">
+  <a href="{{ cite.link }}" class="cite-{{ cite.layout }}">
       {% if cite.banner %}
         <img src="{{ cite.image.url }}" width="100%"/>
       {% else %}
+        {% if cite.video %}
+       {% embed_video cite.video %}
+       {% endif %}
+       {% if cite.picture %}
+               <img src="{{ cite.picture.url }}">
+       {% endif %}
         {% if cite.vip %}
           <p class='vip mono'><span>{{ cite.vip }} {% trans "recommends" %}:</span></p>
         {% endif %}
-        <blockquote class="cite-body">
-          <span>{{ cite.text|linebreaksbr|safe }}</span>
-        </blockquote>
+       {% if cite.text %}
+          <blockquote class="cite-body">
+            <span>{{ cite.text|linebreaksbr|safe }}</span>
+          </blockquote>
+       {% endif %}
         {% if cite.book %}
           <p class="source mono"><span>{{ cite.book.pretty_title }}</span></p>
         {% endif %}
@@ -26,4 +35,4 @@
   {% if main %}
     </section>
   {% 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 (file)
index 0000000..9810e7f
--- /dev/null
@@ -0,0 +1,6 @@
+{% if youtube_id %}
+<iframe style="position: absolute; left:0;right:0;height:100%;width:100%;"
+       type="text/html" width="100%" height="360"
+                                                  src="http://www.youtube.com/embed/{{ youtube_id }}"
+        frameborder="0"></iframe>
+         {% endif %}
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 898d3ba..8f67bdf
@@ -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,
+    }
index 1ddd979..213f2e7 100644 (file)
@@ -62,6 +62,8 @@ INSTALLED_APPS_CONTRIB = [
     'raven.contrib.django.raven_compat',
     'club.apps.ClubConfig',
 
+    'debug_toolbar',
+
     # allauth stuff
     'allauth',
     'allauth.account',
index ebadbb8..2684cc4 100644 (file)
@@ -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',
index 978b6db..308353a 100644 (file)
@@ -41,3 +41,8 @@ REST_FRAMEWORK = {
         'api.drf_auth.PistonOAuthAuthentication',
     )
 }
+
+
+DEBUG_TOOLBAR_CONFIG = {
+    'RESULTS_CACHE_SIZE': 100,
+}
index eb3a511..1e64cd3 100755 (executable)
@@ -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;
index 7a9ab6a..ddd3e0b 100755 (executable)
@@ -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) {
index 4a627e6..c306412 100644 (file)
@@ -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 %}
 
 {% block body %}
   {% spaceless %}
-    {% if cite %}
-      {% cache 3600 main_cite cite.pk %}
-        {% include "social/cite_promo.html" with main=True %}
-      {% endcache %}
-    {% endif %}
+    {% carousel 'main' %}
 
     <section id="main-library">
       <h1>{% trans "In our digital library you will find" %}</h1>
index 0ebc489..f284857 100644 (file)
@@ -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