allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: [#8174] Improve messaging for project icon uploads
Date Mon, 15 Jan 2018 20:14:12 GMT
Repository: allura
Updated Branches:
  refs/heads/master 0a279cde1 -> 3cf74ee59


[#8174] Improve messaging for project icon uploads


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

Branch: refs/heads/master
Commit: 3cf74ee595de06ac93b3827085c9178c5ed1e616
Parents: 0a279cd
Author: Kenton Taylor <ktaylor@slashdotmedia.com>
Authored: Mon Jan 15 19:10:34 2018 +0000
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Mon Jan 15 15:14:00 2018 -0500

----------------------------------------------------------------------
 .../templates/admin_widgets/metadata_admin.html |  4 +--
 .../ext/admin/templates/project_overview.html   |  5 ++-
 Allura/allura/ext/admin/widgets.py              |  3 +-
 Allura/allura/lib/validators.py                 | 14 +++++++++
 Allura/allura/tests/test_validators.py          | 33 ++++++++++++++++++++
 5 files changed, 55 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/3cf74ee5/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 97c0b9e..27acac4 100644
--- a/Allura/allura/ext/admin/templates/admin_widgets/metadata_admin.html
+++ b/Allura/allura/ext/admin/templates/admin_widgets/metadata_admin.html
@@ -94,7 +94,7 @@
   </div>
 
   <div class="grid-10">
-    <label>Icon:</label>
+    <label>Project Logo:</label>
     <br>
     <div id="project-icon" class="viewing">
       {% if value.icon %}
@@ -114,7 +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>
+          <br><small>(best if square & hi-res. JPG, GIF, or PNG files expected.)</small>
       </div>
     </div>
     {%if c.project.neighborhood.name != 'Users' or not value.is_root%}

http://git-wip-us.apache.org/repos/asf/allura/blob/3cf74ee5/Allura/allura/ext/admin/templates/project_overview.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/project_overview.html b/Allura/allura/ext/admin/templates/project_overview.html
index 90eca92..649eb12 100644
--- a/Allura/allura/ext/admin/templates/project_overview.html
+++ b/Allura/allura/ext/admin/templates/project_overview.html
@@ -39,7 +39,7 @@
     /*global confirm: true*/
     $(document).ready(function () {
       $.maxlength.setDefaults({feedbackText : '{r} characters left'})
-      
+
       var $metadata_form = $('#metadata_form');
       var $removal_original = $('input[name=removal]:checked');
       var $removal_delete_cb = $('#removal_delete_cb');
@@ -79,6 +79,9 @@
         var $parent = $this.closest('#project-icon');
         $('#project-icon-upload').removeClass('hidden');
       });
+      if($('#project-icon-upload .error').length) {
+        $('#project-icon-upload').removeClass('hidden');
+      }
       $('#project-status a').click(function(e) {
         e.preventDefault();
         $('#project-status-edit').removeClass('hidden');

http://git-wip-us.apache.org/repos/asf/allura/blob/3cf74ee5/Allura/allura/ext/admin/widgets.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/widgets.py b/Allura/allura/ext/admin/widgets.py
index 7c7e05c..dd10429 100644
--- a/Allura/allura/ext/admin/widgets.py
+++ b/Allura/allura/ext/admin/widgets.py
@@ -214,7 +214,8 @@ class MetadataAdmin(ff.AdminForm):
             append_to='bottom',
             extra_field_on_focus_name='feature',
             field=FeaturesField())
-        icon = ew.FileField(label='Icon', attrs={'accept': 'image/*'})
+        icon = ew.FileField(label='Icon', attrs={'accept': 'image/*'},
+                            validator=V.IconValidator())
         external_homepage = ew.InputField(field_type="text", label='Homepage',
                                           validator=fev.URL(add_http=True))
         video_url = ew.InputField(field_type="text", label="Video (YouTube)",

http://git-wip-us.apache.org/repos/asf/allura/blob/3cf74ee5/Allura/allura/lib/validators.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/validators.py b/Allura/allura/lib/validators.py
index 39985c7..7331c4e 100644
--- a/Allura/allura/lib/validators.py
+++ b/Allura/allura/lib/validators.py
@@ -427,3 +427,17 @@ def convertTime(timestring):
         except:
             pass
     return None
+
+
+class IconValidator(fev.FancyValidator):
+    regex = '(jpg|jpeg|gif|png)$'
+    def _to_python(self, value, state):
+        p = re.compile(self.regex, flags=re.I)
+        result = p.search(value.filename)
+
+        if not result:
+            raise fe.Invalid(
+                'Project icons must be PNG, GIF, or JPG format.',
+                value, state)
+
+        return value

http://git-wip-us.apache.org/repos/asf/allura/blob/3cf74ee5/Allura/allura/tests/test_validators.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_validators.py b/Allura/allura/tests/test_validators.py
index f50b8f7..e812655 100644
--- a/Allura/allura/tests/test_validators.py
+++ b/Allura/allura/tests/test_validators.py
@@ -285,3 +285,36 @@ class TestNonHttpUrlValidator(unittest.TestCase):
         with self.assertRaises(fe.Invalid) as cm:
             self.val.to_python('url')
         self.assertEqual(str(cm.exception), 'You must start your URL with a scheme')
+
+
+class TestIconValidator(unittest.TestCase):
+    val = v.IconValidator
+
+    def _mock(self, val):
+        # Mock has an attr `mixed`, which inadvertantly gets called by formencode to_python
method :/
+        def f(filename): pass
+
+        m = Mock(spec=f)
+        m.filename = val
+        return m
+
+    def test_valid(self):
+        input = self._mock('foo.png')
+        self.assertEqual(input, self.val.to_python(input))
+
+        input = self._mock('foo.jpg')
+        self.assertEqual(input, self.val.to_python(input))
+
+        input = self._mock('svg.jpg')
+        self.assertEqual(input, self.val.to_python(input))
+
+    def test_invalid(self):
+        input = self._mock('foo.svg')
+        with self.assertRaises(fe.Invalid) as cm:
+            self.val.to_python(input)
+        self.assertEqual(str(cm.exception), 'Project icons must be PNG, GIF, or JPG format.')
+
+        input = self._mock('foogif.svg')
+        with self.assertRaises(fe.Invalid) as cm:
+            self.assertEqual(input, self.val.to_python(input))
+        self.assertEqual(str(cm.exception), 'Project icons must be PNG, GIF, or JPG format.')


Mime
View raw message