X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d69fc5f16ed739c02685e7d695abf6de59c2bf5e..4c0b1c26b2e4789b194f34c907c822c55f04af3c:/apps/picture/models.py diff --git a/apps/picture/models.py b/apps/picture/models.py index 42a26c3c5..70efd781b 100644 --- a/apps/picture/models.py +++ b/apps/picture/models.py @@ -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'') @@ -108,7 +108,7 @@ class Picture(models.Model): def save(self, force_insert=False, force_update=False, **kwargs): from sortify import sortify - self.sort_key = sortify(self.title) + self.sort_key = sortify(self.title)[:120] try: author = self.tags.filter(category='author')[0].sort_key @@ -156,12 +156,12 @@ class Picture(models.Model): image_store = ImageStore(picture_storage.path('images')) picture_xml = WLPicture.from_file(xml_file, image_store=image_store) - picture, created = Picture.objects.get_or_create(slug=picture_xml.slug) + picture, created = Picture.objects.get_or_create(slug=picture_xml.slug[:120]) if not created and not overwrite: raise Picture.AlreadyExists('Picture %s already exists' % picture_xml.slug) picture.areas.all().delete() - picture.title = unicode(picture_xml.picture_info.title) + picture.title = unicode(picture_xml.picture_info.title)[:255] picture.extra_info = picture_xml.picture_info.to_dict() picture_tags = set(catalogue.models.Tag.tags_from_info(picture_xml.picture_info)) @@ -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()