1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
4 from django.core.files.base import ContentFile
5 from django.db import models, migrations
6 from django.template.loader import render_to_string
9 def rebuild_extra_info(apps, schema_editor):
10 Picture = apps.get_model("picture", "Picture")
11 from librarian.picture import PictureInfo
12 from librarian import dcparser
13 for pic in Picture.objects.all():
14 info = dcparser.parse(pic.xml_file.path, PictureInfo)
15 pic.extra_info = info.to_dict()
16 areas_json = pic.areas_json
17 for field in areas_json[u'things'].values():
18 field[u'object'] = field[u'object'].capitalize()
19 pic.areas_json = areas_json
20 html_text = render_to_string('picture/picture_info.html', {
21 'things': pic.areas_json['things'],
22 'themes': pic.areas_json['themes'],
24 pic.html_file.save("%s.html" % pic.slug, ContentFile(html_text))
28 class Migration(migrations.Migration):
31 ('picture', '0004_auto_20141016_1337'),
35 migrations.RunPython(rebuild_extra_info),