← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~franku/widelands-website/admin_action_correct_image_path into lp:widelands-website

 

kaputtnik has proposed merging lp:~franku/widelands-website/admin_action_correct_image_path into lp:widelands-website.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~franku/widelands-website/admin_action_correct_image_path/+merge/254993

This branch add an "admin action" to the site https://wl.widelands.org/admin/wlimages/image/

The "action" changes the path form the "image"value from an absolute path to a relative path in a convenient way. See https://code.launchpad.net/~franku/widelands-website/handle_big_images/+merge/247235/comments/628869 for a reason why this is needed.

See also:
1. https://code.launchpad.net/~franku/widelands-website/correct_image_paths/+merge/254990
2. https://code.launchpad.net/~franku/widelands-website/handle_great_images/+merge/254988
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~franku/widelands-website/admin_action_correct_image_path into lp:widelands-website.
=== modified file 'wlimages/admin.py'
--- wlimages/admin.py	2015-03-15 18:01:51 +0000
+++ wlimages/admin.py	2015-04-01 20:51:58 +0000
@@ -13,6 +13,17 @@
 from django.utils.translation import ugettext_lazy as _
 from models import Image
 
+# A function to correct the image paths to a relative path
+# This function could be removed if all old image paths are modified
+# to "wlimages/name_of_image.extension"
+def correct_image_path(modeladmin, request, queryset):
+    for obj in queryset:
+        # use original value of image because of CaSes
+        path = unicode(obj.image)
+        f_name =  path.rpartition("/")[2]
+        obj.image = "wlimages/%s" % (f_name)
+        obj.save()
+
 class ImageAdmin(admin.ModelAdmin):
     fieldsets = (
         (None, {'fields': ( ('image', 'name'), 'date_submitted', 'url','revision')}),
@@ -23,5 +34,6 @@
     list_filter = ('date_submitted',)
     date_hierarchy = 'date_submitted'
     search_fields = ('image', 'user__username')
+    actions = [correct_image_path]
 
 admin.site.register(Image, ImageAdmin)


Follow ups