+ picture.extra_info = picture_xml.picture_info.to_dict()
+
+ motif_tags = set()
+ thing_tags = set()
+ area_data = {'themes':{}, 'things':{}}
+
+ for part in picture_xml.partiter():
+ if picture_xml.frame:
+ 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'],
+ }
+ else:
+ for motif in part['themes']:
+ 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)
+ area_data['themes'][tag.slug] = {
+ 'theme': motif,
+ 'coords': part['coords']
+ }
+
+ picture.tags = catalogue.models.Tag.tags_from_info(picture_xml.picture_info) + \
+ list(motif_tags) + list(thing_tags)
+ picture.areas = area_data