allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [5/7] allura git commit: [#8143] refactor icon-saving logic into method; use it from nbhd-template code too
Date Tue, 31 Jan 2017 20:27:07 GMT
[#8143] refactor icon-saving logic into method; use it from nbhd-template code too


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/a124e25d
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/a124e25d
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/a124e25d

Branch: refs/heads/db/8143
Commit: a124e25d95678ad676da23130d28f84e42420a67
Parents: 419df7e
Author: Dave Brondsema <dave@brondsema.net>
Authored: Tue Jan 31 11:51:45 2017 -0500
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Tue Jan 31 15:12:31 2017 -0500

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py | 11 +----------
 Allura/allura/lib/plugin.py           |  9 ++-------
 Allura/allura/model/project.py        | 12 ++++++++++++
 3 files changed, 15 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/a124e25d/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index ef0f666..44c34df 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -451,16 +451,7 @@ class ProjectAdminController(BaseController):
             if c.project.icon:
                 M.ProjectFile.query.remove(dict(project_id=c.project._id, category=re.compile(r'^icon')))
             M.AuditLog.log('update project icon')
-            icon_orig, icon_thumb = M.ProjectFile.save_image(
-                icon.filename, icon.file, content_type=icon.type,
-                square=True, thumbnail_size=(48, 48),
-                thumbnail_meta=dict(project_id=c.project._id, category='icon'),
-                save_original=True,
-                original_meta=dict(project_id=c.project._id, category='icon_original'),
-            )
-            # store the dimensions so we don't have to read the whole image each time we
need to know
-            icon_orig_img = PIL.Image.open(icon_orig.rfile())
-            c.project.set_tool_data('allura', icon_original_size=icon_orig_img.size)
+            c.project.save_icon(icon.filename, icon.file, content_type=icon.type)
         g.post_event('project_updated')
         flash('Saved', 'success')
         redirect('overview')

http://git-wip-us.apache.org/repos/asf/allura/blob/a124e25d/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 952dc72..a0c20bf 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -941,13 +941,8 @@ class ProjectRegistrationProvider(object):
                     troves.append(
                         M.TroveCategory.query.get(trove_cat_id=trove_id)._id)
         if 'icon' in project_template:
-            icon_file = StringIO(
-                urlopen(project_template['icon']['url']).read())
-            M.ProjectFile.save_image(
-                project_template['icon']['filename'], icon_file,
-                square=True, thumbnail_size=(48, 48),
-                thumbnail_meta=dict(project_id=p._id, category='icon'))
-            # FIXME
+            icon_file = StringIO(urlopen(project_template['icon']['url']).read())
+            p.save_icon(project_template['icon']['filename'], icon_file)
 
         if user_project:
             # Allow for special user-only tools

http://git-wip-us.apache.org/repos/asf/allura/blob/a124e25d/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index db85b84..f05c0f0 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -358,6 +358,18 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
             project_id=self._id,
             category='screenshot')).sort('sort').all()
 
+    def save_icon(self, filename, file_input, content_type=None):
+        icon_orig, icon_thumb = ProjectFile.save_image(
+            filename, file_input, content_type=content_type,
+            square=True, thumbnail_size=(48, 48),
+            thumbnail_meta=dict(project_id=self._id, category='icon'),
+            save_original=True,
+            original_meta=dict(project_id=self._id, category='icon_original'),
+        )
+        # store the dimensions so we don't have to read the whole image each time we need
to know
+        icon_orig_img = PIL.Image.open(icon_orig.rfile())
+        self.set_tool_data('allura', icon_original_size=icon_orig_img.size)
+
     @property
     def icon(self):
         return self.icon_sized(DEFAULT_ICON_WIDTH)


Mime
View raw message