allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [4/7] allura git commit: [#8143] use the hi-res logos from HTML
Date Tue, 31 Jan 2017 20:27:06 GMT
[#8143] use the hi-res logos from HTML


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

Branch: refs/heads/db/8143
Commit: 419df7e1e33669ac18bdadc366e28cad6efedae9
Parents: fe26253
Author: Dave Brondsema <dave@brondsema.net>
Authored: Mon Jan 30 16:31:32 2017 -0500
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Tue Jan 31 15:12:30 2017 -0500

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py           | 12 ++++++----
 .../templates/admin_widgets/metadata_admin.html |  2 +-
 .../templates/sections/projects.html            |  3 ++-
 Allura/allura/lib/utils.py                      |  3 +++
 Allura/allura/model/project.py                  | 25 +++++++++++++++++---
 Allura/allura/templates/jinja_master/lib.html   | 14 +++++++++++
 .../allura/templates/jinja_master/nav_menu.html |  2 +-
 .../templates/widgets/project_summary.html      |  5 ++--
 8 files changed, 54 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/419df7e1/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 fc7e9c5..ef0f666 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -23,6 +23,7 @@ from urlparse import urlparse
 import json
 from operator import itemgetter, attrgetter
 import pkg_resources
+
 from pylons import tmpl_context as c, app_globals as g, response
 from pylons import request
 from paste.deploy.converters import asbool, aslist
@@ -32,12 +33,12 @@ from webob import exc
 from bson import ObjectId
 from ming.orm.ormsession import ThreadLocalORMSession
 from ming.odm import session
-from ming.utils import LazyProperty
+import PIL
+
 from allura.app import Application, DefaultAdminController, SitemapEntry
 from allura.lib import helpers as h
 from allura import version
 from allura import model as M
-from allura.lib.repository import RepositoryApp
 from allura.lib.security import has_access, require_access
 from allura.lib.widgets import form_fields as ffw
 from allura.lib import exceptions as forge_exc
@@ -46,7 +47,6 @@ from allura.controllers import BaseController
 from allura.lib.decorators import require_post
 from allura.tasks import export_tasks
 from allura.lib.widgets.project_list import ProjectScreenshots
-from allura.lib.utils import is_ajax
 
 from . import widgets as aw
 
@@ -350,6 +350,7 @@ class ProjectAdminController(BaseController):
             c.project.removal_changed_date = datetime.utcnow()
         if 'delete_icon' in kw:
             M.ProjectFile.query.remove(dict(project_id=c.project._id, category=re.compile(r'^icon')))
+            c.project.set_tool_data('allura', icon_original_size=None)
             M.AuditLog.log('remove project icon')
             h.log_action(log, 'remove project icon').info('')
             g.post_event('project_updated')
@@ -450,13 +451,16 @@ 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')
-            M.ProjectFile.save_image(
+            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)
         g.post_event('project_updated')
         flash('Saved', 'success')
         redirect('overview')

http://git-wip-us.apache.org/repos/asf/allura/blob/419df7e1/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 e26c98e..a26eb9e 100644
--- a/Allura/allura/ext/admin/templates/admin_widgets/metadata_admin.html
+++ b/Allura/allura/ext/admin/templates/admin_widgets/metadata_admin.html
@@ -99,7 +99,7 @@
     <div id="project-icon" class="viewing">
       {% if value.icon %}
         <div class="viewer" style="overflow: auto">
-          <img src="{{value.url()}}icon?{{value.icon._id.generation_time}}" style="float:left;
margin-right: 1em;" alt="">
+          <img {{ lib.project_icon_srcs(value) }} style="float:left; margin-right: 1em;"
alt="">
           {{ g.icons['edit'].render(id='edit-icon', style='display:inline-block;margin-top:15px')
}}
           {{ g.icons['delete'].render(id='delete-icon', style='display:inline-block;margin-top:15px')
}}
         </div>

http://git-wip-us.apache.org/repos/asf/allura/blob/419df7e1/Allura/allura/ext/user_profile/templates/sections/projects.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/user_profile/templates/sections/projects.html b/Allura/allura/ext/user_profile/templates/sections/projects.html
index 7e1756b..7f9c2d8 100644
--- a/Allura/allura/ext/user_profile/templates/sections/projects.html
+++ b/Allura/allura/ext/user_profile/templates/sections/projects.html
@@ -17,6 +17,7 @@
        under the License.
 -#}
 {% extends "allura.ext.user_profile:templates/profile_section_base.html" %}
+{% import 'allura:templates/jinja_master/lib.html' as lib with context %}
 
 {% block title %}
     Projects
@@ -35,7 +36,7 @@
     {% for project in projects %}
         <li{% if loop.index > 5 %} class="hidden"{% endif %}>
             {% if project.icon -%}
-                <img src="{{project.url()}}icon?{{project.icon._id.generation_time}}"
alt="Project Logo" width="48" height="48"/>
+                <img {{ lib.project_icon_srcs(project) }} alt="Project Logo" width="48"
height="48"/>
             {%- else -%}
                 <img src="{{g.forge_static('images/project_default.png')}}" alt="Project
Logo" width="48" height="48"/>
             {%- endif -%}

http://git-wip-us.apache.org/repos/asf/allura/blob/419df7e1/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index b75a7f8..e68e287 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -559,6 +559,9 @@ class ForgeHTMLSanitizer(html5lib.sanitizer.HTMLSanitizer):
                        + html5lib.sanitizer.HTMLSanitizer.mathml_elements \
                        + html5lib.sanitizer.HTMLSanitizer.svg_elements
 
+    # srcset is used in our own project_list/project_summary widgets which are used as macros
so go through markdown
+    allowed_attributes = html5lib.sanitizer.HTMLSanitizer.allowed_attributes + ['srcset']
+
     valid_iframe_srcs = ('https://www.youtube.com/embed/', 'https://www.gittip.com/')
 
     _prev_token_was_ok_iframe = False

http://git-wip-us.apache.org/repos/asf/allura/blob/419df7e1/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index c80a136..db85b84 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -17,6 +17,7 @@
 #       under the License.
 
 import logging
+from calendar import timegm
 from collections import Counter, OrderedDict
 from datetime import datetime
 from copy import deepcopy
@@ -372,7 +373,7 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
             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')
+            orig = self.icon_original
             if not orig:
                 return None
             sized = orig.save_thumbnail(filename='',
@@ -384,6 +385,25 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
                                         )
         return sized
 
+    @LazyProperty
+    def icon_original(self):
+        return ProjectFile.query.get(project_id=self._id, category='icon_original')
+
+    @LazyProperty
+    def icon_max_size(self):
+        stored_original_size = self.get_tool_data('allura', 'icon_original_size')
+        if stored_original_size:
+            # max not min, since non-square images get white padding added
+            return max(stored_original_size)
+        elif self.icon:
+            return DEFAULT_ICON_WIDTH
+        else:
+            return None
+
+    @LazyProperty
+    def icon_timestamp(self):
+        return timegm(self.icon._id.generation_time.timetuple())
+
     @property
     def description_html(self):
         return g.markdown.cached_convert(self, 'description')
@@ -503,8 +523,7 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
         for icon in ProjectFile.query.find(dict(
                 project_id={'$in': result.keys()},
                 category='icon')):
-            result[icon.project_id] = project_index[
-                icon.project_id].url() + 'icon'
+            result[icon.project_id] = project_index[icon.project_id].url() + 'icon'
         return result
 
     @classmethod

http://git-wip-us.apache.org/repos/asf/allura/blob/419df7e1/Allura/allura/templates/jinja_master/lib.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/lib.html b/Allura/allura/templates/jinja_master/lib.html
index ad4e227..65a5f52 100644
--- a/Allura/allura/templates/jinja_master/lib.html
+++ b/Allura/allura/templates/jinja_master/lib.html
@@ -200,6 +200,20 @@
     {{ g.icons['restore'].render(show_title=True, id='restore-content') }}
 {%- endmacro %}
 
+{#
+ icon_url param is entirely optional; only pass it if you already have one for effeciency
+#}
+{%- macro project_icon_srcs(project, icon_url=None) %}
+    {% set icon_url = icon_url or project.url() + 'icon' %}
+    src="{{icon_url}}?{{project.icon_timestamp}}"
+    {% if project.icon_max_size >= 72 -%}
+        srcset="{{icon_url}}?w=72&amp;{{project.icon_timestamp}} 1.5x,
+        {% if project.icon_max_size >= 96 -%}
+            {{icon_url}}?w=96&amp;{{project.icon_timestamp}} 2x,
+        {%- endif -%}
+        "
+   {%- endif -%}
+{%- endmacro %}
 
 
 {% macro markdown_syntax(id='') %}

http://git-wip-us.apache.org/repos/asf/allura/blob/419df7e1/Allura/allura/templates/jinja_master/nav_menu.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/nav_menu.html b/Allura/allura/templates/jinja_master/nav_menu.html
index e100912..0f956ce 100644
--- a/Allura/allura/templates/jinja_master/nav_menu.html
+++ b/Allura/allura/templates/jinja_master/nav_menu.html
@@ -29,7 +29,7 @@
     {% if c.project.is_user_project %}
       {{lib.gravatar(c.project.user_project_of, size=48, className='project_icon')}}
     {% elif c.project.icon %}
-      <img src="{{c.project.url()}}icon?{{c.project.icon._id.generation_time}}" class="project_icon"
alt="Project Logo">
+      <img class="project_icon" alt="Project Logo" {{ lib.project_icon_srcs(c.project)
}}>
     {% endif %}
         <h1 class="project_title">
             <a href="{{c.project.url()}}" class="project_link">

http://git-wip-us.apache.org/repos/asf/allura/blob/419df7e1/Allura/allura/templates/widgets/project_summary.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/project_summary.html b/Allura/allura/templates/widgets/project_summary.html
index 10d8693..ee1b61f 100644
--- a/Allura/allura/templates/widgets/project_summary.html
+++ b/Allura/allura/templates/widgets/project_summary.html
@@ -16,6 +16,7 @@
        specific language governing permissions and limitations
        under the License.
 -#}
+{% import 'allura:templates/jinja_master/lib.html' as lib with context %}
 <div class="list card{% if show_proj_icon%} proj_icon{% endif %}"
 	{%- if columns == 2 %} style="width: 330px"{% elif columns == 3 %} style="width: 220px"{%
endif %}>
   {% if accolades %}
@@ -23,11 +24,11 @@
       <div class="feature">
         <a href="{{accolades[0].award_url}}" title="{{accolades[0].comment}}">{{accolades[0].award.short}}</a>
       </div>
-      {% if icon_url %}<img src="{{icon_url}}" alt="{{value.name}} Logo"/>{% endif
%}
+      {% if icon_url %}<img {{ lib.project_icon_srcs(project=value, icon_url=icon_url)
}} alt="{{value.name}} Logo" width="48" height="48"/>{% endif %}
     </div>
   {% elif icon_url %}
     <div class="box">
-      <img src="{{icon_url}}" alt="{{value.name}} Logo"/>
+      <img {{ lib.project_icon_srcs(value, icon_url=icon_url) }} alt="{{value.name}} Logo"
width="48" height="48"/>
     </div>
   {% endif %}
   <h2><a href="{{value.url()}}">{{value.name}}</a></h2>


Mime
View raw message