Merge lp:~benoit.pierre/sloecode/sorted-lists into lp:sloecode

Proposed by Benoit Pierre
Status: Merged
Merged at revision: 133
Proposed branch: lp:~benoit.pierre/sloecode/sorted-lists
Merge into: lp:sloecode
Diff against target: 158 lines (+33/-10)
9 files modified
sloecode/config/environment.py (+6/-2)
sloecode/lib/filters.py (+19/-0)
sloecode/templates/admin/person-list.html (+1/-1)
sloecode/templates/admin/project-list.html (+1/-1)
sloecode/templates/macros/nav.html (+1/-1)
sloecode/templates/person-details.html (+1/-1)
sloecode/templates/person-manage-keys.html (+1/-1)
sloecode/templates/project-details.html (+2/-2)
sloecode/templates/project-manage-users.html (+1/-1)
To merge this branch: bzr merge lp:~benoit.pierre/sloecode/sorted-lists
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
Review via email: mp+77792@code.launchpad.net

Description of the change

- add support for custom Jinja2 filters
- add 2 sort filters
- use them to sort web UI lists when applicable

To post a comment you must log in.
Revision history for this message
Benoit Pierre (benoit.pierre) wrote :

N.B.:

- sorting by method return value uses operator.methodcaller, which is only available starting with Python 2.6
- sorting using a dotted attribute (using operator.attrgetter), is only available starting with Python 2.6 too

I know Bazaar still support Python 2.4, I don't know about other components. The filters implementation will have to be changed if Python 2.4 is too be supported for sloecode.

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Looks great, thanks. If we wanted to support python < 2.6 we'd have problems in other parts of the codebase as well (although off the top of my head I can't remember where, exactly). We made a deliberate decision not to support older distributions.. what can I say, we were lazy!

