1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from django.db import models, transaction
5 import catalogue.models
6 from sorl.thumbnail import ImageField
7 from django.conf import settings
8 from django.contrib.contenttypes.fields import GenericRelation
9 from django.core.files.storage import FileSystemStorage
10 from django.urls import reverse
11 from slugify import slugify
13 from catalogue.models.tag import prefetched_relations
14 from catalogue.utils import split_tags
15 from wolnelektury.utils import cached_render, clear_cached_renders
16 from io import BytesIO
24 from newtagging import managers
28 picture_storage = FileSystemStorage(location=path.join(
29 settings.MEDIA_ROOT, 'pictures'),
30 base_url=settings.MEDIA_URL + "pictures/")
33 class PictureArea(models.Model):
34 picture = models.ForeignKey('picture.Picture', models.CASCADE, related_name='areas')
35 area = models.TextField('obszar', default='{}', editable=False)
36 kind = models.CharField(
37 'typ', max_length=10, blank=False, null=False, db_index=True,
38 choices=(('thing', 'przedmiot'), ('theme', 'motyw'))
41 objects = models.Manager()
42 tagged = managers.ModelTaggedItemManager(catalogue.models.Tag)
43 tags = managers.TagDescriptor(catalogue.models.Tag)
44 tag_relations = GenericRelation(catalogue.models.Tag.intermediary_table_model)
47 class Picture(models.Model):
52 title = models.CharField('tytuł', max_length=32767)
53 slug = models.SlugField('slug', max_length=120, db_index=True, unique=True)
54 sort_key = models.CharField('klucz sortowania', max_length=120, db_index=True, editable=False)
55 sort_key_author = models.CharField(
56 'klucz sortowania wg autora', max_length=120, db_index=True, editable=False, default='')
57 created_at = models.DateTimeField('data utworzenia', auto_now_add=True, db_index=True)
58 changed_at = models.DateTimeField('data zmiany', auto_now=True, db_index=True)
59 xml_file = models.FileField('plik xml', upload_to="xml", storage=picture_storage)
60 image_file = ImageField('plik obrazu', upload_to="images", storage=picture_storage)
61 html_file = models.FileField('plik html', upload_to="html", storage=picture_storage)
62 areas_json = models.TextField('obszary w JSON', default='{}', editable=False)
63 extra_info = models.TextField('dodatkowa informacja', default='{}')
64 culturepl_link = models.CharField(blank=True, max_length=240)
65 wiki_link = models.CharField(blank=True, max_length=240)
67 width = models.IntegerField(null=True)
68 height = models.IntegerField(null=True)
70 objects = models.Manager()
71 tagged = managers.ModelTaggedItemManager(catalogue.models.Tag)
72 tags = managers.TagDescriptor(catalogue.models.Tag)
73 tag_relations = GenericRelation(catalogue.models.Tag.intermediary_table_model)
76 ordering = ('sort_key_author', 'sort_key')
78 verbose_name = 'obraz'
79 verbose_name_plural = 'obrazy'