Fixes #3511: capitalize objects.
authorRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Wed, 22 Oct 2014 09:26:39 +0000 (11:26 +0200)
committerRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Wed, 22 Oct 2014 09:26:39 +0000 (11:26 +0200)
apps/catalogue/migrations/0006_auto_20141022_1059.py [new file with mode: 0644]
apps/picture/migrations/0005_auto_20141022_1001.py
apps/picture/models.py

diff --git a/apps/catalogue/migrations/0006_auto_20141022_1059.py b/apps/catalogue/migrations/0006_auto_20141022_1059.py
new file mode 100644 (file)
index 0000000..f36eb07
--- /dev/null
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+def capitalize_objects(apps, schema_editor):
+    """Capitalize Polish names of things."""
+    Tag = apps.get_model('catalogue', 'Tag')
+    for tag in Tag.objects.filter(category='thing'):
+        tag.name = tag.name_pl = tag.name.capitalize()
+        tag.save()
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('catalogue', '0005_auto_20141016_1337'),
+    ]
+
+    operations = [
+        migrations.RunPython(capitalize_objects),
+    ]
index e5e8738..677877e 100644 (file)
@@ -1,7 +1,10 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
+from django.core.files.base import ContentFile
 from django.db import models, migrations
 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")
 
 def rebuild_extra_info(apps, schema_editor):
     Picture = apps.get_model("picture", "Picture")
@@ -10,6 +13,15 @@ def rebuild_extra_info(apps, schema_editor):
     for pic in Picture.objects.all():
         info = dcparser.parse(pic.xml_file.path, PictureInfo)
         pic.extra_info = info.to_dict()
     for pic in Picture.objects.all():
         info = dcparser.parse(pic.xml_file.path, PictureInfo)
         pic.extra_info = info.to_dict()
+        areas_json = pic.areas_json
+        for field in areas_json[u'things'].values():
+            field[u'object'] = field[u'object'].capitalize()
+        pic.areas_json = areas_json
+        html_text = unicode(render_to_string('picture/picture_info.html', {
+                    'things': pic.areas_json['things'],
+                    'themes': pic.areas_json['themes'],
+                    }))
+        pic.html_file.save("%s.html" % pic.slug, ContentFile(html_text))
         pic.save()
 
 
         pic.save()
 
 
index 97dbd0e..7ef6ca7 100644 (file)
@@ -170,6 +170,9 @@ class Picture(models.Model):
 
             area_data = {'themes':{}, 'things':{}}
 
 
             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]
             for part in picture_xml.partiter():
                 if picture_xml.frame:
                     c = picture_xml.frame[0]
@@ -180,7 +183,8 @@ class Picture(models.Model):
                         objname = objname.strip()
                         tag, created = catalogue.models.Tag.objects.get_or_create(slug=slughifi(objname), category='thing')
                         if created:
                         objname = objname.strip()
                         tag, created = catalogue.models.Tag.objects.get_or_create(slug=slughifi(objname), category='thing')
                         if created:
-                            tag.name = objname
+                            tag.name = objname.capitalize()
+                            setattr(tag, 'name_%s' % lang, tag.name)
                             tag.sort_key = sortify(tag.name)
                             tag.save()
                         #thing_tags.add(tag)
                             tag.sort_key = sortify(tag.name)
                             tag.save()
                         #thing_tags.add(tag)