incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [3/16] git commit: [#4990] ticket:181 fixed count labels error, added tests
Date Tue, 16 Oct 2012 14:27:08 GMT
[#4990] ticket:181 fixed count labels error, added tests


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

Branch: refs/heads/cj/5094
Commit: 9a021b4959e88ba494127bc738e0f3bba7a7f02e
Parents: ba8af5c
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Mon Oct 1 01:28:00 2012 +0400
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Mon Oct 15 21:32:47 2012 +0000

----------------------------------------------------------------------
 .../forgewiki/templates/wiki/browse_tags.html      |    2 +-
 ForgeWiki/forgewiki/tests/functional/test_root.py  |   22 +++++++++++++++
 ForgeWiki/forgewiki/wiki_main.py                   |   19 +++++++++----
 3 files changed, 36 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9a021b49/ForgeWiki/forgewiki/templates/wiki/browse_tags.html
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/templates/wiki/browse_tags.html b/ForgeWiki/forgewiki/templates/wiki/browse_tags.html
index 8f8c23a..76532f5 100644
--- a/ForgeWiki/forgewiki/templates/wiki/browse_tags.html
+++ b/ForgeWiki/forgewiki/templates/wiki/browse_tags.html
@@ -15,7 +15,7 @@
   </thead>
   <tbody>
     {% set i = 0 %}
-    {% for label in labels %}
+    {% for label in name_labels %}
       <tr class="{{i%2 and 'even' or ''}}">
         <td>{{label}}</td>
         <td>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9a021b49/ForgeWiki/forgewiki/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py
index fa11a89..3375b6d 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -248,6 +248,28 @@ class TestRootController(TestController):
                 'viewable_by-0.id':'all'})
         assert 'tést' in response
 
+    def test_page_label_count(self):
+        labels = "label"
+        for i in range(1, 100):
+            labels += ',label%s' % i
+        self.app.post(
+            '/wiki/tést/update',
+            params={
+                'title': 'tést',
+                'text': 'sometext',
+                'labels': labels,
+                'labels_old': labels,
+                'viewable_by-0.id': 'all'})
+        r = self.app.get('/wiki/browse_tags/')
+        assert 'results of 100 ' in r
+        assert '<div class="page_list">' in r
+        assert '(Page 1 of 4)' in r
+        assert '<td>label30</td>' in r
+        assert '<td>label1</td>' in r
+        r = self.app.get('/wiki/browse_tags/?page=3')
+        assert '<td>label77</td>' in r
+        assert '<td>label99</td>' in r
+
     def test_new_attachment(self):
         self.app.post(
             '/wiki/tést/update',

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9a021b49/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index ab56690..3528dd8 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -353,24 +353,31 @@ class RootController(BaseController, DispatchIndex):
     @expose('jinja:forgewiki:templates/wiki/browse_tags.html')
     @validate(dict(sort=validators.UnicodeString(if_empty='alpha'),
                    page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=None)))
-    def browse_tags(self, sort='alpha', page=0, limit=None):
+                   limit=validators.Int(if_empty=25)))
+    def browse_tags(self, sort='alpha', page=0, limit=None, **kw):
         'list of all labels in the wiki'
         c.page_list = W.page_list
         c.page_size = W.page_size
         limit, pagenum, start = g.handle_paging(limit, page, default=25)
         count = 0
         page_tags = {}
-        q = WM.Page.query.find(dict(app_config_id=c.app.config._id, deleted=False))
-        count = q.count()
-        q = q.skip(start).limit(int(limit))
+        q = WM.Page.query.find(dict(app_config_id=c.app.config._id,
+                                    deleted=False,
+                                    labels={'$ne': []}))
         for page in q:
             if page.labels:
                 for label in page.labels:
                     if label not in page_tags:
                         page_tags[label] = []
                     page_tags[label].append(page)
-        return dict(labels=page_tags, limit=limit, count=count, page=pagenum)
+        count = len(page_tags)
+        name_labels = list(page_tags)
+        name_labels.sort()
+        return dict(labels=page_tags,
+                    limit=limit,
+                    count=count,
+                    page=pagenum,
+                    name_labels=name_labels[start:start + limit])
 
     @with_trailing_slash
     @expose('jinja:allura:templates/markdown_syntax.html')


Mime
View raw message