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:
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
--- /dev/null
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+def init_tag_for_books_pictures(apps, schema_editor):
+ Tag = apps.get_model('catalogue', 'Tag')
+ db_alias = schema_editor.connection.alias
+ tag_objects = Tag.objects.using(db_alias).exclude(category='set')
+ tags_for_books = tag_objects.filter(items__content_type__model__in=('book', 'fragment')).distinct()
+ tags_for_books.update(for_books=True)
+ tags_for_pictures = tag_objects.filter(items__content_type__model__in=('picture', 'picturearea')).distinct()
+ tags_for_pictures.update(for_pictures=True)
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('catalogue', '0018_auto_20171221_1106'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='tag',
+ name='for_books',
+ field=models.BooleanField(default=False),
+ ),
+ migrations.AddField(
+ model_name='tag',
+ name='for_pictures',
+ field=models.BooleanField(default=False),
+ ),
+ migrations.RunPython(init_tag_for_books_pictures, migrations.RunPython.noop)
+ ]
meta_tags = Tag.tags_from_info(book_info)
+ for tag in meta_tags:
+ if not tag.for_books:
+ tag.for_books = True
+ tag.save()
+
book.tags = set(meta_tags + book_shelves)
cover_changed = old_cover != book.cover_info()
_('category'), max_length=50, blank=False, null=False, db_index=True, choices=TAG_CATEGORIES)
description = models.TextField(_('description'), blank=True)
+ for_books = models.BooleanField(default=False)
+ for_pictures = models.BooleanField(default=False)
+
user = models.ForeignKey(User, blank=True, null=True)
gazeta_link = models.CharField(blank=True, max_length=240)
culturepl_link = models.CharField(blank=True, max_length=240)
picture.extra_info = picture_xml.picture_info.to_dict()
picture_tags = set(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': {}}
tag.name = objname
setattr(tag, 'name_%s' % lang, tag.name)
tag.sort_key = sortify(tag.name)
+ tag.for_pictures = True
tag.save()
- # thing_tags.add(tag)
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()
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']