allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [3/7] allura git commit: [#8143] Upload & serve hi-res logos
Date Tue, 31 Jan 2017 20:27:05 GMT
[#8143] Upload & serve hi-res logos


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

Branch: refs/heads/db/8143
Commit: bfca80feed431a8269396409507bbaabbbf411e1
Parents: 887ca59
Author: Dave Brondsema <dave@brondsema.net>
Authored: Fri Jan 27 18:12:20 2017 -0500
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Tue Jan 31 11:36:02 2017 -0500

----------------------------------------------------------------------
 Allura/allura/controllers/project.py            |  8 +++--
 Allura/allura/ext/admin/admin_main.py           | 12 ++++---
 .../templates/admin_widgets/metadata_admin.html |  1 +
 Allura/allura/lib/plugin.py                     |  1 +
 Allura/allura/model/filesystem.py               |  2 +-
 Allura/allura/model/project.py                  | 36 ++++++++++++++++----
 Allura/development.ini                          |  6 ++++
 7 files changed, 52 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/bfca80fe/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 8821f9e..eca8833 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -420,8 +420,12 @@ class ProjectController(FeedController):
             project.url())
 
     @expose()
-    def icon(self, **kw):
-        icon = c.project.icon
+    def icon(self, w=48, **kw):
+        try:
+            icon = c.project.icon_sized(w=int(w))
+        except ValueError as e:
+            log.info('Invalid project icon size: %s on %s', e, request.url)
+            icon = None
         if not icon:
             raise exc.HTTPNotFound
         return icon.serve()

http://git-wip-us.apache.org/repos/asf/allura/blob/bfca80fe/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 6e21e4a..fc7e9c5 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -16,6 +16,7 @@
 #       under the License.
 
 import logging
+import re
 from collections import OrderedDict
 from datetime import datetime
 from urlparse import urlparse
@@ -348,8 +349,7 @@ class ProjectAdminController(BaseController):
             c.project.removal = removal
             c.project.removal_changed_date = datetime.utcnow()
         if 'delete_icon' in kw:
-            M.ProjectFile.query.remove(
-                dict(project_id=c.project._id, category='icon'))
+            M.ProjectFile.query.remove(dict(project_id=c.project._id, category=re.compile(r'^icon')))
             M.AuditLog.log('remove project icon')
             h.log_action(log, 'remove project icon').info('')
             g.post_event('project_updated')
@@ -448,13 +448,15 @@ class ProjectAdminController(BaseController):
 
         if icon is not None and icon != '':
             if c.project.icon:
-                M.ProjectFile.remove(
-                    dict(project_id=c.project._id, category='icon'))
+                M.ProjectFile.query.remove(dict(project_id=c.project._id, category=re.compile(r'^icon')))
             M.AuditLog.log('update project icon')
             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'))
+                thumbnail_meta=dict(project_id=c.project._id, category='icon'),
+                save_original=True,
+                original_meta=dict(project_id=c.project._id, category='icon_original'),
+            )
         g.post_event('project_updated')
         flash('Saved', 'success')
         redirect('overview')

http://git-wip-us.apache.org/repos/asf/allura/blob/bfca80fe/Allura/allura/ext/admin/templates/admin_widgets/metadata_admin.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/admin_widgets/metadata_admin.html b/Allura/allura/ext/admin/templates/admin_widgets/metadata_admin.html
index d7a1506..e26c98e 100644
--- a/Allura/allura/ext/admin/templates/admin_widgets/metadata_admin.html
+++ b/Allura/allura/ext/admin/templates/admin_widgets/metadata_admin.html
@@ -114,6 +114,7 @@
       <div id="project-icon-upload" class="hidden">
           {{widget.display_field(widget.fields.icon)}}
           <input type="submit" value="Save" name="save" style="float: none" />
+          <br><small>(best if square & hi-res)</small>
       </div>
     </div>
     {%if c.project.neighborhood.name != 'Users'%}

http://git-wip-us.apache.org/repos/asf/allura/blob/bfca80fe/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 4b2bf0a..952dc72 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -947,6 +947,7 @@ class ProjectRegistrationProvider(object):
                 project_template['icon']['filename'], icon_file,
                 square=True, thumbnail_size=(48, 48),
                 thumbnail_meta=dict(project_id=p._id, category='icon'))
