You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2016/06/02 14:54:18 UTC

allura git commit: [#7858] change category and skill lookup to use unique id numbers rather than "shortname" which might not be unique

Repository: allura
Updated Branches:
  refs/heads/db/7858 [created] aa49e570e


[#7858] change category and skill lookup to use unique id numbers rather than "shortname" which might not be unique


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

Branch: refs/heads/db/7858
Commit: aa49e570e2df9b5d76f2cd4c64f77e5f0ae50787
Parents: ff00dd7
Author: Dave Brondsema <da...@brondsema.net>
Authored: Thu Jun 2 10:53:59 2016 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Thu Jun 2 10:53:59 2016 -0400

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py               |  6 ++++--
 Allura/allura/controllers/trovecategories.py    | 14 +++++++------
 Allura/allura/lib/widgets/forms.py              |  2 +-
 Allura/allura/templates/trovecategories.html    |  4 ++--
 Allura/allura/templates/user_skills.html        |  6 +++---
 .../tests/functional/test_trovecategory.py      | 21 +++++++++++++++++---
 6 files changed, 36 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/aa49e570/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index e7492b2..9ad0dea 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -647,8 +647,10 @@ class UserSkillsController(BaseController):
         require_authenticated()
 
     @expose()
-    def _lookup(self, catshortname, *remainder):
-        cat = M.TroveCategory.query.get(shortname=catshortname)
+    def _lookup(self, trove_cat_id, *remainder):
+        cat = M.TroveCategory.query.get(trove_cat_id=int(trove_cat_id))
+        if not cat:
+            raise wexc.HTTPNotFound
         return UserSkillsController(category=cat), remainder
 
     @with_trailing_slash

http://git-wip-us.apache.org/repos/asf/allura/blob/aa49e570/Allura/allura/controllers/trovecategories.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/trovecategories.py b/Allura/allura/controllers/trovecategories.py
index b57e517..c05d2ed 100644
--- a/Allura/allura/controllers/trovecategories.py
+++ b/Allura/allura/controllers/trovecategories.py
@@ -20,7 +20,7 @@ from tg import expose, flash, redirect, validate, config
 from pylons import tmpl_context as c
 from string import digits, lowercase
 from tg.decorators import without_trailing_slash
-from webob.exc import HTTPForbidden
+from webob.exc import HTTPForbidden, HTTPNotFound
 from pylons import app_globals as g
 
 from allura import model as M
@@ -40,8 +40,10 @@ class F(object):
 
 class TroveCategoryController(BaseController):
     @expose()
-    def _lookup(self, catshortname, *remainder):
-        cat = M.TroveCategory.query.get(shortname=catshortname)
+    def _lookup(self, trove_cat_id, *remainder):
+        cat = M.TroveCategory.query.get(trove_cat_id=int(trove_cat_id))
+        if not cat:
+            raise HTTPNotFound
         return TroveCategoryController(category=cat), remainder
 
     def _check_security(self):
@@ -70,7 +72,7 @@ class TroveCategoryController(BaseController):
                 hierarchy = [temp_cat] + hierarchy
                 temp_cat = temp_cat.parent_category
         else:
-            l = M.TroveCategory.query.find(dict(trove_parent_id=0)).all()
+            l = M.TroveCategory.query.find(dict(trove_parent_id=0)).sort('fullname').all()
             selected_cat = None
             hierarchy = []
         return dict(
@@ -142,7 +144,7 @@ class TroveCategoryController(BaseController):
             else:
                 flash('An error occured while crearing the category.', "error")
         if upper:
-            redirect('/categories/%s' % upper.shortname)
+            redirect('/categories/%s' % upper.trove_cat_id)
         else:
             redirect('/categories')
 
@@ -154,7 +156,7 @@ class TroveCategoryController(BaseController):
         if cat.trove_parent_id:
             parent = M.TroveCategory.query.get(
                 trove_cat_id=cat.trove_parent_id)
-            redirecturl = '/categories/%s' % parent.shortname
+            redirecturl = '/categories/%s' % parent.trove_cat_id
         else:
             redirecturl = '/categories'
         if len(cat.subcategories) > 0:

http://git-wip-us.apache.org/repos/asf/allura/blob/aa49e570/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index df5ad84..fbff6d4 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -601,7 +601,7 @@ class RemoveTroveCategoryForm(ForgeForm):
                 fields=[
                     ew.LinkField(
                         text=cat.fullname,
-                        href="/categories/%s" % cat.shortname),
+                        href="/categories/%s" % cat.trove_cat_id),
                     ew.SubmitButton(
                         show_errors=False,
                         attrs={'value': 'Remove'})],

http://git-wip-us.apache.org/repos/asf/allura/blob/aa49e570/Allura/allura/templates/trovecategories.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/trovecategories.html b/Allura/allura/templates/trovecategories.html
index 91bbd9e..81b6c1c 100644
--- a/Allura/allura/templates/trovecategories.html
+++ b/Allura/allura/templates/trovecategories.html
@@ -29,7 +29,7 @@
       <div class="grid-20">
         <a href="/categories">Top-level categories</a>
         {% for cat in hierarchy %}
-          &gt; <a href="/categories/{{cat.shortname}}">{{cat.fullname}}</a>
+          &gt; <a href="/categories/{{cat.trove_cat_id}}">{{cat.fullname}}</a>
         {% endfor %}
         &gt; {{selected_cat.fullname}}
       </div>
@@ -72,7 +72,7 @@
       {{g.theme.add_trove_category.display(uppercategory_id=0)}}
     {% endif %}
     <div class="grid-20" style="margin-bottom:10px;">
-      Are you done creating new categories? <a href="/auth/user_info/skills/{{selected_cat.shortname}}">Click here</a> to configure your skills!
+      Are you done creating new categories? <a href="/auth/user_info/skills/{{selected_cat.trove_cat_id}}">Click here</a> to configure your skills!
     </div>
 
   </div>

http://git-wip-us.apache.org/repos/asf/allura/blob/aa49e570/Allura/allura/templates/user_skills.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_skills.html b/Allura/allura/templates/user_skills.html
index 7cf615c..4ed52bb 100644
--- a/Allura/allura/templates/user_skills.html
+++ b/Allura/allura/templates/user_skills.html
@@ -64,7 +64,7 @@
         <div class="grid-12" style="margin-bottom:20px">      
            <a href=".">List of all skills</a>
            {% for cat in parents %}
-             &gt; <a href="{{cat.shortname}}">{{cat.fullname}}</a>
+             &gt; <a href="{{cat.trove_cat_id}}">{{cat.fullname}}</a>
            {% endfor %}
            &gt; <b>{{selected_skill.fullname}}</b>
            <input type="hidden" name="upper_category" value="{{selected_skill.trove_parent_id}}"/>
@@ -83,7 +83,7 @@
     {% if selected_skill %}
       <h3>Add "{{selected_skill.fullname}}" to you set of skills</h3>
       {{g.theme.add_user_skill.display(selected_skill=selected_skill.trove_cat_id, 
-           action=selected_skill.shortname + "/save_skill")}}
+           action="{}/save_skill".format(selected_skill.trove_cat_id)) }}
     {% endif %}
 
     <h3>Other possible actions</h3>
