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):
# 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
"""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)
"""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()
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()
--- /dev/null
+{% 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 %}
{% 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 %}
{% if main %}
</section>
{% endif %}
-{% endspaceless %}
\ No newline at end of file
+{% endspaceless %}
--- /dev/null
+{% 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 %}
-# -*- 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
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()
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,
+ }
'raven.contrib.django.raven_compat',
'club.apps.ClubConfig',
+ 'debug_toolbar',
+
# allauth stuff
'allauth',
'allauth.account',
-# -*- 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.
#
}]
MIDDLEWARE_CLASSES = [
+ 'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'ssify.middleware.SsiMiddleware',
'django.middleware.cache.UpdateCacheMiddleware',
'api.drf_auth.PistonOAuthAuthentication',
)
}
+
+
+DEBUG_TOOLBAR_CONFIG = {
+ 'RESULTS_CACHE_SIZE': 100,
+}
-.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;
-#big-cite {
+.big-cite {
background-color: #444;
color: white;
padding: 0;
background: none;
}
- .cite {
+ .cite-text, .cite-text-small {
@include size(padding, 46px 10px 48px 0);
background: none;
color: white;
}
/* 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);
.white-box {
position: relative;
- .cite {
+ .cite-text, .cite-text-small {
display: none;
@media screen and (min-width: 768px) {
{% 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>
]
+if settings.DEBUG:
+ import debug_toolbar
+ urlpatterns = [
+ url(r'^__debug__/', include(debug_toolbar.urls)),
+ ] + urlpatterns
+
if settings.DEBUG:
urlpatterns += [
# Static files