+            # FIXME
 
         if user_project:
             # Allow for special user-only tools

http://git-wip-us.apache.org/repos/asf/allura/blob/bfca80fe/Allura/allura/model/filesystem.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/filesystem.py b/Allura/allura/model/filesystem.py
index 5b747b2..47c5eeb 100644
--- a/Allura/allura/model/filesystem.py
+++ b/Allura/allura/model/filesystem.py
@@ -128,7 +128,6 @@ class File(MappedClass):
                        thumbnail_size=None,
                        thumbnail_meta=None,
                        square=False):
-        format = image.format
         height = image.size[0]
         width = image.size[1]
         if square and height != width:
@@ -151,6 +150,7 @@ class File(MappedClass):
         thumbnail_meta = thumbnail_meta or {}
         thumbnail = cls(
             filename=filename, content_type=content_type, **thumbnail_meta)
+        format = image.format or 'png'
         with thumbnail.wfile() as fp_w:
             if 'transparency' in image.info:
                 image.save(fp_w,

http://git-wip-us.apache.org/repos/asf/allura/blob/bfca80fe/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 3b36ea2..c80a136 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -27,11 +27,12 @@ from xml.etree import ElementTree as ET
 from tg import config
 from pylons import tmpl_context as c, app_globals as g
 from pylons import request
-from paste.deploy.converters import asbool
+from paste.deploy.converters import asbool, aslist
 import formencode as fe
-import json
 from webob import exc
+import PIL
 
+from allura.lib.decorators import memoize
 from ming import schema as S
 from ming.utils import LazyProperty
 from ming.orm import ThreadLocalORMSession
@@ -63,6 +64,8 @@ log = logging.getLogger(__name__)
 # max sitemap entries per tool type
 SITEMAP_PER_TOOL_LIMIT = 10
 
+DEFAULT_ICON_WIDTH = 48
+
 
 class ProjectFile(File):
 
@@ -354,11 +357,32 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
             project_id=self._id,
             category='screenshot')).sort('sort').all()
 
-    @LazyProperty
+    @property
     def icon(self):
-        return ProjectFile.query.get(
-            project_id=self._id,
-            category='icon')
+        return self.icon_sized(DEFAULT_ICON_WIDTH)
+
+    @memoize
+    def icon_sized(self, w):
+        allowed_sizes = map(int, aslist(config.get('project_icon_sizes', '48 72 96')))
+        if w not in allowed_sizes:
+            raise ValueError('Width must be one of {} (see project_icon_sizes in your .ini
file)'.format(allowed_sizes))
+        if w == DEFAULT_ICON_WIDTH:
+            icon_cat_name = 'icon'
+        else:
+            icon_cat_name = 'icon-{}'.format(w)
+        sized = ProjectFile.query.get(project_id=self._id, category=icon_cat_name)
+        if not sized and w != DEFAULT_ICON_WIDTH:
+            orig = ProjectFile.query.get(project_id=self._id, category='icon_original')
+            if not orig:
+                return None
+            sized = orig.save_thumbnail(filename='',
+                                        image=PIL.Image.open(orig.rfile()),
+                                        content_type=orig.content_type,
+                                        thumbnail_size=(w, w),
+                                        thumbnail_meta=dict(project_id=c.project._id, category=icon_cat_name),
+                                        square=True,
+                                        )
+        return sized
 
     @property
     def description_html(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/bfca80fe/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index a030020..5cc3219 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -131,6 +131,12 @@ global_nav = [{"title": "Site Home", "url": "/"}]
 registration.method = local
 theme = allura
 
+; These are the sizes of project icons that may be requested.  They will be saved to the
database.
+; If your theme is going to support other sizes, update this list.
+; If you remove sizes, you can clean up space in mongodb with e.g: `db.fs.remove({category:/^icon-84/},
{multi:true})`
+; 48 is the historical default size
+project_icon_sizes = 48 72 96
+
 ; For LDAP see https://forge-allura.apache.org/docs/getting_started/installation.html#using-ldap
 ;auth.method = ldap
 auth.method = local


Mime
View raw message