Thanks for your help - I'm merging this now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'sloecode/config/environment.py'
--- sloecode/config/environment.py 2011-06-04 06:41:58 +0000
+++ sloecode/config/environment.py 2011-10-01 15:18:25 +0000
@@ -11,10 +11,10 @@
11from sloecode.bzr.factory import BazaarRepositoryFactory11from sloecode.bzr.factory import BazaarRepositoryFactory
12import sloecode.lib.app_globals as app_globals12import sloecode.lib.app_globals as app_globals
13import sloecode.lib.helpers13import sloecode.lib.helpers
14from sloecode.lib.filters import FILTERS
14from sloecode.config.routing import make_map15from sloecode.config.routing import make_map
15from sloecode.model import init_model16from sloecode.model import init_model
1617
17
18def load_environment(global_conf, app_conf):18def load_environment(global_conf, app_conf):
19 """Configure the Pylons environment via the ``pylons.config``19 """Configure the Pylons environment via the ``pylons.config``
20 object20 object
@@ -39,13 +39,17 @@
39 pylons.cache._push_object(config['pylons.app_globals'].cache)39 pylons.cache._push_object(config['pylons.app_globals'].cache)
4040
41 # Create the Jinja2 Environment41 # Create the Jinja2 Environment
42 config['pylons.app_globals'].jinja2_env = Environment(42 jinja2_env = Environment(
43 extensions=['jinja2.ext.do'],43 extensions=['jinja2.ext.do'],
44 loader=ChoiceLoader(44 loader=ChoiceLoader(
45 [FileSystemLoader(path) for path in paths['templates']]))45 [FileSystemLoader(path) for path in paths['templates']]))
46 config['pylons.app_globals'].jinja2_env = jinja2_env
46 # Jinja2's unable to request c's attributes without strict_c47 # Jinja2's unable to request c's attributes without strict_c
47 config['pylons.strict_tmpl_context'] = True48 config['pylons.strict_tmpl_context'] = True
4849
50 # Register our custom filters.
51 jinja2_env.filters.update(FILTERS)
52
49 # Setup the SQLAlchemy database engine53 # Setup the SQLAlchemy database engine
50 # do this by creating the engine url from components:54 # do this by creating the engine url from components:
51 db_config = RawConfigParser()55 db_config = RawConfigParser()
5256
=== added file 'sloecode/lib/filters.py'
--- sloecode/lib/filters.py 1970-01-01 00:00:00 +0000
+++ sloecode/lib/filters.py 2011-10-01 15:18:25 +0000
@@ -0,0 +1,19 @@
1"""Custom filters for Jinja2 templates
2"""
3
4
5from operator import attrgetter, methodcaller
6
7
8def do_attrsort(objs, attr):
9 return sorted(objs, key=attrgetter(attr))
10
11def do_methodsort(objs, method):
12 return sorted(objs, key=methodcaller(method))
13
14
15FILTERS = {
16 'attrsort': do_attrsort,
17 'methodsort': do_methodsort,
18}
19
020
=== modified file 'sloecode/templates/admin/person-list.html'
--- sloecode/templates/admin/person-list.html 2011-06-22 06:54:54 +0000
+++ sloecode/templates/admin/person-list.html 2011-10-01 15:18:25 +0000
@@ -26,7 +26,7 @@
26 <th>Actions</th>26 <th>Actions</th>
27 </tr>27 </tr>
28 {% set row_class = cycler('odd', 'even') %}28 {% set row_class = cycler('odd', 'even') %}
29 {% for person in people.items %}29 {% for person in people.items|attrsort('login') %}
30 <tr class="{{row_class.next()}}">30 <tr class="{{row_class.next()}}">
31 <td>{{h.link_to(person.login|e,31 <td>{{h.link_to(person.login|e,
32 h.url(controller='person',32 h.url(controller='person',
3333
=== modified file 'sloecode/templates/admin/project-list.html'
--- sloecode/templates/admin/project-list.html 2011-06-22 06:54:54 +0000
+++ sloecode/templates/admin/project-list.html 2011-10-01 15:18:25 +0000
@@ -24,7 +24,7 @@
24 <th>Actions</th>24 <th>Actions</th>
25 </tr>25 </tr>
26 {% set row_class = cycler('odd', 'even') %}26 {% set row_class = cycler('odd', 'even') %}
27 {% for project in projects.items %}27 {% for project in projects.items|attrsort('name') %}
28 <tr class="{{row_class.next()}}">28 <tr class="{{row_class.next()}}">
29 <td>{{h.link_to(project.name|e,29 <td>{{h.link_to(project.name|e,
30 h.url(controller='project', project_name=project.name),30 h.url(controller='project', project_name=project.name),
3131
=== modified file 'sloecode/templates/macros/nav.html'
--- sloecode/templates/macros/nav.html 2011-07-02 22:51:24 +0000
+++ sloecode/templates/macros/nav.html 2011-10-01 15:18:25 +0000
@@ -41,7 +41,7 @@
41 <div class="yui3-menu-content">41 <div class="yui3-menu-content">
42 <ul>42 <ul>
43 {# List of projects that this user is in #}43 {# List of projects that this user is in #}
44 {% for membership in user_details.projects %}44 {% for membership in user_details.projects|attrsort('project.name') %}
45 <li class="yui3-menuitem">45 <li class="yui3-menuitem">
46 {{ h.link_to(membership.project.name,46 {{ h.link_to(membership.project.name,
47 h.url(controller='project',47 h.url(controller='project',
4848
=== modified file 'sloecode/templates/person-details.html'
--- sloecode/templates/person-details.html 2011-08-15 00:56:40 +0000
+++ sloecode/templates/person-details.html 2011-10-01 15:18:25 +0000
@@ -51,7 +51,7 @@
5151
52 <h2>Personal Repository:</h2>52 <h2>Personal Repository:</h2>
53 {{ h.help_link("What's a Personal Repository?", '/what-is/repo-type')}}53 {{ h.help_link("What's a Personal Repository?", '/what-is/repo-type')}}
54 {% set branches = repo.get_branches() %}54 {% set branches = repo.get_branches()|attrsort('get_name') %}
55 {% if is_me %}55 {% if is_me %}
56 <p>Your personal repository has {{branches|length}} branches.</p>56 <p>Your personal repository has {{branches|length}} branches.</p>
57 {% else %}57 {% else %}
5858
=== modified file 'sloecode/templates/person-manage-keys.html'
--- sloecode/templates/person-manage-keys.html 2011-06-22 06:54:54 +0000
+++ sloecode/templates/person-manage-keys.html 2011-10-01 15:18:25 +0000
@@ -48,7 +48,7 @@
48 {% if person.auth_keys|length %}48 {% if person.auth_keys|length %}
49 <p>You have the following SSH Keys stored in the sloecode system. You may49 <p>You have the following SSH Keys stored in the sloecode system. You may
50 remove existing keys, or add new ones above.</p>50 remove existing keys, or add new ones above.</p>
51 {% for key in person.auth_keys %}51 {% for key in person.auth_keys|attrsort('key_name') %}
52 <div class="box-header">52 <div class="box-header">
53 <span class="label">Name: </span> {{key.key_name}}53 <span class="label">Name: </span> {{key.key_name}}
54 </div>54 </div>
5555
=== modified file 'sloecode/templates/project-details.html'
--- sloecode/templates/project-details.html 2011-08-15 01:43:23 +0000
+++ sloecode/templates/project-details.html 2011-10-01 15:18:25 +0000
@@ -34,7 +34,7 @@
34 <th></th><th>Branch Name</th><th>Revisions</th><th>Actions</th>34 <th></th><th>Branch Name</th><th>Revisions</th><th>Actions</th>
35 </tr>35 </tr>
3636
37 {% for branch in branches %}37 {% for branch in branches|methodsort('get_name') %}
38 <tr>38 <tr>
39 <td>39 <td>
40 {{h.image(h.url('/bzr_icon.png'), 'Bazaar Branch')}}40 {{h.image(h.url('/bzr_icon.png'), 'Bazaar Branch')}}
@@ -69,7 +69,7 @@
69 <div class="details_list">69 <div class="details_list">
70 <dl>70 <dl>
71 <dt>Users in this Project</dt>71 <dt>Users in this Project</dt>
72 {% for member in project.users %}72 {% for member in project.users|attrsort('person.name') %}
73 <dd class="user">73 <dd class="user">
74 {{ h.link_to(member.person.name,74 {{ h.link_to(member.person.name,
75 h.url(controller="person", person_name=member.person.login),75 h.url(controller="person", person_name=member.person.login),
7676
=== modified file 'sloecode/templates/project-manage-users.html'
--- sloecode/templates/project-manage-users.html 2011-06-22 06:54:54 +0000
+++ sloecode/templates/project-manage-users.html 2011-10-01 15:18:25 +0000
@@ -17,7 +17,7 @@
17 <th>Add/Remove User</th>17 <th>Add/Remove User</th>
18 <th>Change Role</th>18 <th>Change Role</th>
19 </tr>19 </tr>
20 {% for person in all_people %}20 {% for person in all_people|attrsort('name') %}
21 <tr>21 <tr>
22 <td>22 <td>
23 {{ h.checkbox('usernames', value=person.login, id=person.login,23 {{ h.checkbox('usernames', value=person.login, id=person.login,

Subscribers

People subscribed via source and target branches