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 2014/07/18 21:02:19 UTC
[12/28] git commit: [#7293] Trove Categories Listing
[#7293] Trove Categories Listing
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/326ba276
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/326ba276
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/326ba276
Branch: refs/heads/db/7523
Commit: 326ba27674245edac7b3dcb8f22d6ca947204bc5
Parents: d9e2aa7
Author: Alexander Luberg <al...@slashdotmedia.com>
Authored: Thu Jul 3 23:15:32 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Jul 9 18:07:08 2014 +0000
----------------------------------------------------------------------
.gitignore | 1 +
Allura/allura/controllers/trovecategories.py | 25 ++++++++++++++
Allura/allura/ext/admin/admin_main.py | 1 +
.../templates/browse_trove_categories.html | 36 ++++++++++++++++++++
Allura/allura/templates/trovecategories.html | 1 +
.../tests/functional/test_trovecategory.py | 36 +++++++++++++++++++-
6 files changed, 99 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/326ba276/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 230b56d..a792fb7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,4 @@ Allura/forced_upgrade.ini
scripts/teamforge-export/
report.clonedigger
.ropeproject
+.idea
http://git-wip-us.apache.org/repos/asf/allura/blob/326ba276/Allura/allura/controllers/trovecategories.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/trovecategories.py b/Allura/allura/controllers/trovecategories.py
index 959713d..c208e2f 100644
--- a/Allura/allura/controllers/trovecategories.py
+++ b/Allura/allura/controllers/trovecategories.py
@@ -14,10 +14,12 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+from collections import OrderedDict
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 pylons import app_globals as g
@@ -77,6 +79,29 @@ class TroveCategoryController(BaseController):
selected_cat=selected_cat,
hierarchy=hierarchy)
+ def generate_category(self, category):
+ if not category:
+ return ()
+
+ children = {
+ key: value
+ for (key, value) in
+ (self.generate_category(child) for child in category.subcategories)
+ }
+
+ return category.fullname, OrderedDict(sorted(children.iteritems()))
+
+ @without_trailing_slash
+ @expose('jinja:allura:templates/browse_trove_categories.html')
+ def browse(self):
+ parent_categories = M.TroveCategory.query.find(dict(trove_parent_id=0)).all()
+ tree = {
+ key: value
+ for (key, value) in
+ (self.generate_category(child) for child in parent_categories)
+ }
+ return dict(tree=OrderedDict(sorted(tree.iteritems())))
+
@expose()
@require_post()
@validate(F.add_category_form, error_handler=index)
http://git-wip-us.apache.org/repos/asf/allura/blob/326ba276/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 07b27a5..6a1287b 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+from collections import OrderedDict
import logging
from datetime import datetime
http://git-wip-us.apache.org/repos/asf/allura/blob/326ba276/Allura/allura/templates/browse_trove_categories.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/browse_trove_categories.html b/Allura/allura/templates/browse_trove_categories.html
new file mode 100644
index 0000000..9e2ab07
--- /dev/null
+++ b/Allura/allura/templates/browse_trove_categories.html
@@ -0,0 +1,36 @@
+{#-
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-#}
+{% set hide_left_bar = True %}
+{% extends g.theme.master %}
+
+{% block title %}Trove Categories List{% endblock %}
+
+{% block content %}
+ <h3><a href="/categories">(back)</a></h3>
+ <h3>Trove Categories</h3>
+ <ul>
+ {% for key, value in tree.iteritems() recursive %}
+ <li>{{ key }}</li>
+ {% if value %}
+ <ul>{{ loop(value.iteritems()) }}</ul>
+ {% endif %}
+ {% endfor %}
+ </ul>
+ <h3><a href="/categories">(back)</a></h3>
+{% endblock content %}
http://git-wip-us.apache.org/repos/asf/allura/blob/326ba276/Allura/allura/templates/trovecategories.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/trovecategories.html b/Allura/allura/templates/trovecategories.html
index f0267c7..91bbd9e 100644
--- a/Allura/allura/templates/trovecategories.html
+++ b/Allura/allura/templates/trovecategories.html
@@ -39,6 +39,7 @@
{% else %}
<h2>
List of all top-level categories
+ <a href="/categories/browse">(browse all categories)</a>
</h2>
{% endif %}
http://git-wip-us.apache.org/repos/asf/allura/blob/326ba276/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 459275c..3e0facc 100644
--- a/Allura/allura/tests/functional/test_trovecategory.py
+++ b/Allura/allura/tests/functional/test_trovecategory.py
@@ -14,18 +14,19 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+from collections import OrderedDict
import mock
from tg import config
from nose.tools import assert_equals, assert_true
from ming.orm import session
-from bson.objectid import ObjectId
from allura import model as M
from allura.lib import helpers as h
from allura.tests import TestController
from alluratest.controller import setup_trove_categories
+from allura.tests import decorators as td
class TestTroveCategory(TestController):
@@ -80,3 +81,36 @@ class TestTroveCategory(TestController):
with h.push_config(config, **cfg):
check_access(username='test-user', status=403)
check_access(username='root', status=200)
+
+class TestTroveCategoryController(TestController):
+ @td.with_tool('test2', 'admin_main', 'admin')
+ def test_trove_hierarchy(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)
+
+ session(M.TroveCategory).flush()
+
+ r = self.app.get('/categories/browse')
+ tree = r.controller_output['tree']
+
+ expected_data = OrderedDict(
+ [('Root', OrderedDict(
+ [('CategoryA', OrderedDict([
+ ('ChildA', OrderedDict()),
+ ('ChildB', OrderedDict())
+ ])),
+ ('CategoryB', OrderedDict())
+ ])
+ )]
+ )
+ assert tree == expected_data
+
+ @td.with_tool('test2', 'admin_main', 'admin')
+ def test_trove_empty_hierarchy(self):
+ r = self.app.get('/categories/browse')
+ tree = r.controller_output['tree']
+ assert tree == OrderedDict()
+