+ 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:
+ _tags = set()
+ 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 = objname
+ tag.sort_key = sortify(tag.name)
+ tag.save()
+ #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()
+ area.tags = _tags.union(picture_tags)
+
+ picture.tags = picture_tags.union(motif_tags).union(thing_tags)
+ picture.areas_json = area_data