From ea710efc8f7d2a23c42e179ab01d73d78db32931 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 28 Aug 2024 11:37:52 +0200 Subject: [PATCH] Remove picture models. --- .../0016_alter_mediainsertset_file_format.py | 18 ++++ src/catalogue/constants.py | 2 - src/catalogue/fields.py | 5 -- ...tion_kind_remove_tag_for_books_and_more.py | 35 ++++++++ src/catalogue/models/book.py | 5 -- src/catalogue/models/tag.py | 7 -- ...urearea_picture_delete_picture_and_more.py | 23 ++++++ src/picture/models.py | 82 ------------------- 8 files changed, 76 insertions(+), 101 deletions(-) create mode 100644 src/annoy/migrations/0016_alter_mediainsertset_file_format.py create mode 100644 src/catalogue/migrations/0048_remove_collection_kind_remove_tag_for_books_and_more.py create mode 100644 src/picture/migrations/0010_remove_picturearea_picture_delete_picture_and_more.py delete mode 100644 src/picture/models.py diff --git a/src/annoy/migrations/0016_alter_mediainsertset_file_format.py b/src/annoy/migrations/0016_alter_mediainsertset_file_format.py new file mode 100644 index 000000000..4698bb60d --- /dev/null +++ b/src/annoy/migrations/0016_alter_mediainsertset_file_format.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.8 on 2024-08-28 08:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('annoy', '0015_alter_banner_options_alter_dynamictextinsert_options_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='mediainsertset', + name='file_format', + field=models.CharField(choices=[('epub', 'epub'), ('mobi', 'mobi'), ('pdf', 'pdf')], max_length=8), + ), + ] diff --git a/src/catalogue/constants.py b/src/catalogue/constants.py index 9d21d4e88..f02bdd3b0 100644 --- a/src/catalogue/constants.py +++ b/src/catalogue/constants.py @@ -67,7 +67,6 @@ CATEGORIES_NAME_PLURAL = { 'genre': _('gatunki'), 'theme': _('motywy'), 'set': _('półki'), - 'thing': _('obiekty'), } WHOLE_CATEGORY = { @@ -77,5 +76,4 @@ WHOLE_CATEGORY = { 'genre': _('Wszystkie gatunki'), 'theme': _('Wszystkie motywy'), 'set': _('Wszystkie półki'), - 'thing': _('Wszystkie obiekty'), } diff --git a/src/catalogue/fields.py b/src/catalogue/fields.py index c4dec7e3f..9c5696fa6 100644 --- a/src/catalogue/fields.py +++ b/src/catalogue/fields.py @@ -350,7 +350,6 @@ class HtmlField(EbookField): tag.name = theme_name setattr(tag, "name_%s" % lang, theme_name) tag.sort_key = sortify(theme_name.lower()) - tag.for_books = True tag.save() themes.append(tag) elif lang is not None: @@ -380,10 +379,6 @@ class HtmlField(EbookField): new_fragment.save() new_fragment.tags = set(meta_tags + themes) - for theme in themes: - if not theme.for_books: - theme.for_books = True - theme.save() book.html_built.send(sender=type(self), instance=book) return True return False diff --git a/src/catalogue/migrations/0048_remove_collection_kind_remove_tag_for_books_and_more.py b/src/catalogue/migrations/0048_remove_collection_kind_remove_tag_for_books_and_more.py new file mode 100644 index 000000000..a4f3455ac --- /dev/null +++ b/src/catalogue/migrations/0048_remove_collection_kind_remove_tag_for_books_and_more.py @@ -0,0 +1,35 @@ +# Generated by Django 4.0.8 on 2024-08-28 08:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0047_book_translators'), + ] + + operations = [ + migrations.RemoveField( + model_name='collection', + name='kind', + ), + migrations.RemoveField( + model_name='tag', + name='for_books', + ), + migrations.RemoveField( + model_name='tag', + name='for_pictures', + ), + migrations.AlterField( + model_name='book', + name='translators', + field=models.ManyToManyField(blank=True, to='catalogue.tag'), + ), + migrations.AlterField( + model_name='tag', + name='category', + field=models.CharField(choices=[('author', 'autor'), ('epoch', 'epoka'), ('kind', 'rodzaj'), ('genre', 'gatunek'), ('theme', 'motyw'), ('set', 'półka')], db_index=True, max_length=50, verbose_name='kategoria'), + ), + ] diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index ac8c02b9e..29e375464 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -653,11 +653,6 @@ class Book(models.Model): meta_tags = Tag.tags_from_info(book_info) - for tag, relationship in meta_tags: - if not tag.for_books: - tag.for_books = True - tag.save() - just_tags = [t for (t, rel) in meta_tags if not rel] book.tags = set(just_tags + book_shelves) book.save() # update sort_key_author diff --git a/src/catalogue/models/tag.py b/src/catalogue/models/tag.py index af1d67fdb..13d8a6403 100644 --- a/src/catalogue/models/tag.py +++ b/src/catalogue/models/tag.py @@ -23,7 +23,6 @@ TAG_CATEGORIES = ( ('genre', _('gatunek')), ('theme', _('motyw')), ('set', _('półka')), - ('thing', _('obiekt')), # things shown on pictures ) @@ -58,9 +57,6 @@ class Tag(models.Model): 'kategoria', max_length=50, blank=False, null=False, db_index=True, choices=TAG_CATEGORIES) description = models.TextField('opis', blank=True) - for_books = models.BooleanField(default=False) - for_pictures = models.BooleanField(default=False) - user = models.ForeignKey(User, models.CASCADE, blank=True, null=True) gazeta_link = models.CharField(blank=True, max_length=240) culturepl_link = models.CharField(blank=True, max_length=240) @@ -113,7 +109,6 @@ class Tag(models.Model): 'gatunek': 'genre', 'motyw': 'theme', 'polka': 'set', - 'obiekt': 'thing', } categories_dict = dict((item[::-1] for item in categories_rev.items())) @@ -156,8 +151,6 @@ class Tag(models.Model): # TODO: remove magic. if self.category == 'set': return reverse('social_my_shelf') - elif self.category == 'thing': - return '' else: return reverse(f'{self.category}_catalogue') diff --git a/src/picture/migrations/0010_remove_picturearea_picture_delete_picture_and_more.py b/src/picture/migrations/0010_remove_picturearea_picture_delete_picture_and_more.py new file mode 100644 index 000000000..32fa4112f --- /dev/null +++ b/src/picture/migrations/0010_remove_picturearea_picture_delete_picture_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.0.8 on 2024-08-28 08:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('picture', '0009_alter_picture_options_alter_picture_areas_json_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='picturearea', + name='picture', + ), + migrations.DeleteModel( + name='Picture', + ), + migrations.DeleteModel( + name='PictureArea', + ), + ] diff --git a/src/picture/models.py b/src/picture/models.py deleted file mode 100644 index ae3d66a79..000000000 --- a/src/picture/models.py +++ /dev/null @@ -1,82 +0,0 @@ -# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. -# -from django.db import models, transaction -import catalogue.models -from sorl.thumbnail import ImageField -from django.conf import settings -from django.contrib.contenttypes.fields import GenericRelation -from django.core.files.storage import FileSystemStorage -from django.urls import reverse -from slugify import slugify - -from catalogue.models.tag import prefetched_relations -from catalogue.utils import split_tags -from wolnelektury.utils import cached_render, clear_cached_renders -from io import BytesIO -import itertools -import json -import logging -import re - -from PIL import Image - -from newtagging import managers -from os import path - - -picture_storage = FileSystemStorage(location=path.join( - settings.MEDIA_ROOT, 'pictures'), - base_url=settings.MEDIA_URL + "pictures/") - - -class PictureArea(models.Model): - picture = models.ForeignKey('picture.Picture', models.CASCADE, related_name='areas') - area = models.TextField('obszar', default='{}', editable=False) - kind = models.CharField( - 'typ', max_length=10, blank=False, null=False, db_index=True, - choices=(('thing', 'przedmiot'), ('theme', 'motyw')) - ) - - objects = models.Manager() - tagged = managers.ModelTaggedItemManager(catalogue.models.Tag) - tags = managers.TagDescriptor(catalogue.models.Tag) - tag_relations = GenericRelation(catalogue.models.Tag.intermediary_table_model) - - -class Picture(models.Model): - """ - Picture resource. - - """ - title = models.CharField('tytuł', max_length=32767) - slug = models.SlugField('slug', max_length=120, db_index=True, unique=True) - sort_key = models.CharField('klucz sortowania', max_length=120, db_index=True, editable=False) - sort_key_author = models.CharField( - 'klucz sortowania wg autora', max_length=120, db_index=True, editable=False, default='') - created_at = models.DateTimeField('data utworzenia', auto_now_add=True, db_index=True) - changed_at = models.DateTimeField('data zmiany', auto_now=True, db_index=True) - xml_file = models.FileField('plik xml', upload_to="xml", storage=picture_storage) - image_file = ImageField('plik obrazu', upload_to="images", storage=picture_storage) - html_file = models.FileField('plik html', upload_to="html", storage=picture_storage) - areas_json = models.TextField('obszary w JSON', default='{}', editable=False) - extra_info = models.TextField('dodatkowa informacja', default='{}') - culturepl_link = models.CharField(blank=True, max_length=240) - wiki_link = models.CharField(blank=True, max_length=240) - - width = models.IntegerField(null=True) - height = models.IntegerField(null=True) - - objects = models.Manager() - tagged = managers.ModelTaggedItemManager(catalogue.models.Tag) - tags = managers.TagDescriptor(catalogue.models.Tag) - tag_relations = GenericRelation(catalogue.models.Tag.intermediary_table_model) - - class Meta: - ordering = ('sort_key_author', 'sort_key') - - verbose_name = 'obraz' - verbose_name_plural = 'obrazy' - - def __str__(self): - return self.title -- 2.20.1