Fix Picture import: split theme names, more space for titles.
authorRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Wed, 24 Sep 2014 14:06:02 +0000 (16:06 +0200)
committerRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Wed, 24 Sep 2014 14:06:02 +0000 (16:06 +0200)
apps/picture/migrations/0003_auto_20140924_1559.py [new file with mode: 0644]
apps/picture/models.py

diff --git a/apps/picture/migrations/0003_auto_20140924_1559.py b/apps/picture/migrations/0003_auto_20140924_1559.py
new file mode 100644 (file)
index 0000000..4e257d8
--- /dev/null
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('picture', '0002_remove_picture__related_info'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='picture',
+            name='title',
+            field=models.CharField(max_length=255, verbose_name='Title'),
+        ),
+    ]
index 42a26c3..cc29f85 100644 (file)
@@ -72,7 +72,7 @@ class Picture(models.Model):
     Picture resource.
 
     """
-    title       = models.CharField(_('title'), max_length=120)
+    title       = models.CharField(_('title'), max_length=255)
     slug        = models.SlugField(_('slug'), max_length=120, db_index=True, unique=True)
     sort_key    = models.CharField(_('sort key'), max_length=120, db_index=True, editable=False)
     sort_key_author = models.CharField(_('sort key by author'), max_length=120, db_index=True, editable=False, default=u'')
@@ -175,37 +175,40 @@ class Picture(models.Model):
                     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:
-                    objname = part['object']
-                    tag, created = catalogue.models.Tag.objects.get_or_create(slug=slughifi(objname), category='thing')
-                    if created:
-                        tag.name = objname
-                        tag.sort_key = sortify(tag.name)
-                        tag.save()
-                    #thing_tags.add(tag)
-                    area_data['things'][tag.slug] = {
-                        'object': part['object'],
-                        'coords': part['coords'],
-                        }
-                    area = PictureArea.rectangle(picture, 'thing', part['coords'])
-                    area.save()
                     _tags = set()
-                    _tags.add(tag)
-                    area.tags = _tags
-                else:
-                    _tags = set()
-                    for motif in part['themes']:
-                        tag, created = catalogue.models.Tag.objects.get_or_create(slug=slughifi(motif), category='theme')
+                    for objname in part['object'].split(','):
+                        objname = objname.strip()
+                        tag, created = catalogue.models.Tag.objects.get_or_create(slug=slughifi(objname), category='thing')
                         if created:
-                            tag.name = motif
+                            tag.name = objname
                             tag.sort_key = sortify(tag.name)
                             tag.save()
-                        #motif_tags.add(tag)
-                        _tags.add(tag)
-                        area_data['themes'][tag.slug] = {
-                            'theme': motif,
-                            'coords': part['coords']
+                        #thing_tags.add(tag)
+                        area_data['things'][tag.slug] = {
+                            'object': part['object'],
+                            'coords': part['coords'],
                             }
 
+                        _tags.add(tag)
+                    area = PictureArea.rectangle(picture, 'thing', part['coords'])
+                    area.save()
+                    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=slughifi(motif), category='theme')
+                            if created:
+                                tag.name = motif
+                                tag.sort_key = sortify(tag.name)
+                                tag.save()
+                            #motif_tags.add(tag)
+                            _tags.add(tag)
+                            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()