@@ -92,7 +92,7 @@
         {% if tg.config.get('trovecategories.enableediting', 'false') == 'true' %}
           {% if selected_skill %}
             <li>
-              <a href="/categories/{{selected_skill.shortname}}">
+              <a href="/categories/{{selected_skill.trove_cat_id}}">
                 Create a new category in this list
               </a>
               if you want to add a more specific kind of skill which is not included here.

http://git-wip-us.apache.org/repos/asf/allura/blob/aa49e570/Allura/allura/tests/functional/test_trovecategory.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_trovecategory.py b/Allura/allura/tests/functional/test_trovecategory.py
index 64992a7..3b1076d 100644
--- a/Allura/allura/tests/functional/test_trovecategory.py
+++ b/Allura/allura/tests/functional/test_trovecategory.py
@@ -82,14 +82,29 @@ class TestTroveCategory(TestController):
 
 
 class TestTroveCategoryController(TestController):
-    @td.with_tool('test2', 'admin_main', 'admin')
-    def test_trove_hierarchy(self):
+    def create_some_cats(self):
         root_parent = M.TroveCategory(fullname="Root", trove_cat_id=1, trove_parent_id=0)
         category_a = M.TroveCategory(fullname="CategoryA", trove_cat_id=2, trove_parent_id=1)
         category_b = M.TroveCategory(fullname="CategoryB", trove_cat_id=3, trove_parent_id=1)
         child_a = M.TroveCategory(fullname="ChildA", trove_cat_id=4, trove_parent_id=2)
         child_b = M.TroveCategory(fullname="ChildB", trove_cat_id=5, trove_parent_id=2)
 
+    def test_root(self):
+        self.create_some_cats()
+        session(M.TroveCategory).flush()
+        r = self.app.get('/categories/')
+        assert '<a href="/categories/1">Root</a>' in r
+
+    def test_subcat(self):
+        self.create_some_cats()
+        session(M.TroveCategory).flush()
+        r = self.app.get('/categories/1')
+        assert '<a href="/categories/2">CategoryA</a>' in r
+        assert '<a href="/categories/3">CategoryB</a>' in r
+
+    @td.with_tool('test2', 'admin_main', 'admin')
+    def test_trove_hierarchy(self):
+        self.create_some_cats()
         session(M.TroveCategory).flush()
 
         r = self.app.get('/categories/browse')
@@ -117,4 +132,4 @@ class TestTroveCategoryController(TestController):
         <ul>
         </ul>
         """.strip())
-        assert str(expected) == str(rendered_tree)
\ No newline at end of file
+        assert str(expected) == str(rendered_tree)