Fixes #3393: sponsor logo on picture viewer page.
[wolnelektury.git] / apps / picture / models.py
index cc29f85..7ef6ca7 100644 (file)
@@ -72,7 +72,7 @@ class Picture(models.Model):
     Picture resource.
 
     """
     Picture resource.
 
     """
-    title       = models.CharField(_('title'), max_length=255)
+    title       = models.CharField(_('title'), max_length=32767)
     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'')
     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
 
     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
 
         try:
             author = self.tags.filter(category='author')[0].sort_key
@@ -156,7 +156,7 @@ class Picture(models.Model):
                 image_store = ImageStore(picture_storage.path('images'))
             picture_xml = WLPicture.from_file(xml_file, image_store=image_store)
 
                 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)
 
             if not created and not overwrite:
                 raise Picture.AlreadyExists('Picture %s already exists' % picture_xml.slug)
 
@@ -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)
@@ -340,6 +344,7 @@ class Picture(models.Model):
             template % (self.pk, lang)
             for template in [
                 '/katalog/p/%d/short.%s.html',
             template % (self.pk, lang)
             for template in [
                 '/katalog/p/%d/short.%s.html',
+                '/katalog/p/%d/mini.%s.html',
                 ]
             for lang in languages
             ])
                 ]
             for lang in languages
             ])