Commits

dobrych  committed 9fa2b29

Few fixes for thumbnail filter, comments, little tune up of admin/models.

  • Participants
  • Parent commits d0eacce

Comments (0)

Files changed (3)

     list_filter = ('default', 'mime')
 
 class ItemAdmin(admin.ModelAdmin):
+    exclude = ['user']
     list_display = ('__unicode__', 'mime', 'upload_date')
     prepopulated_fields = {"slug": ("name",)}
     date_hierarchy = 'upload_date'
     #radio_fields = {'category': admin.VERTICAL}
     list_filter = ('upload_date', 'mime')
     search_fields = ['name']
+    
+    def save_model(self, request, obj, form, change):
+        obj.user = request.user
+        obj.save()
 
 admin.site.register(Item, ItemAdmin)
 admin.site.register(Meta, MetaAdmin)

File filters/thumbnail.py

     """
     if objekt.mime.name != 'image/jpeg':
         return
+    # size of long side
     size = (params.get('max_size'), params.get('max_size'))
+    # variant name generator
+    name="thumb_%spx" % (params.get('max_size'))
+    # cleaning exiting variant with same name
+    objekt.variant_set.filter(name=name).delete()
+    # generating tmp thumbnail
     tmpfile = StringIO()
     im = Image.open(objekt.file.path)
     im.thumbnail(size, Image.ANTIALIAS)
     im.save(tmpfile, im.format)
+    # creating and saving variant
     variant = objekt.variant_set.model()
     variant.parent = objekt
-    variant.name="thumb_%spx" % (params.get('max_size'))
+    variant.name = name
     variant.default = params.get('default')
     variant.file.save("variants/%s_%s.jpg" % (objekt.slug, variant.name), ContentFile(tmpfile.getvalue()))
-    variant.save()
     filtered = models.ForeignKey(Filter, blank=True, null=True)
     default = models.BooleanField(default=False)
 
+    class Meta:
+        unique_together = (("name", "parent"),)
+
     def __unicode__(self):
         return "%s for %s" % (self.name, self.parent)