← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands-website/move_minimaps into lp:widelands-website

 

kaputtnik has proposed merging lp:~widelands-dev/widelands-website/move_minimaps into lp:widelands-website.

Commit message:
Move minimaps from 'media/wlmaps/maps/' to 'media/wlmaps/minimaps/' when uploading a map.


Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1608270 in Widelands Website: "One wrong migration / migrations files in general"
  https://bugs.launchpad.net/widelands-website/+bug/1608270

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands-website/move_minimaps/+merge/303493

Move minimaps from 'media/wlmaps/maps/' to 'media/wlmaps/minimaps/' when uploading a map.

Added a few comments to model wlmaps Map.

If merged only minimaps of newly uploaded maps where moved. I am working also on a branch which moves existing minimaps in media/wlmaps/maps/ to media/wlmaps/minimaps/.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/move_minimaps into lp:widelands-website.
=== modified file '.bzrignore'
--- .bzrignore	2016-07-31 11:11:22 +0000
+++ .bzrignore	2016-08-21 13:20:05 +0000
@@ -10,3 +10,4 @@
 media/wlprofile/avatars/*
 media/wlscreens/*
 media/wlimages/*
+media/wlmaps/minimaps/*

=== added directory 'media/wlmaps/minimaps'
=== modified file 'wlmaps/forms.py'
--- wlmaps/forms.py	2016-02-15 14:06:09 +0000
+++ wlmaps/forms.py	2016-08-21 13:20:05 +0000
@@ -11,7 +11,7 @@
 
 from settings import MEDIA_ROOT
 from wlmaps.models import Map
-
+from os import rename
 
 class UploadMapForm(ModelForm):
 
@@ -32,13 +32,19 @@
         try:
             # call map info tool to generate minimap and json info file
             check_call(['wl_map_info', name])
-            # TODO(shevonar): delete file because it will be saved again when
+            
+            # Delete file because it will be saved again when
             # the model is saved. File should not be saved twice
             default_storage.delete(name)
+            
         except CalledProcessError:
             self._errors['file'] = self.error_class(
                 ['The map file could not be processed.'])
             del cleaned_data['file']
+            
+            # The uploaded file should be deleted if an error occurs
+            default_storage.delete(name)
+            
             return cleaned_data
 
         mapinfo = json.load(open(name + '.json'))
@@ -49,6 +55,17 @@
             del cleaned_data['file']
             return cleaned_data
 
+        try:
+            # Move the minimap
+            rename(MEDIA_ROOT + '/wlmaps/maps/' + file.name + '.png',
+                   MEDIA_ROOT + '/wlmaps/minimaps/' + file.name + '.png' )
+        except OSError:
+            self._errors['file'] = self.error_class(
+                ['The minimap could not be moved. Please inform an admin.'])
+            del cleaned_data['file']
+            
+            return cleaned_data
+
         # Add information to the map
         self.instance.name = mapinfo['name']
         self.instance.author = mapinfo['author']
@@ -60,7 +77,7 @@
 
         self.instance.world_name = mapinfo['world_name']
         # mapinfo["minimap"] is an absolute path and cannot be used.
-        self.instance.minimap = '/wlmaps/maps/' + file.name + '.png'
+        self.instance.minimap = '/wlmaps/minimaps/' + file.name + '.png'
 
         # the json file is no longer needed
         default_storage.delete(name + '.json')

=== modified file 'wlmaps/models.py'
--- wlmaps/models.py	2016-08-11 18:13:59 +0000
+++ wlmaps/models.py	2016-08-21 13:20:05 +0000
@@ -14,6 +14,7 @@
 
 
 class Map(models.Model):
+    # Name of the map given in editor map options
     name = models.CharField(max_length=255, unique=True)
     slug = models.SlugField(unique=True)
     author = models.CharField(max_length=255)
@@ -23,8 +24,13 @@
 
     descr = models.TextField(verbose_name='Description')
     hint = models.TextField(verbose_name='Hint')
+    
+    # Attribute 'upload_to=' has no effect here; saving of minimap is
+    # processed in wlmaps.forms.UploadMapForm
     minimap = models.ImageField(
         verbose_name='Minimap', upload_to='wlmaps/minimaps')
+    
+    # The real filename of a map
     file = models.FileField(verbose_name='Mapfile',
                             upload_to='wlmaps/maps')
 


Follow ups