0001-myspace-upgrade-sort-and-remove-dedicated-display-fo.patch
auquotidien/modules/myspace.py | ||
---|---|---|
50 | 50 |
invoices = [] |
51 | 51 |
invoices.extend(Invoice.get_with_indexed_value( |
52 | 52 |
str('user_id'), str(user.id))) |
53 | ||
54 |
def cmp_invoice(a, b): |
|
55 |
t = cmp(a.regie_id, b.regie_id) |
|
56 |
if t != 0: |
|
57 |
return t |
|
58 |
return -cmp(a.date, b.date) |
|
59 | ||
60 |
invoices.sort(cmp_invoice) |
|
53 |
invoices.sort(key=lambda x: (x.regie_id, -x.date)) |
|
61 | 54 | |
62 | 55 |
last_regie_id = None |
63 | 56 |
unpaid = False |
... | ... | |
127 | 120 |
for formdef in formdefs: |
128 | 121 |
user_forms.extend(formdef.data_class().get_with_indexed_value( |
129 | 122 |
'user_id', self.user.id)) |
130 |
user_forms.sort(lambda x,y: cmp(x.receipt_time, y.receipt_time))
|
|
123 |
user_forms.sort(key=lambda x: x.receipt_time)
|
|
131 | 124 | |
132 | 125 |
get_response().set_content_type('application/json') |
133 | 126 | |
... | ... | |
193 | 186 |
for formdef in formdefs: |
194 | 187 |
user_forms.extend(formdef.data_class().get_with_indexed_value( |
195 | 188 |
'user_id', user.id)) |
196 |
user_forms.sort(lambda x,y: cmp(x.receipt_time, y.receipt_time))
|
|
189 |
user_forms.sort(key=lambda x: x.receipt_time)
|
|
197 | 190 | |
198 | 191 |
profile_links = [] |
199 | 192 |
if not get_cfg('sp', {}).get('idp-manage-user-attributes', False): |
auquotidien/modules/root.py | ||
---|---|---|
19 | 19 |
import wcs |
20 | 20 |
import wcs.root |
21 | 21 |
from wcs import qommon |
22 |
from wcs.forms.root import RootDirectory as FormsRootDirectory |
|
22 | 23 |
from wcs.qommon import get_cfg, get_logger |
23 | 24 |
from wcs.qommon import template |
24 | 25 |
from wcs.qommon import errors |
... | ... | |
70 | 71 |
Category.TEXT_ATTRIBUTES = ['name', 'url_name', 'description', 'homepage_position'] |
71 | 72 |
Category.INT_ATTRIBUTES = ['position', 'limit'] |
72 | 73 | |
73 | ||
74 |
class FormsRootDirectory(wcs.forms.root.RootDirectory): |
|
75 | ||
76 |
def _q_index(self, *args): |
|
77 |
get_response().filter['is_index'] = True |
|
78 |
return wcs.forms.root.RootDirectory._q_index(self, *args) |
|
79 | ||
80 |
def user_forms(self, user_forms): |
|
81 |
r = TemplateIO(html=True) |
|
82 |
base_url = get_publisher().get_root_url() |
|
83 | ||
84 |
draft = [x for x in user_forms if x.is_draft() and not x.formdef.is_disabled()] |
|
85 |
if draft: |
|
86 |
r += htmltext('<h4 id="drafts">%s</h4>') % _('My Current Drafts') |
|
87 |
r += htmltext('<ul>') |
|
88 |
for f in draft: |
|
89 |
if f.formdef.category: |
|
90 |
category_url = '%s' % f.formdef.category.url_name |
|
91 |
else: |
|
92 |
category_url = '.' |
|
93 |
r += htmltext('<li><a href="%s%s/%s/%s">%s</a>, %s') % (base_url, |
|
94 |
category_url, |
|
95 |
f.formdef.url_name, f.id, f.formdef.name, |
|
96 |
misc.localstrftime(f.receipt_time)) |
|
97 |
r += htmltext(' (<a href="%s%s/%s/%s?remove-draft">%s</a>)') % (base_url, |
|
98 |
category_url, |
|
99 |
f.formdef.url_name, f.id, _('delete')) |
|
100 |
r += htmltext('</li>') |
|
101 |
r += htmltext('</ul>') |
|
102 | ||
103 |
forms_by_status_name = {} |
|
104 |
for f in user_forms: |
|
105 |
if f.is_draft(): |
|
106 |
continue |
|
107 |
status = f.get_visible_status() |
|
108 |
if status: |
|
109 |
status_name = status.name |
|
110 |
else: |
|
111 |
status_name = None |
|
112 |
if status_name in forms_by_status_name: |
|
113 |
forms_by_status_name[status_name].append(f) |
|
114 |
else: |
|
115 |
forms_by_status_name[status_name] = [f] |
|
116 |
for status_name in forms_by_status_name: |
|
117 |
if status_name: |
|
118 |
r += htmltext('<h4>%s</h4>') % _('My forms with status "%s"') % status_name |
|
119 |
else: |
|
120 |
r += htmltext('<h4>%s</h4>') % _('My forms with an unknown status') % status_name |
|
121 |
r += htmltext('<ul>') |
|
122 |
forms_by_status_name[status_name].sort(lambda x,y: cmp(x.receipt_time, y.receipt_time)) |
|
123 |
for f in forms_by_status_name[status_name]: |
|
124 |
if f.formdef.category_id: |
|
125 |
category_url = f.formdef.category.url_name |
|
126 |
else: |
|
127 |
category_url = '.' |
|
128 |
r += htmltext('<li><a href="%s%s/%s/%s/">%s</a>, %s</li>') % ( |
|
129 |
base_url, |
|
130 |
category_url, |
|
131 |
f.formdef.url_name, f.id, f.formdef.name, |
|
132 |
misc.localstrftime(f.receipt_time)) |
|
133 |
r += htmltext('</ul>') |
|
134 |
return r.getvalue() |
|
135 | ||
136 | ||
137 | 74 |
OldRegisterDirectory = wcs.root.RegisterDirectory |
138 | 75 | |
139 | 76 |
class AlternateRegisterDirectory(OldRegisterDirectory): |
tests/test_user_pages.py | ||
---|---|---|
94 | 94 | |
95 | 95 |
app = login(get_app(pub), username='user', password='user') |
96 | 96 |
resp = app.get('/myspace/') |
97 |
assert 'Status1' in resp |
|
98 |
assert '<a href="/cat/test/%s/"' % formdata.id in resp |
|
99 |
assert 'Draft' in resp |
|
100 |
assert '<a href="/cat/test/%s"' % draft.id in resp |
|
101 |
resp = app.get('/cat/test/%s' % formdata.id) |
|
97 |
assert formdata.id != draft.id |
|
98 |
assert '<a href="test/%s/"' % formdata.id in resp |
|
99 |
assert '<a href="test/%s"' % draft.id in resp |
|
100 |
resp = app.get('/test/%s' % formdata.id) |
|
102 | 101 |
resp.status_int = 200 |
103 |
resp = app.get('/cat/test/%s' % draft.id, status=302) |
|
102 |
resp = app.get('/test/%s' % draft.id, status=302) |
|
103 |
resp = resp.follow(status=302) |
|
104 |
resp.location.startswith('http://example.net/test/?mt=') |
|
104 | 105 |
resp = resp.follow(status=302) |
105 | 106 |
resp.location.startswith('http://example.net/cat/test/?mt=') |
106 | 107 |
resp = resp.follow(status=200) |
... | ... | |
109 | 110 |
formdef.disabled = True |
110 | 111 |
formdef.store() |
111 | 112 |
resp = app.get('/myspace/') |
112 |
assert 'Status1' in resp |
|
113 |
assert '<a href="/cat/test/%s/"' % formdata.id in resp |
|
114 |
assert not 'Draft' in resp |
|
115 |
assert not '<a href="/cat/test/%s"' % draft.id in resp |
|
113 |
assert formdata.id != draft.id |
|
114 |
assert '<a href="test/%s/"' % formdata.id in resp |
|
115 |
assert not '<a href="test/%s"' % draft.id in resp |
|
116 | 116 |
resp = app.get('/cat/test/%s' % formdata.id) |
117 | 117 |
resp.status_int = 200 |
118 | 118 |
resp = app.get('/cat/test/%s' % draft.id, status=302) |
119 | 119 |
resp = resp.follow(status=302) |
120 |
resp.location.startswith('http://example.net/cat/test/?mt=')
|
|
120 |
resp.location.startswith('http://example.net/test/?mt=') |
|
121 | 121 |
resp = resp.follow(status=403) |
122 | 122 | |
123 | 123 |
def test_form_category_redirection(): |
124 |
- |