You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/04/12 23:16:36 UTC

[6/6] git commit: [#5481] Refactored and improved [[members]] macro and replaced [[project_admins]] with it in the default wiki

[#5481] Refactored and improved [[members]] macro and replaced [[project_admins]] with it in the default wiki

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


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

Branch: refs/heads/cj/5481
Commit: 20b4e57fd1bc3d1d7f5a3721e23563e034d3be20
Parents: 5fe1e8c
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Fri Apr 12 21:00:05 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Fri Apr 12 21:00:05 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/macro.py          |   42 +++++++++++++++++------------
 Allura/allura/lib/plugin.py         |    2 +-
 Allura/allura/tests/test_globals.py |   24 +++++++++++++++--
 ForgeWiki/forgewiki/wiki_main.py    |    3 +-
 4 files changed, 48 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/20b4e57f/Allura/allura/lib/macro.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index 0f2c65f..747ce58 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -4,10 +4,12 @@ import shlex
 import string
 import logging
 import traceback
+from operator import attrgetter
 
 import pymongo
 from pylons import tmpl_context as c, app_globals as g
 from pylons import request
+from paste.deploy.converters import asint
 from urlparse import urljoin
 
 from . import helpers as h
@@ -336,21 +338,27 @@ def img(src=None, **kw):
 template_project_admins = string.Template('<a href="$url">$name</a><br/>')
 @macro()
 def project_admins():
-    from allura import model as M
-    output = ''
-    admin_role = M.ProjectRole.query.get(project_id=c.project._id,name='Admin')
-    if admin_role:
-        output = ''.join(
-            template_project_admins.substitute(dict(
-                url=user_role.user.url(),
-                name=user_role.user.display_name))
-            for user_role in admin_role.users_with_role())
-    return u'<h6>Project Admins:</h6><div class="grid-10">{}</div><div style="clear: both;"></div>'.format(output)
-
-template_members = string.Template('<a href="$url">Members</a><br/>')
-@macro()
-def members():
+    admins = c.project.users_with_role('Admin')
     output = ''.join(
-            template_members.substitute(dict(
-                url=urljoin(c.project.url(), '_members'),)))
-    return u'<p>{}</p>'.format(output)
+        template_project_admins.substitute(dict(
+            url=user.url(),
+            name=user.display_name))
+        for user in admins)
+    return u'<h6>Project Admins:</h6><div class="grid-10" style="margin-left: 2em">{}</div><div style="clear: both;"></div>'.format(output)
+
+template_members = string.Template('<a href="$url">$name</a>$admin<br/>')
+@macro()
+def members(limit=20):
+    limit = asint(limit)
+    admins = set(c.project.users_with_role('Admin'))
+    members = sorted(c.project.users(), key=attrgetter('display_name'))
+    output = '<div style="margin-left: 0.5em; margin-bottom: 0.5em;">%s</div>' % ''.join(
+        template_members.substitute(dict(
+            url=user.url(),
+            name=user.display_name,
+            admin=' (admin)' if user in admins else '',
+            ))
+        for user in members[:limit])
+    if len(members) > limit:
+        output = output + '<a href="%s_members">All Members</a>' % c.project.url()
+    return u'<h6>Project Members:</h6><div style="margin-left: 1.5em;">{}</div><div style="clear: both;"></div>'.format(output)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/20b4e57f/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 77207a2..87e1e63 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -521,7 +521,7 @@ class ProjectRegistrationProvider(object):
                     if tool == 'wiki':
                         from forgewiki import model as WM
                         text = tool_config.get('home_text',
-                            '[[project_admins]]\n[[members]]\n[[download_button]]')
+                            '[[members limit=20]]\n[[download_button]]')
                         WM.Page.query.get(app_config_id=app.config._id).text = text
 
         if 'tool_order' in project_template:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/20b4e57f/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 44c6850..1750bdc 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -149,16 +149,34 @@ def test_macros():
     r = g.markdown_wiki.convert('[[neighborhood_blog_posts]]')
     assert 'test content' in r
 
+@with_setup(teardown=setUp) # reset everything we changed
 def test_macro_members():
-    r = g.markdown_wiki.convert('[[members]]')
-    assert_equal(r, u'<div class="markdown_content"><p><a href="/p/test/_members">Members</a><br /></p>\n</div>')
+    p_nbhd = M.Neighborhood.query.get(name='Projects')
+    p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
+    p_test.add_user(M.User.by_username('test-user'), ['Developer'])
+    p_test.add_user(M.User.by_username('test-user-0'), ['Member'])
+    ThreadLocalORMSession.flush_all()
+    r = g.markdown_wiki.convert('[[members limit=2]]')
+    assert_equal(r,
+        '<div class="markdown_content">'
+            '<h6>Project Members:</h6>'
+            '<div style="margin-left: 1.5em;">'
+                '<div style="margin-left: 0.5em; margin-bottom: 0.5em;">'
+                    '<a href="/u/test-admin/">Test Admin</a> (admin)<br />'
+                    '<a href="/u/test-user/">Test User</a><br />'
+                '</div>'
+                '<a href="/p/test/_members">All Members</a>'
+            '</div><div style="clear: both;"></div>\n'
+        '</div>')
 
+@with_setup(teardown=setUp) # reset everything we changed
 def test_macro_project_admins():
     user = M.User.by_username('test-admin')
     user.display_name = u'Test Ådmin'
     r = g.markdown_wiki.convert('[[project_admins]]')
-    assert_equal(r, u'<div class="markdown_content"><h6>Project Admins:</h6><div class="grid-10"><a href="/u/test-admin/">Test Ådmin</a><br /></div><div style="clear: both;"></div>\n</div>')
+    assert_equal(r, u'<div class="markdown_content"><h6>Project Admins:</h6><div class="grid-10" style="margin-left: 2em;"><a href="/u/test-admin/">Test Ådmin</a><br /></div><div style="clear: both;"></div>\n</div>')
 
+@with_setup(teardown=setUp) # reset everything we changed
 def test_macro_project_admins_one_br():
     p_nbhd = M.Neighborhood.query.get(name='Projects')
     p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/20b4e57f/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index ce253fb..b62762d 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -246,8 +246,7 @@ This is the default page, edit it as you see fit. To add a new page simply refer
 
 The wiki uses [Markdown](%s) syntax.
 
-[[project_admins]]
-[[members]]
+[[members limit=20]]
 [[download_button]]
 """ % url
                 p.commit()