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
1=== modified file 'sloecode/config/environment.py'
2--- sloecode/config/environment.py 2011-06-04 06:41:58 +0000
3+++ sloecode/config/environment.py 2011-10-01 15:18:25 +0000
4@@ -11,10 +11,10 @@
5 from sloecode.bzr.factory import BazaarRepositoryFactory
6 import sloecode.lib.app_globals as app_globals
7 import sloecode.lib.helpers
8+from sloecode.lib.filters import FILTERS
9 from sloecode.config.routing import make_map
10 from sloecode.model import init_model
11
12-
13 def load_environment(global_conf, app_conf):
14 """Configure the Pylons environment via the ``pylons.config``
15 object
16@@ -39,13 +39,17 @@
17 pylons.cache._push_object(config['pylons.app_globals'].cache)
18
19 # Create the Jinja2 Environment
20- config['pylons.app_globals'].jinja2_env = Environment(
21+ jinja2_env = Environment(
22 extensions=['jinja2.ext.do'],
23 loader=ChoiceLoader(
24 [FileSystemLoader(path) for path in paths['templates']]))
25+ config['pylons.app_globals'].jinja2_env = jinja2_env
26 # Jinja2's unable to request c's attributes without strict_c
27 config['pylons.strict_tmpl_context'] = True
28
29+ # Register our custom filters.
30+ jinja2_env.filters.update(FILTERS)
31+
32 # Setup the SQLAlchemy database engine
33 # do this by creating the engine url from components:
34 db_config = RawConfigParser()
35
36=== added file 'sloecode/lib/filters.py'
37--- sloecode/lib/filters.py 1970-01-01 00:00:00 +0000
38+++ sloecode/lib/filters.py 2011-10-01 15:18:25 +0000
39@@ -0,0 +1,19 @@
40+"""Custom filters for Jinja2 templates
41+"""
42+
43+
44+from operator import attrgetter, methodcaller
45+
46+
47+def do_attrsort(objs, attr):
48+ return sorted(objs, key=attrgetter(attr))
49+
50+def do_methodsort(objs, method):
51+ return sorted(objs, key=methodcaller(method))
52+
53+
54+FILTERS = {
55+ 'attrsort': do_attrsort,
56+ 'methodsort': do_methodsort,
57+}
58+
59
60=== modified file 'sloecode/templates/admin/person-list.html'
61--- sloecode/templates/admin/person-list.html 2011-06-22 06:54:54 +0000
62+++ sloecode/templates/admin/person-list.html 2011-10-01 15:18:25 +0000
63@@ -26,7 +26,7 @@
64 <th>Actions</th>
65 </tr>
66 {% set row_class = cycler('odd', 'even') %}
67- {% for person in people.items %}
68+ {% for person in people.items|attrsort('login') %}
69 <tr class="{{row_class.next()}}">
70 <td>{{h.link_to(person.login|e,
71 h.url(controller='person',
72
73=== modified file 'sloecode/templates/admin/project-list.html'
74--- sloecode/templates/admin/project-list.html 2011-06-22 06:54:54 +0000
75+++ sloecode/templates/admin/project-list.html 2011-10-01 15:18:25 +0000
76@@ -24,7 +24,7 @@
77 <th>Actions</th>
78 </tr>
79 {% set row_class = cycler('odd', 'even') %}
80- {% for project in projects.items %}
81+ {% for project in projects.items|attrsort('name') %}
82 <tr class="{{row_class.next()}}">
83 <td>{{h.link_to(project.name|e,
84 h.url(controller='project', project_name=project.name),
85
86=== modified file 'sloecode/templates/macros/nav.html'
87--- sloecode/templates/macros/nav.html 2011-07-02 22:51:24 +0000
88+++ sloecode/templates/macros/nav.html 2011-10-01 15:18:25 +0000
89@@ -41,7 +41,7 @@
90 <div class="yui3-menu-content">
91 <ul>
92 {# List of projects that this user is in #}
93- {% for membership in user_details.projects %}
94+ {% for membership in user_details.projects|attrsort('project.name') %}
95 <li class="yui3-menuitem">
96 {{ h.link_to(membership.project.name,
97 h.url(controller='project',
98
99=== modified file 'sloecode/templates/person-details.html'
100--- sloecode/templates/person-details.html 2011-08-15 00:56:40 +0000
101+++ sloecode/templates/person-details.html 2011-10-01 15:18:25 +0000
102@@ -51,7 +51,7 @@
103
104 <h2>Personal Repository:</h2>
105 {{ h.help_link("What's a Personal Repository?", '/what-is/repo-type')}}
106- {% set branches = repo.get_branches() %}
107+ {% set branches = repo.get_branches()|attrsort('get_name') %}
108 {% if is_me %}
109 <p>Your personal repository has {{branches|length}} branches.</p>
110 {% else %}
111
112=== modified file 'sloecode/templates/person-manage-keys.html'
113--- sloecode/templates/person-manage-keys.html 2011-06-22 06:54:54 +0000
114+++ sloecode/templates/person-manage-keys.html 2011-10-01 15:18:25 +0000
115@@ -48,7 +48,7 @@
116 {% if person.auth_keys|length %}
117 <p>You have the following SSH Keys stored in the sloecode system. You may
118 remove existing keys, or add new ones above.</p>
119- {% for key in person.auth_keys %}
120+ {% for key in person.auth_keys|attrsort('key_name') %}
121 <div class="box-header">
122 <span class="label">Name: </span> {{key.key_name}}
123 </div>
124
125=== modified file 'sloecode/templates/project-details.html'
126--- sloecode/templates/project-details.html 2011-08-15 01:43:23 +0000
127+++ sloecode/templates/project-details.html 2011-10-01 15:18:25 +0000
128@@ -34,7 +34,7 @@
129 <th></th><th>Branch Name</th><th>Revisions</th><th>Actions</th>
130 </tr>
131
132- {% for branch in branches %}
133+ {% for branch in branches|methodsort('get_name') %}
134 <tr>
135 <td>
136 {{h.image(h.url('/bzr_icon.png'), 'Bazaar Branch')}}
137@@ -69,7 +69,7 @@
138 <div class="details_list">
139 <dl>
140 <dt>Users in this Project</dt>
141- {% for member in project.users %}
142+ {% for member in project.users|attrsort('person.name') %}
143 <dd class="user">
144 {{ h.link_to(member.person.name,
145 h.url(controller="person", person_name=member.person.login),
146
147=== modified file 'sloecode/templates/project-manage-users.html'
148--- sloecode/templates/project-manage-users.html 2011-06-22 06:54:54 +0000
149+++ sloecode/templates/project-manage-users.html 2011-10-01 15:18:25 +0000
150@@ -17,7 +17,7 @@
151 <th>Add/Remove User</th>
152 <th>Change Role</th>
153 </tr>
154- {% for person in all_people %}
155+ {% for person in all_people|attrsort('name') %}
156 <tr>
157 <td>
158 {{ h.checkbox('usernames', value=person.login, id=person.login,

Subscribers

People subscribed via source and target branches