You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2018/02/02 20:10:02 UTC

allura git commit: fixup! fixup! [#8182] Improvements to Category/Trove admin

Repository: allura
Updated Branches:
  refs/heads/kt/8182 d6ca29cc9 -> 878533254


fixup! fixup! [#8182] Improvements to Category/Trove admin


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

Branch: refs/heads/kt/8182
Commit: 8785332547b11da1964dc8b4c100cf1105aa9f55
Parents: d6ca29c
Author: Kenton Taylor <kt...@slashdotmedia.com>
Authored: Fri Feb 2 20:09:51 2018 +0000
Committer: Kenton Taylor <kt...@slashdotmedia.com>
Committed: Fri Feb 2 20:09:51 2018 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/trovecategories.py         |  4 ++--
 Allura/allura/ext/admin/templates/project_trove.html |  2 +-
 Allura/allura/lib/helpers.py                         |  7 ++++---
 Allura/allura/lib/widgets/forms.py                   |  8 +++-----
 Allura/allura/templates/trovecategories.html         |  2 +-
 Allura/allura/tests/test_helpers.py                  | 12 ++++++++++++
 6 files changed, 23 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/87853325/Allura/allura/controllers/trovecategories.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/trovecategories.py b/Allura/allura/controllers/trovecategories.py
index be8e7ea..2e2c33f 100644
--- a/Allura/allura/controllers/trovecategories.py
+++ b/Allura/allura/controllers/trovecategories.py
@@ -144,9 +144,9 @@ class TroveCategoryController(BaseController):
             else:
                 flash('An error occured while crearing the category.', "error")
         if upper:
-            redirect('/categories/{}/?categoryname={}&shortname={}'.format(upper.trove_cat_id, name, shortname))
+            redirect(u'/categories/{}/?categoryname={}&shortname={}'.format(upper.trove_cat_id, name, shortname))
         else:
-            redirect('/categories/?categoryname={}&shortname={}'.format(name, shortname))
+            redirect(u'/categories/?categoryname={}&shortname={}'.format(name, shortname))
 
     @expose()
     @require_post()

http://git-wip-us.apache.org/repos/asf/allura/blob/87853325/Allura/allura/ext/admin/templates/project_trove.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/project_trove.html b/Allura/allura/ext/admin/templates/project_trove.html
index 81173cf..ea1a3bf 100644
--- a/Allura/allura/ext/admin/templates/project_trove.html
+++ b/Allura/allura/ext/admin/templates/project_trove.html
@@ -94,7 +94,7 @@
       </form>
     </div>
   </div>
-  {% for base in base_troves %}
+  {% for base in base_troves if hasattr(c.project, "trove_{}".format(base.shortname))%}
     {{show_trove_base_cat(base)}}
   {% endfor %}
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/allura/blob/87853325/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 2be5139..572b6e6 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -1297,13 +1297,14 @@ def base64uri(content_or_image, image_format='PNG', mimetype='image/png'):
     return 'data:{};base64,{}'.format(mimetype, data)
 
 
-def slugify(name):
+def slugify(name, allow_periods=False):
     """
-    Returns a tuple with slug and lowered slug ased on name, according to our specific rules for commercial software.
+    Returns a tuple with slug and lowered slug based on name
     """
+    dash_collapse_pattern = r'[^.\w]+' if allow_periods else r'[^\w]+'
     slug = re.sub(r'(^-)|(-$)', '',  # leading - or trailing - gets removed
                   unicode(
-                      re.sub(r'[^.\w]+', '-',  # replace non ". alphanum_" sequences into single -
+                      re.sub(dash_collapse_pattern, '-',  # replace non ". alphanum_" sequences into single -
                              re.sub(r"'", '',  # remove any apostrophes
                                     unicodedata.normalize('NFKD', name)
                                     .encode('ascii', 'ignore')))

http://git-wip-us.apache.org/repos/asf/allura/blob/87853325/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index 871d809..d92471c 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -599,12 +599,12 @@ class RemoveTroveCategoryForm(ForgeForm):
                 show_errors=False,
                 show_label=False,
                 fields=[
-                    ew.HTMLField(
-                        text=cat.shortname,
-                        attrs={'disabled':True, 'value':cat.shortname}),
                     ew.LinkField(
                         text=cat.fullname,
                         href="/categories/%s" % cat.trove_cat_id),
+                    ew.HTMLField(
+                        text=cat.shortname,
+                        attrs={'disabled':True, 'value':cat.shortname}),
                     ew.SubmitButton(
                         show_errors=False,
                         attrs={'value': 'Remove'})],
@@ -643,8 +643,6 @@ class AddTroveCategoryForm(ForgeForm):
         upper_category = kw.get('uppercategory_id', 0)
 
         self.fields['uppercategory_id'].attrs['value'] = upper_category
-        # self.fields['shortname'].attrs['value'] = kw.get('shortname', '')
-        # self.fields['categoryname'].attrs['value'] = kw.get('categoryname', '')
         return super(ForgeForm, self).display(**kw)
 
     @ew_core.core.validator

http://git-wip-us.apache.org/repos/asf/allura/blob/87853325/Allura/allura/templates/trovecategories.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/trovecategories.html b/Allura/allura/templates/trovecategories.html
index 0e82aab..ff7959c 100644
--- a/Allura/allura/templates/trovecategories.html
+++ b/Allura/allura/templates/trovecategories.html
@@ -47,8 +47,8 @@
       <table>
         <thead>
           <tr>
-            <th>Short Name</th>
             <th>Name</th>
+            <th>Short Name</th>
             <th>Actions</th>
           </tr>
         </thead>

http://git-wip-us.apache.org/repos/asf/allura/blob/87853325/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index fbc9813..e7ace1c 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -601,3 +601,15 @@ def test_base64uri_img():
 def test_base64uri_text():
     b64txt = h.base64uri('blah blah blah 123 456 foo bar baz', mimetype='text/plain')
     assert b64txt.startswith('data:text/plain;base64,'), b64txt
+
+
+def test_slugify():
+    assert_equals(h.slugify(u'Foo Bar Bat')[0], 'Foo-Bar-Bat')
+    assert_equals(h.slugify(u'Foo_Bar')[0], 'Foo_Bar')
+    assert_equals(h.slugify(u'Foo   ')[0], 'Foo')
+    assert_equals(h.slugify(u'    Foo   ')[0], 'Foo')
+    assert_equals(h.slugify(u'"    Foo   ')[0], 'Foo')
+    assert_equals(h.slugify(u'Fôö')[0], 'Foo')
+    assert_equals(h.slugify(u'Foo.Bar')[0], 'Foo-Bar')
+    assert_equals(h.slugify(u'Foo.Bar', True)[0], 'Foo.Bar')
+