REDAKCJA_URL = "http://redakcja.wolnelektury.pl"
GOOD_LICENSES = set([r'CC BY \d\.\d', r'CC BY-SA \d\.\d'])
+ RELATED_RANDOM_PICTURE_CHANCE = .5
def _more_DONT_BUILD(self, value):
for format_ in ['cover', 'pdf', 'epub', 'mobi', 'fb2', 'txt']:
{% spaceless %}
{% load catalogue_random_book from catalogue_tags %}
+{% load picture_random_picture from picture_tags %}
{% load ssi_include from ssify %}
+{% for pic in pics %}
+ {% ssi_include 'picture_mini' pk=pic.pk %}
+{% endfor %}
+
{% for book in books %}
{% ssi_include 'catalogue_book_mini' pk=book.pk %}
{% endfor %}
{% if random %}
- {% catalogue_random_book random_excluded as random_pk %}
- {{ random_pk.if }}
- {% ssi_include 'catalogue_book_mini' pk=random_pk %}
- {{ random_pk.endif }}
+ {% catalogue_random_book random_excluded_books as random_book_pk %}
+ {% picture_random_picture random_excluded_pics unless=random_book_pk as random_pic_pk %}
+ {{ random_book_pk.if }}
+ {% ssi_include 'catalogue_book_mini' pk=random_book_pk %}
+ {{ random_book_pk.endif }}
+ {{ random_pic_pk.if }}
+ {% ssi_include 'picture_mini' pk=random_pic_pk %}
+ {{ random_pic_pk.endif }}
{% endif %}
{% endspaceless %}
\ No newline at end of file
# 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 random import randint, random
from urlparse import urlparse
from django.conf import settings
return locals()
+# TODO: These are no longer just books.
@register.inclusion_tag('catalogue/related_books.html', takes_context=True)
-def related_books(context, book, limit=6, random=1, taken=0):
+def related_books(context, instance, limit=6, random=1, taken=0):
limit = limit - taken
- related = Book.tagged.related_to(book,
- Book.objects.exclude(common_slug=book.common_slug)
- ).exclude(ancestor=book)[:limit-random]
- random_excluded = [b.pk for b in related] + [book.pk]
+ max_books = limit - random
+ is_picture = isinstance(instance, Picture)
+
+ pics_qs = Picture.objects.all()
+ if is_picture:
+ pics_qs = pics_qs.exclude(pk=instance.pk)
+ pics = Picture.tagged.related_to(instance, pics_qs)
+ if pics.exists():
+ # Reserve one spot for an image.
+ max_books -= 1
+
+ books_qs = Book.objects.all()
+ if not is_picture:
+ books_qs = books_qs.exclude(common_slug=instance.common_slug).exclude(ancestor=instance)
+ books = Book.tagged.related_to(instance, books_qs)[:max_books]
+
+ pics = pics[:1 + max_books - books.count()]
+
+ random_excluded_books = [b.pk for b in books]
+ random_excluded_pics = [p.pk for p in pics]
+ (random_excluded_pics if is_picture else random_excluded_books).append(instance.pk)
+
return {
'request': context['request'],
- 'books': related,
+ 'books': books,
+ 'pics': pics,
'random': random,
- 'random_excluded': random_excluded,
+ 'random_excluded_books': random_excluded_books,
+ 'random_excluded_pics': random_excluded_pics,
}
@ssi_variable(register, patch_response=[add_never_cache_headers])
def catalogue_random_book(request, exclude_ids):
+ from .. import app_settings
+ if random() < app_settings.RELATED_RANDOM_PICTURE_CHANCE:
+ return None
queryset = Book.objects.exclude(pk__in=exclude_ids)
count = queryset.count()
if count:
url(r'^obraz/(?P<slug>%s).html$' % SLUG, 'picture_viewer', name='picture_viewer'),
url(r'^obraz/(?P<slug>%s)/$' % SLUG, 'picture_detail'),
+ url(r'^p/(?P<pk>\d+)/mini\.(?P<lang>.+)\.html', 'picture_mini', name='picture_mini'),
url(r'^p/(?P<pk>\d+)/short\.(?P<lang>.+)\.html', 'picture_short', name='picture_short'),
url(r'^pa/(?P<pk>\d+)/short\.(?P<lang>.+)\.html', 'picturearea_short', name='picture_area_short'),
)
template % (self.pk, lang)
for template in [
'/katalog/p/%d/short.%s.html',
+ '/katalog/p/%d/mini.%s.html',
]
for lang in languages
])
{% block body %}
{% picture_wide picture %}
+
+{% spaceless %}
+
+<section class="see-also" style="display: inline-block;">
+<h1>{% trans "See also" %}:</h1>
+{% related_books picture %}
+</section>
+{% endspaceless %}
+
{% endblock %}
{% extends "base.html" %}
{% load i18n %}
+{% load catalogue_tags %}
{% load static %}
{% load ssi_include from ssify %}
</div>
<div class='clearboth'></div>
-<div id="books-list">
- <ol class="work-list">{% spaceless %}
-{% for picture in book_list %}
- <li class="Picture-item">
- {% ssi_include 'picture_short' pk=picture.pk %}
- </li>
-{% endfor %}
- {% endspaceless %}</ol>
-</div>
+
+
+
+{% work_list book_list %}
+
+{% spaceless %}
{% load thumbnail %}
<div class="book-mini-box">
- <a href="{{ book.get_absolute_url }}">
- {% if picture.cover %}
- <img src="
- {% thumbnail book.cover "139x193" as thumb %}
- {{ thumb.url }}
- {% empty %}
- {{ book.cover.url }}
- {% endthumbnail %}
- " alt="{{ author_str }} – {{ book.title }}" class="cover" />
+ <div class="book-mini-box-inner">
+ {% if with_link %}
+ <a href="{{ picture.get_absolute_url }}">
+ {% endif %}
+ {% if picture.image_file %}
+ <img src="{% thumbnail picture.image_file "139x193" crop="center" as thumb %}{{ thumb.url }}{% empty %}{{ picture.image_file.url }}{% endthumbnail %}" alt="{{ author_str }} – {{ picture.title }}" class="cover" />
{% endif %}
<div class="desc">
<span class="mono author">{{ author_str }}</span>
- <span class="title">{{ book.title }}</span>
+ <span class="title">{{ picture.title }}</span>
</div>
+ {% if with_link %}
</a>
+ {% endif %}
+ </div>
</div>
+{% endspaceless %}
\ No newline at end of file
{% block picture-view %}
<a href="{{ main_link }}">
-{% thumbnail picture.image_file "535" upscale="false" as thumb %}
+{% thumbnail picture.image_file "535" upscale=0 as thumb %}
<img class="cover" src="{{thumb.url}}"/></a>
{% endthumbnail %}
{% endblock %}
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
+import logging
+from random import randint
from django import template
from django.core.urlresolvers import reverse
+from django.utils.cache import add_never_cache_headers
+import sorl.thumbnail.default
+from ssify import ssi_variable
from catalogue.utils import split_tags
from ..engine import CustomCroppingEngine
-import sorl.thumbnail.default
-import logging
+from ..models import Picture
+
register = template.Library()
sorl.thumbnail.default.engine = _engine
return th.url
+
+
+@ssi_variable(register, patch_response=[add_never_cache_headers])
+def picture_random_picture(request, exclude_ids, unless=None):
+ if unless:
+ return None
+ queryset = Picture.objects.exclude(pk__in=exclude_ids).exclude(image_file='')
+ count = queryset.count()
+ if count:
+ return queryset[randint(0, count - 1)].pk
+ else:
+ return None
return HttpResponse(_("Error importing file: %r") % import_form.errors)
+@ssi_included
+def picture_mini(request, pk, with_link=True):
+ picture = get_object_or_404(Picture, pk=pk)
+ author_str = ", ".join(tag.name
+ for tag in picture.tags.filter(category='author'))
+ return render(request, 'picture/picture_mini_box.html', {
+ 'picture': picture,
+ 'author_str': author_str,
+ 'with_link': with_link,
+ })
+
+
@ssi_included
def picture_short(request, pk):
picture = get_object_or_404(Picture, pk=pk)