limit_choices_to={'category': 'author'},
blank=True
)
- kind = models.CharField('rodzaj', max_length=10, blank=False, default='book', db_index=True,
- choices=(('book', 'książki'), ('picture', 'obrazy')))
listed = models.BooleanField('na liście', default=True, db_index=True)
role = models.CharField(max_length=128, blank=True, db_index=True, choices=[
('', '–'),
+++ /dev/null
-{% spaceless %}
- {% load catalogue_random_book from catalogue_tags %}
- {% load picture_random_picture from picture_tags %}
-
- {% for pic in pics %}
- {{ pic.mini_box }}
- {% endfor %}
-
- {% for book in books %}
- {{ book.mini_box }}
- {% endfor %}
-
- {% if random %}
- {% catalogue_random_book random_excluded_books as random_book %}
- {% if random_book %}
- {{ random_book.mini_box }}
- {% else %}
- {% picture_random_picture random_excluded_pics as random_pic %}
- {% if random_pic %}
- {{ random_pic.mini_box }}
- {% endif %}
- {% endif %}
- {% endif %}
-{% endspaceless %}
from catalogue.feeds import AudiobookFeed
from catalogue.models import Book
from catalogue import views
-import picture.views
import search.views
urlpatterns = [
- path('obraz/strona/', picture.views.picture_page, name='picture_page'),
- # pictures - currently pictures are coupled with catalogue, hence the url is here
- path('obraz/', picture.views.picture_list_thumb, name='picture_list_thumb'),
- path('obraz/<slug:slug>.html', picture.views.picture_viewer, name='picture_viewer'),
- path('obraz/<slug:slug>/', picture.views.picture_detail, name='picture_detail'),
-
# old search page - redirected
path('szukaj/', RedirectView.as_view(
url='/szukaj/', query_string=True, permanent=True)),
# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
#
import json
-from django.core.files.base import ContentFile
-from django.db import models, migrations
-from django.template.loader import render_to_string
-
-
-def rebuild_extra_info(apps, schema_editor):
- Picture = apps.get_model("picture", "Picture")
- from librarian.picture import PictureInfo
- from librarian import dcparser
- for pic in Picture.objects.all():
- info = dcparser.parse(pic.xml_file.path, PictureInfo)
- pic.extra_info = json.dumps(info.to_dict())
- areas_json = json.loads(pic.areas_json)
- for field in areas_json['things'].values():
- field['object'] = field['object'].capitalize()
- pic.areas_json = json.dumps(areas_json)
- html_text = render_to_string('picture/picture_info.html', {
- 'things': areas_json['things'],
- 'themes': areas_json['themes'],
- })
- pic.html_file.save("%s.html" % pic.slug, ContentFile(html_text))
- pic.save()
+from django.db import migrations
class Migration(migrations.Migration):
]
operations = [
- migrations.RunPython(rebuild_extra_info),
]
tags = managers.TagDescriptor(catalogue.models.Tag)
tag_relations = GenericRelation(catalogue.models.Tag.intermediary_table_model)
- short_html_url_name = 'picture_area_short'
-
- @classmethod
- def rectangle(cls, picture, kind, coords):
- pa = PictureArea()
- pa.picture = picture
- pa.kind = kind
- pa.area = json.dumps(coords)
- return pa
-
- def get_area_json(self):
- return json.loads(self.area)
-
class Picture(models.Model):
"""
tags = managers.TagDescriptor(catalogue.models.Tag)
tag_relations = GenericRelation(catalogue.models.Tag.intermediary_table_model)
- short_html_url_name = 'picture_short'
-
- is_picture = True
-
- class AlreadyExists(Exception):
- pass
-
class Meta:
ordering = ('sort_key_author', 'sort_key')
verbose_name = 'obraz'
verbose_name_plural = 'obrazy'
- def get_extra_info_json(self):
- return json.loads(self.extra_info or '{}')
-
- def save(self, force_insert=False, force_update=False, **kwargs):
- from sortify import sortify
-
- self.sort_key = sortify(self.title)[:120]
-
- try:
- author = self.authors().first().sort_key
- except AttributeError:
- author = ''
- self.sort_key_author = author
-
- ret = super(Picture, self).save(force_insert, force_update)
-
- return ret
-
def __str__(self):
return self.title
-
- def authors(self):
- return self.tags.filter(category='author')
-
- def epochs(self):
- return self.tags.filter(category='epoch')
-
- def genres(self):
- return self.tags.filter(category='genre')
-
- def kinds(self):
- return self.tags.filter(category='kind')
-
- def tag_unicode(self, category):
- relations = prefetched_relations(self, category)
- if relations:
- return ', '.join(rel.tag.name for rel in relations)
- else:
- return ', '.join(self.tags.filter(category=category).values_list('name', flat=True))
-
- def author_unicode(self):
- return self.tag_unicode('author')
-
- def tags_by_category(self):
- return split_tags(self.tags)
-
- def get_absolute_url(self):
- return reverse('picture_detail', args=[self.slug])
-
- def get_initial(self):
- try:
- return re.search(r'\w', self.title, re.U).group(0)
- except AttributeError:
- return ''
-
- def get_next(self):
- try:
- return type(self).objects.filter(sort_key__gt=self.sort_key)[0]
- except IndexError:
- return None
-
- def get_previous(self):
- try:
- return type(self).objects.filter(sort_key__lt=self.sort_key).order_by('-sort_key')[0]
- except IndexError:
- return None
-
- @classmethod
- def from_xml_file(cls, xml_file, image_file=None, image_store=None, overwrite=False):
- """
- Import xml and it's accompanying image file.
- If image file is missing, it will be fetched by librarian.picture.ImageStore
- which looks for an image file in the same directory the xml is, with extension matching
- its mime type.
- """
- from sortify import sortify
- from django.core.files import File
- from librarian.picture import WLPicture, ImageStore
- close_xml_file = False
- close_image_file = False
-
- if image_file is not None and not isinstance(image_file, File):
- image_file = File(open(image_file, 'rb'))
- close_image_file = True
-
- if not isinstance(xml_file, File):
- xml_file = File(open(xml_file))
- close_xml_file = True
-
- with transaction.atomic():
- # use librarian to parse meta-data
- if image_store is None:
- image_store = ImageStore(picture_storage.path('images'))
- picture_xml = WLPicture.from_file(xml_file, image_store=image_store)
-
- picture, created = Picture.objects.get_or_create(slug=picture_xml.slug[:120])
- if not created and not overwrite:
- raise Picture.AlreadyExists('Picture %s already exists' % picture_xml.slug)
-
- picture.areas.all().delete()
- picture.title = str(picture_xml.picture_info.title)
- picture.extra_info = json.dumps(picture_xml.picture_info.to_dict())
-
- picture_tags = set([t for (t, rel) in catalogue.models.Tag.tags_from_info(picture_xml.picture_info)])
- for tag in picture_tags:
- if not tag.for_pictures:
- tag.for_pictures = True
- tag.save()
-
- area_data = {'themes': {}, 'things': {}}
-
- # Treat all names in picture XML as in default language.
- lang = settings.LANGUAGE_CODE
-
- for part in picture_xml.partiter():
- if picture_xml.frame:
- c = picture_xml.frame[0]
- part['coords'] = [[p[0] - c[0], p[1] - c[1]] for p in part['coords']]
- if part.get('object', None) is not None:
- _tags = set()
- for objname in part['object'].split(','):
- objname = objname.strip()
- assert objname, 'Empty object name'
- # str.capitalize() is wrong, because it also lowers letters
- objname = objname[0].upper() + objname[1:]
- tag, created = catalogue.models.Tag.objects.get_or_create(
- slug=slugify(objname), category='thing')
- if created:
- tag.name = objname
- setattr(tag, 'name_%s' % lang, tag.name)
- tag.sort_key = sortify(tag.name)
- tag.for_pictures = True
- tag.save()
- area_data['things'][tag.slug] = {
- 'object': objname,
- 'coords': part['coords'],
- }
-
- _tags.add(tag)
- if not tag.for_pictures:
- tag.for_pictures = True
- tag.save()
- area = PictureArea.rectangle(picture, 'thing', part['coords'])
- area.save()
- # WTF thing area does not inherit tags from picture and theme area does, is it intentional?
- area.tags = _tags
- else:
- _tags = set()
- for motifs in part['themes']:
- for motif in motifs.split(','):
- tag, created = catalogue.models.Tag.objects.get_or_create(
- slug=slugify(motif), category='theme')
- if created:
- tag.name = motif
- tag.sort_key = sortify(tag.name)
- tag.for_pictures = True
- tag.save()
- # motif_tags.add(tag)
- _tags.add(tag)
- if not tag.for_pictures:
- tag.for_pictures = True
- tag.save()
- area_data['themes'][tag.slug] = {
- 'theme': motif,
- 'coords': part['coords']
- }
-
- logging.debug("coords for theme: %s" % part['coords'])
- area = PictureArea.rectangle(picture, 'theme', part['coords'])
- area.save()
- area.tags = _tags.union(picture_tags)
-
- picture.tags = picture_tags
- picture.areas_json = json.dumps(area_data)
-
- if image_file is not None:
- img = image_file
- else:
- img = picture_xml.image_file()
-
- modified = cls.crop_to_frame(picture_xml, img)
- modified = cls.add_source_note(picture_xml, modified)
-
- picture.width, picture.height = modified.size
-
- modified_file = BytesIO()
- modified.save(modified_file, format='JPEG', quality=95)
- # FIXME: hardcoded extension - detect from DC format or orginal filename
- picture.image_file.save(path.basename(picture_xml.image_path), File(modified_file))
-
- picture.xml_file.save("%s.xml" % picture.slug, File(xml_file))
- picture.save()
-
- if close_xml_file:
- xml_file.close()
- if close_image_file:
- image_file.close()
-
- return picture
-
- @classmethod
- def crop_to_frame(cls, wlpic, image_file):
- img = Image.open(image_file)
- if wlpic.frame is None or wlpic.frame == [[0, 0], [-1, -1]]:
- return img
- img = img.crop(itertools.chain(*wlpic.frame))
- return img
-
- @staticmethod
- def add_source_note(wlpic, img):
- from PIL import ImageDraw, ImageFont
- from librarian import get_resource
-
- annotated = Image.new(img.mode, (img.size[0], img.size[1] + 40), (255, 255, 255))
- annotated.paste(img, (0, 0))
- annotation = Image.new('RGB', (img.size[0] * 3, 120), (255, 255, 255))
- ImageDraw.Draw(annotation).text(
- (30, 15),
- wlpic.picture_info.source_name,
- (0, 0, 0),
- font=ImageFont.truetype(get_resource("fonts/DejaVuSerif.ttf"), 75)
- )
- annotated.paste(annotation.resize((img.size[0], 40), Image.ANTIALIAS), (0, img.size[1]))
- return annotated
-
- @property
- def info(self):
- if not hasattr(self, '_info'):
- from librarian import dcparser
- from librarian import picture
- info = dcparser.parse(self.xml_file.path, picture.PictureInfo)
- self._info = info
- return self._info
-
- def pretty_title(self, html_links=False):
- names = [(tag.name, tag.get_absolute_url()) for tag in self.authors().only('name', 'category', 'slug')]
- names.append((self.title, self.get_absolute_url()))
-
- if html_links:
- names = ['<a href="%s">%s</a>' % (tag[1], tag[0]) for tag in names]
- else:
- names = [tag[0] for tag in names]
- return ', '.join(names)
-
- @cached_render('picture/picture_mini_box.html')
- def mini_box(self):
- return {
- 'picture': self,
- }
-
- def related_themes(self):
- return catalogue.models.Tag.objects.usage_for_queryset(
- self.areas.all(), counts=True).filter(category__in=('theme', 'thing'))
-
- def clear_cache(self):
- clear_cached_renders(self.mini_box)
+++ /dev/null
-{% extends "admin/change_list.html" %}
-
-{% block content %}
- <form action="{% url 'import_picture' %}" method="post" enctype="multipart/form-data">
- {% csrf_token %}
- <p>
- XML: <input type="file" id="id_picture_xml_file" name="picture_xml_file" /><br/>
- Obraz: <input type="file" id="id_picture_image_file" name="picture_image_file" /><br/>
- <input type="submit" value="Zaimportuj obraz"/>
- </p>
- </form>
- {{ block.super }}
-{% endblock content %}
+++ /dev/null
-{% extends 'base.html' %}
-{% load i18n %}
-
-{% load chunks %}
-{% load static %}
-{% load thumbnail %}
-{% load catalogue_tags %}
-
-
-{% block global-content %}
- <div class="l-container">
- <div class="l-breadcrumb">
- <a href="/"><span>{% trans "Strona główna" %}</span></a>
- <a href="/katalog/obraz/"><span>{% trans "Obrazy" %}</span></a>
- </div>
- </div>
-
-
- <main class="l-main">
- <section class="l-section lay-s-col-rev">
- <aside class="l-aside">
- <ul class="l-aside__info">
- <li><span>Epoka:</span> {% for tag in picture.epochs %}<a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a> {% endfor %}</li>
- <li><span>Rodzaj:</span> {% for tag in picture.kinds %}<a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a> {% endfor %}</li>
- <li><span>Gatunek:</span> {% for tag in picture.genres %}<a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a> {% endfor %}</li>
- {% with extra_info=picture.get_extra_info_json %}
- {% if extra_info.styles %}
- <li>
- <span>{% trans "Styl" context "obrazu" %}:</span>
- {% for tag in extra_info.styles %}
- <a>{{ tag }}</a>
- {% if not forloop.last %}, {% endif %}
- {% endfor %}
- </li>
- {% endif %}
-
- {% if extra_info.medium %}
- <li>
- <span>{% trans "Technika" context "obrazu" %}:</span>
- <a>{{ extra_info.medium }}</a>
- </li>
- {% endif %}
-
- {% if extra_info.original_dimensions %}
- <li>
- <span>{% trans "Wymiary pracy" context "obrazu" %}:</span>
- <a>{{ extra_info.original_dimensions }}</a>
- </li>
- {% endif %}
-
- <li>
- <span>{% trans "Czas powstania" context "obrazu" %}:</span>
- <a>{{ extra_info.created_at }}</a>
- </li>
- {% endwith %}
-
- </ul>
- </aside>
- <div class="l-content">
- <header class="l-header">
- <div class="l-header__content">
- <p>{% for author in picture.authors %}<a href="{{ author.get_absolute_url }}">{{ author.name }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}
- </p>
- <h1><a href="{{ picture.get_absolute_url }}">{{ picture.title }}</a></h1>
- </div>
- </header>
- <article class="l-article">
- <div class="c-media">
- <div class="c-media__actions">
- <div class="c-media__btn">
- <a href="{{ picture.image_file.url }}" class="l-button l-button--media"><i class="icon icon-picture"></i> pobierz obraz</a>
- </div>
- <div class="c-media__btn" style="padding-right: 0">
- <a href="{% url 'picture_viewer' picture.slug %}" class="l-button l-button--media l-button--media--full"><i class="icon icon-eye"></i> obejrzyj online</a>
- </div>
- </div>
- </div>
-
- <div class="l-article__overlay" data-max-height="327" style="margin-top:30px;">
- {% thumbnail picture.image_file "850" upscale=0 as thumb %}
- <a href="{% url 'picture_viewer' picture.slug %}">
- <img class="l-art__preview" src="{{ thumb.url }}" />
- </a>
- {% endthumbnail %}
- </div>
- <button class="l-article__read-more" aria-label="Kliknij aby rozwinąć" data-label="Pokaż więcej" data-action="Pokaż mniej">Pokaż więcej</button>
- </article>
- </div>
- </section>
-
- {% for tag in picture.authors %}
- <section class="l-section">
- <div class="l-author">
- {% include 'catalogue/author_box.html' %}
- </div>
- </section>
- {% endfor %}
-
- <section class="l-section">
- <div class="l-themes__wrapper">
- {% if themes %}
- <h2>Motywy obecne na tym obrazie <a href="/katalog/motyw/"><span>Wszystkie motywy</span> <i class="icon icon-arrow-right"></i></a></h2>
- <div class="l-themes l-article__overlay" data-max-height="80">
- <ul>
- {% for item in themes %}
- <li><a href="{% url 'picture_viewer' picture.slug %}#theme-{{ item.slug }}">{{ item }} ({{ item.count}})</a></li>
- {% endfor %}
- </ul>
- </div>
- <button class="l-article__read-more" aria-label="Kliknij aby rozwinąć" data-label="Czytaj więcej" data-action="Zwiń tekst">Zobacz więcej</button>
-
- {% endif %}
- {% if things %}
- <h2>Obiekty na tym obrazie <a href="/katalog/motyw/"><span>Wszystkie obiekty</span> <i class="icon icon-arrow-right"></i></a></h2>
- <div class="l-themes l-article__overlay" data-max-height="80">
- <ul>
- {% for item in things %}
- <li><a href="{% url 'picture_viewer' picture.slug %}#object-{{ item.slug }}">{{ item }} ({{ item.count}})</a></li>
- {% endfor %}
- </ul>
- </div>
- <button class="l-article__read-more" aria-label="Kliknij aby rozwinąć" data-label="Czytaj więcej" data-action="Zwiń tekst">Zobacz więcej</button>
-
- {% endif %}
- <ul class="links">
- {% if picture.wiki_link %}
- <li><a href="{{ picture.wiki_link }}">strona obrazu w Wikipedii</a></li>
- {% endif %}
- <li>
- <a href="{{ picture.xml_url }}">źródłowy plik XML</a>
- </li>
- <li>
- <a target="_blank" href="{{ picture.get_extra_info_json.about }}">obraz na Platformie Redakcyjnej</a>
- </li>
- </ul>
- </div>
- </section>
- </main>
-
-
-
-
-
- <section class="l-section">
- <div class="l-books__wrapper">
- <div class="l-container">
- <h2>Czytaj także</h2>
- <dive class="l-books">
- {% related_pictures_2022 picture=picture as related_books %}
- {% for rel in related_books %}
- <article class="l-books__item">
- <figure class="l-books__item__img">
- <a href="{{ rel.get_absolute_url }}">
- <img src="{% if rel.cover_clean %}{{ rel.cover_clean.url }}{% endif %}" alt="{{ rel.pretty_title }}">
- </a>
- </figure>
- <h3>
- {% for author in rel.authors %}
- <a href="{{ author.get_absolute_url }}">{{ author|upper }}</a>
- {% endfor %}
- </h3>
- <h2><a href="{{ rel.get_absolute_url }}">{{ rel.title }}</a></h2>
- </article>
- {% endfor %}
-
- <article class="l-books__item l-books__item--link">
- <a href="/katalog/kolekcje/">i wiele innych książek, wierszy, obrazów, audiobooków…</a>
- <a href="/katalog/kolekcje/" class="icon-link"><i class="icon icon-all"></i></a>
- </article>
-
- </div>
- </div>
- </div>
- </section>
-
-
-{% endblock %}
+++ /dev/null
-<div id="picture-themes" class="dropdown-body">
- <ul>
- {% for slug, theme in themes.items %}
- <li><a href="#theme-{{slug}}" data-coords="{{theme.coords}}">{{theme.theme}}</a></li>
- {% endfor %}
- </ul>
-</div>
-
-<div id="picture-objects" class="dropdown-body">
- <ul>
- {% for slug, thing in things.items %}
- <li><a href="#object-{{slug}}" data-coords="{{thing.coords}}">{{thing.object}}</a></li>
- {% endfor %}
- </ul>
-</div>
+++ /dev/null
-{% spaceless %}
- {% load thumbnail %}
- {% with picture.author_unicode as author %}
- <div class="book-mini-box">
- <div class="book-mini-box-inner">
- <a href="{{ picture.get_absolute_url }}">
- {% 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 }} – {{ picture.title }}" class="cover" />
- {% endif %}
- <div class="desc">
- <span class="mono author">{{ author }}</span>
- <span class="title">{{ picture.title }}</span>
- </div>
- </a>
- </div>
- </div>
- {% endwith %}
-{% endspaceless %}
+++ /dev/null
-{% load i18n %}
-{% load thumbnail %}
-{% load catalogue_tags social_tags %}
-{% load picture_tags %}
-
-<div class="{% block box-class %}book-box{% endblock %} picture">
- <div class="book-box-inner">
- <div class="picture-left-column">
- <div class="book-box-body">
- {% with picture.get_absolute_url as main_link %}
- {% with picture.tags_by_category as tags %}
- <div class="book-box-head">
- <div class="author">
- {% for tag in tags.author %}
- <a href="{{ tag.get_absolute_gallery_url }}">{{ tag }}</a>{% if not forloop.last %},
- {% endif %}{% endfor %}
- </div>
- <div class="title">
- {% if main_link %}<a href="{{ main_link }}">{% endif %}
- {{ picture.title }}
- {% if main_link %}</a>{% endif %}
- </div>
- </div>
-
- <div class="cover-area">
- {% block picture-view %}
- {% if main_link %}<a href="{{ main_link }}">{% endif %}
- {% thumbnail picture.image_file "216x288" crop="center" as thumb %}
- <img class="cover" src="{{thumb.url}}"/>
- {% endthumbnail %}
- {% if main_link %}</a>{% endif %}
- {% endblock %}
- {# what about licensing icons here #}
- </div>
-
- <div class="tags">
- {% spaceless %}
- <span class="category">
- <span class="mono"> {% trans "Epoka" %}:</span> <span class="book-box-tag">
- {% for tag in tags.epoch %}
- <a href="{{ tag.get_absolute_gallery_url }}">{{ tag }}</a>
- {% if not forloop.last %}<span>, </span>{% endif %}
- {% endfor %}
- </span>
- </span>
-
- <span class="category">
- <span class="mono"> {% trans "Rodzaj" %}:</span> <span class="book-box-tag">
- {% for tag in tags.kind %}
- <a href="{{ tag.get_absolute_gallery_url }}">{{ tag }}</a>
- {% if not forloop.last %}<span>, </span>{% endif %}
- {% endfor %}
- </span>
- </span>
-
- <span class="category">
- <span class="mono"> {% trans "Gatunek" %}:</span> <span class="book-box-tag">
- {% for tag in tags.genre %}
- <a href="{{ tag.get_absolute_gallery_url }}">{{ tag }}</a>
- {% if not forloop.last %}<span>, </span>{% endif %}
- {% endfor %}
- </span>
- </span>
-
- {% block extra_categories %}
- {% endblock %}
- {% endspaceless %}
- </div>
- {% endwith %}
- {% endwith %}
- </div>
- <ul class="book-box-tools">
- <li class="book-box-read">
- <a href="{% url 'picture_viewer' picture.slug %}" class="downarrow">{% trans "Zobacz online" %}</a>
- </li>
- <li class="book-box-download">
- <a href="{{picture.image_file.url}}" class="downarrow">{% trans "pobierz oryginał" %}</a>
- </li>
- </ul>
- </div>
- {% block book-box-extra-info %}{% endblock %}
- {% block box-append %}{% endblock %}
- {% block right-column %}{% endblock %}
- <div class="clearboth"></div>
- </div>
-</div>
+++ /dev/null
-{% extends "catalogue/viewer_base.html" %}
-{% load i18n %}
-{% load static from static %}
-{% load catalogue_tags %}
-{% load thumbnail %}
-
-
-{% block title %}{{ picture.pretty_title }}{% endblock %}
-
-
-{% block body-id %}picture-viewer{% endblock %}
-
-
-{% block js-dependencies %}
- <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
-{% endblock %}
-
-
-{% block no-menu-extra %}
- <li><a class="square button plus inactive" href="#">+<!--➕--><!-- heavy plus sign --></a></li>
- <li><a class="square button minus inactive" href="#">-<!-- ➖--><!-- heavy minus sign --></a></li>
-{% endblock %}
-
-
-{% block menu %}
- <li>
- <a style="width: 50%;display: inline-block;" class="square button plus inactive" href="#">+<!--➕--><!-- heavy plus sign --></a>
- <a style="width: 50%;display: inline-block;" class="square button minus inactive" href="#">-<!-- ➖--><!-- heavy minus sign --></a>
- </li>
-
- {% spaceless %}
- <li>
- {% with picture.get_previous as prev %}
- <a style="width: 50%;display: inline-block;" {% if prev %}href="{% url 'picture_viewer' prev.slug %}"{% endif %}>{% if prev %}<{%endif %}</a>
- {% endwith %}
- {% with picture.get_next as next %}
- <a style="width: 50%;display: inline-block;" {% if next %}href="{% url 'picture_viewer' next.slug %}"{% endif %}>{% if next %}>{% endif %}</a>
- {% endwith %}
- </li>
- {% endspaceless %}
-
- <li>
- <a href="{{ picture.get_absolute_url }}" id="menu-book" data-box="book-short">
- <img src="{% thumbnail picture.image_file '120x300' as thumb %}{{ thumb.url }}{% empty %}{{ picture.image_file.url }}{% endthumbnail %}"
- width="120"
- alt="{{ picture.pretty_title }}"
- title="{{ picture.pretty_title }}">
- </a>
- </li>
-
- <li><a href="#picture-objects" class="dropdown"><span class="label">{% trans "Obiekty" context "na obrazie" %}</span></a></li>
- <li><a href="#picture-themes" class="dropdown"><span class="label">{% trans "Motywy" %}</span></a></li>
-
- <li id="menu-info">
- <a href="#info" data-box="info">
- <span class="label">{% trans "Informacja" %}</span>
- </a>
- </li>
-
- <li id="sponsors">
- {% for sponsor in sponsors %}
- {% thumbnail sponsor.logo "120x300" as logo %}
- <a href="{{ sponsor.url }}" target="_blank"><img src="{{ logo.url }}" alt="{{ sponsor.name }}" /></a>
- {% endthumbnail %}
- {% endfor %}
- </li>
-{% endblock %}
-
-{% block main %}
- <div id="picture-view">
- {% thumbnail picture.image_file "700x500" as pic %}
- <div class="picture-wrap {% if picture.image_file|is_portrait %}portrait{% endif %}"
- data-original-width="{{picture.width}}" data-original-height="{{picture.height}}"
- data-original-url="{{ picture.image_file.url }}"
- data-width="{{pic.width}}" data-height="{{pic.height}}" style="background-image: url('{{pic.url}}'); width: {{pic.width}}px; height: {{pic.height}}px;">
- </div>
- {% endthumbnail %}
- </div>
-{% endblock %}
-
-
-{% block footer %}
- {{ picture.html_file.read.decode|safe }}
-
- <div id="info" class="box">
- <div class="sponsors">
- <a href="/">
- <img src="{% static "img/logo-220.png" %}" alt="Wolne Lektury"/>
- </a>
- {% for sponsor in sponsors %}
- {% thumbnail sponsor.logo "220x220" as logo %}
- <a href="{{ sponsor.url }}" target="_blank"><img src="{{ logo.url }}" alt="{{ sponsor.name }}"/></a>
- {% endthumbnail %}
- {% endfor %}
- </div>
-
- {% book_info picture %}
- </div>
-
- <div class="box Picture-item" id="book-short">
- {% include 'picture/picture_short.html' %}
- </div>
-{% endblock %}
+++ /dev/null
-# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
-#
-from collections import Counter
-from django.conf import settings
-from django.contrib.auth.decorators import permission_required
-from django.shortcuts import render, get_object_or_404, render
-from picture.models import Picture
-from catalogue.models import Tag
-from catalogue.utils import split_tags
-from sponsors.models import Sponsor
-from wolnelektury.utils import ajax
-from catalogue.helpers import get_top_level_related_tags
-
-
-def picture_list_thumb(request):
- pictures = Picture.objects.all()
-
- related_tags = Tag.objects.usage_for_model(Picture, counts=True)
- related_tags = sorted(related_tags, key=lambda t: -t.count)
- suggestion_categories = Counter()
- suggestions = []
- for t in related_tags:
- if suggestion_categories[t.category] < 3:
- suggestion_categories[t.category] += 1
- suggestions.append(t)
- if sum(suggestion_categories.values()) == 10:
- break
- template_name = 'catalogue/author_detail.html'
- return render(request, template_name, {
- 'object_list': pictures,
- 'title': 'Galeria',
- 'tags': [],
- 'suggest': suggestions,
- 'list_type': 'gallery',
- })
-
-
-def picture_detail(request, slug):
- picture = get_object_or_404(Picture, slug=slug)
-
- theme_things = split_tags(picture.related_themes())
-
- template_name = 'picture/picture_detail.html'
-
- return render(request, template_name, {
- 'picture': picture,
- 'themes': theme_things.get('theme', []),
- 'things': theme_things.get('thing', []),
- 'active_menu_item': 'gallery',
- })
-
-
-def picture_viewer(request, slug):
- picture = get_object_or_404(Picture, slug=slug)
- sponsors = []
- for sponsor in picture.get_extra_info_json().get('sponsors', []):
- have_sponsors = Sponsor.objects.filter(name=sponsor)
- if have_sponsors.exists():
- sponsors.append(have_sponsors[0])
- return render(request, "picture/picture_viewer.html", {
- 'picture': picture,
- 'sponsors': sponsors,
- })
-
-
-@ajax(method='get')
-def picture_page(request, key=None):
- pictures = Picture.objects.order_by('-id')
- if key is not None:
- pictures = pictures.filter(id__lt=key)
- pictures = pictures[:settings.PICTURE_PAGE_SIZE]
- picture_data = [
- {
- 'id': picture.id,
- 'title': picture.title,
- 'author': picture.author_unicode(),
- 'epoch': picture.tag_unicode('epoch'),
- 'kind': picture.tag_unicode('kind'),
- 'genre': picture.tag_unicode('genre'),
- 'style': picture.get_extra_info_json()['style'],
- 'image_url': picture.image_file.url,
- 'width': picture.width,
- 'height': picture.height,
- }
- for picture in pictures
- ]
- return {
- 'pictures': picture_data,
- 'count': Picture.objects.count(),
- }
-
-
-# =========
-# = Admin =
-# =========
-@permission_required('picture.add_picture')
-def import_picture(request):
- """docstring for import_book"""
- from django.http import HttpResponse
- from picture.forms import PictureImportForm
-
- import_form = PictureImportForm(request.POST, request.FILES)
- if import_form.is_valid():
- try:
- import_form.save()
- except:
- import sys
- import pprint
- import traceback
- info = sys.exc_info()
- exception = pprint.pformat(info[1])
- tb = '\n'.join(traceback.format_tb(info[2]))
- return HttpResponse("Wystąpił błąd: %(exception)s\n\n%(tb)s" %
- {'exception': exception, 'tb': tb}, content_type='text/plain')
- return HttpResponse('Obraz został zimportowany')
- else:
- return HttpResponse('Błąd importu pliku: %r' % import_form.errors)