0001-backoffice-make-global-listing-sortable-8542.patch
tests/test_sql.py | ||
---|---|---|
40 | 40 |
cur.close() |
41 | 41 | |
42 | 42 |
pub.cfg['postgresql'] = {'database': dbname, 'user': os.environ['USER']} |
43 |
pub.initialize_sql() |
|
43 | 44 | |
44 | 45 |
formdef = formdef.FormDef() |
45 | 46 |
formdef.name = 'tests' |
... | ... | |
54 | 55 |
] |
55 | 56 |
formdef.store() |
56 | 57 | |
57 |
pub.initialize_sql() |
|
58 | ||
59 | 58 |
conn.close() |
60 | 59 | |
61 | 60 | |
... | ... | |
1103 | 1102 | |
1104 | 1103 |
cur.execute('''SELECT id FROM wcs_all_forms WHERE last_update_time = '2015-01-04 00:00' ''') |
1105 | 1104 |
assert bool(cur.fetchone()[0] == formdata2.id) |
1105 | ||
1106 |
@postgresql |
|
1107 |
def test_view_formdef_name(): |
|
1108 |
drop_formdef_tables() |
|
1109 |
conn, cur = sql.get_connection_and_cursor() |
|
1110 | ||
1111 |
formdef1 = FormDef() |
|
1112 |
formdef1.name = 'test formdef name 1' |
|
1113 |
formdef1.fields = [] |
|
1114 |
formdef1.store() |
|
1115 | ||
1116 |
data_class = formdef1.data_class() |
|
1117 |
formdata1 = data_class() |
|
1118 |
formdata1.just_created() |
|
1119 |
formdata1.store() |
|
1120 | ||
1121 |
formdef2 = FormDef() |
|
1122 |
formdef2.name = 'test formdef name 2' |
|
1123 |
formdef2.fields = [] |
|
1124 |
formdef2.store() |
|
1125 | ||
1126 |
data_class = formdef2.data_class() |
|
1127 |
formdata2 = data_class() |
|
1128 |
formdata2.just_created() |
|
1129 |
formdata2.store() |
|
1130 | ||
1131 |
cur.execute('''SELECT COUNT(*) FROM wcs_all_forms''') |
|
1132 |
assert bool(cur.fetchone()[0] == 2) |
|
1133 | ||
1134 |
cur.execute('''SELECT formdef_id FROM wcs_all_forms WHERE formdef_name = 'test formdef name 1' ''') |
|
1135 |
assert bool(str(cur.fetchone()[0]) == str(formdef1.id)) |
|
1136 | ||
1137 |
cur.execute('''SELECT formdef_id FROM wcs_all_forms WHERE formdef_name = 'test formdef name 2' ''') |
|
1138 |
assert bool(str(cur.fetchone()[0]) == str(formdef2.id)) |
|
1139 | ||
1140 |
@postgresql |
|
1141 |
def test_view_user_name(): |
|
1142 |
drop_formdef_tables() |
|
1143 |
conn, cur = sql.get_connection_and_cursor() |
|
1144 | ||
1145 |
formdef1 = FormDef() |
|
1146 |
formdef1.name = 'test user name' |
|
1147 |
formdef1.fields = [] |
|
1148 |
formdef1.store() |
|
1149 | ||
1150 |
sql.SqlUser.wipe() |
|
1151 |
user = sql.SqlUser() |
|
1152 |
user.name = 'Foobar' |
|
1153 |
user.store() |
|
1154 | ||
1155 |
data_class = formdef1.data_class() |
|
1156 |
formdata1 = data_class() |
|
1157 |
formdata1.just_created() |
|
1158 |
formdata1.store() |
|
1159 | ||
1160 |
data_class = formdef1.data_class() |
|
1161 |
formdata2 = data_class() |
|
1162 |
formdata2.user_id = user.id |
|
1163 |
formdata2.just_created() |
|
1164 |
formdata2.store() |
|
1165 | ||
1166 |
cur.execute('''SELECT user_name FROM wcs_all_forms WHERE id = %s ''', (formdata1.id,)) |
|
1167 |
assert bool(cur.fetchone()[0] is None) |
|
1168 | ||
1169 |
cur.execute('''SELECT user_name FROM wcs_all_forms WHERE id = %s ''', (formdata2.id,)) |
|
1170 |
assert bool(cur.fetchone()[0] == user.name) |
wcs/backoffice/management.py | ||
---|---|---|
150 | 150 |
r += htmltext('</div>') |
151 | 151 |
return r.getvalue() |
152 | 152 | |
153 |
def get_global_listing_sidebar(self, limit=None, offset=None): |
|
153 |
def get_global_listing_sidebar(self, limit=None, offset=None, order_by=None):
|
|
154 | 154 |
get_response().add_javascript(['jquery.js']) |
155 | 155 |
DateWidget.prepare_javascript() |
156 | 156 |
form = Form(use_tokens=False, id='listing-settings') |
... | ... | |
165 | 165 |
limit = int(get_publisher().get_site_option('default-page-size') or 20) |
166 | 166 |
form.add_hidden('offset', offset) |
167 | 167 |
form.add_hidden('limit', limit) |
168 |
form.add_hidden('order_by', order_by) |
|
168 | 169 | |
169 | 170 |
form.add_submit('submit', _('Submit')) |
170 | 171 | |
... | ... | |
332 | 333 |
limit = int(get_request().form.get('limit', |
333 | 334 |
get_publisher().get_site_option('default-page-size') or 20)) |
334 | 335 |
offset = int(get_request().form.get('offset', 0)) |
336 |
order_by = get_request().form.get('order_by', 'receipt_time') |
|
335 | 337 | |
336 | 338 |
criterias = self.get_global_listing_criterias() |
337 | 339 |
total_count = sql.AnyFormData.count(criterias) |
338 | 340 |
formdatas = sql.AnyFormData.select(criterias, |
339 |
order_by='receipt_time', limit=limit, offset=offset)
|
|
341 |
order_by=order_by, limit=limit, offset=offset)
|
|
340 | 342 |
include_submission_channel = bool( |
341 | 343 |
get_publisher().get_site_option('welco_url', 'variables')) |
342 | 344 | |
... | ... | |
344 | 346 |
r += htmltext('<table id="listing" class="main">') |
345 | 347 |
r += htmltext('<thead>') |
346 | 348 |
if include_submission_channel: |
347 |
r += htmltext('<th>%s</th>') % _('Channel')
|
|
348 |
r += htmltext('<th>%s</th>') % _('Form')
|
|
349 |
r += htmltext('<th>%s</th>') % _('Created')
|
|
350 |
r += htmltext('<th>%s</th>') % _('Last Modified')
|
|
351 |
r += htmltext('<th>%s</th>') % _('User')
|
|
352 |
r += htmltext('<th>%s</th>') % _('Status')
|
|
349 |
r += htmltext('<th data-field-sort-key="submission_channel"><span>%s</span></th>') % _('Channel')
|
|
350 |
r += htmltext('<th data-field-sort-key="formdef_name"><span>%s</span></th>') % _('Form')
|
|
351 |
r += htmltext('<th data-field-sort-key="receipt_time"><span>%s</span></th>') % _('Created')
|
|
352 |
r += htmltext('<th data-field-sort-key="last_update_time"><span>%s</span></th>') % _('Last Modified')
|
|
353 |
r += htmltext('<th data-field-sort-key="user_name"><span>%s</span></th>') % _('User')
|
|
354 |
r += htmltext('<th class="nosort"><span>%s</span></th>') % _('Status')
|
|
353 | 355 |
r += htmltext('</thead>') |
354 | 356 |
r += htmltext('<tbody>') |
355 | 357 |
workflows = {} |
... | ... | |
399 | 401 |
get_response().filter = None |
400 | 402 |
return r.getvalue() |
401 | 403 | |
402 |
get_response().filter['sidebar'] = self.get_global_listing_sidebar() |
|
404 |
get_response().filter['sidebar'] = self.get_global_listing_sidebar( |
|
405 |
limit=limit, offset=offset, order_by=order_by) |
|
403 | 406 |
rt = TemplateIO(html=True) |
404 | 407 |
rt += htmltext('<h2>%s</h2>') % _('Global View') |
405 | 408 |
rt += get_session().display_message() |
wcs/qommon/static/css/dc2/admin.css | ||
---|---|---|
356 | 356 |
text-align: left; |
357 | 357 |
} |
358 | 358 | |
359 |
table.main th { |
|
360 |
cursor: pointer; |
|
361 |
} |
|
362 | ||
363 |
table.main th.nosort { |
|
364 |
cursor: inherit; |
|
365 |
} |
|
366 | ||
367 |
table.main th.headerSortUp span:after { |
|
368 |
content: " \23f7"; /* down pointing triangle */ |
|
369 |
} |
|
370 | ||
371 |
table.main th.headerSortDown span:after { |
|
372 |
content: " \23f6"; /* up pointing triangle */ |
|
373 |
} |
|
374 | ||
359 | 375 |
div.letters-nav { |
360 | 376 |
text-align: center; |
361 | 377 |
border: 1px solid #888; |
wcs/sql.py | ||
---|---|---|
598 | 598 |
(table_name, )*3), |
599 | 599 |
'last_update_time')) |
600 | 600 | |
601 |
view_fields.append(( |
|
602 |
cur.mogrify('(SELECT text %s)', (formdef.name,)), 'formdef_name')) |
|
603 | ||
604 |
view_fields.append(('''(SELECT name FROM users |
|
605 |
WHERE users.id = CAST(user_id AS INTEGER))''', 'user_name')) |
|
606 | ||
601 | 607 |
view_fields.append(('concerned_roles_array', 'concerned_roles_array')) |
602 | 608 |
view_fields.append(('actions_roles_array', 'actions_roles_array')) |
603 | 609 |
view_fields.append(('fts', 'fts')) |
... | ... | |
648 | 654 |
common_fields.append(('fts', 'fts')) |
649 | 655 |
common_fields.append(('is_at_endpoint', 'is_at_endpoint')) |
650 | 656 |
common_fields.append(('last_update_time', 'last_update_time')) |
657 |
common_fields.append(('formdef_name', 'formdef_name')) |
|
658 |
common_fields.append(('user_name', 'user_name')) |
|
651 | 659 | |
652 | 660 |
union = ' UNION '.join(['''SELECT %s FROM %s''' % ( |
653 | 661 |
', '.join([y[1] for y in common_fields]), x) for x in view_names]) |
... | ... | |
1686 | 1694 |
return result |
1687 | 1695 | |
1688 | 1696 | |
1689 |
SQL_LEVEL = 10
|
|
1697 |
SQL_LEVEL = 11
|
|
1690 | 1698 | |
1691 | 1699 |
def migrate_global_views(conn, cur): |
1692 | 1700 |
cur.execute('''SELECT COUNT(*) FROM information_schema.tables |
... | ... | |
1735 | 1743 |
migrate_views(conn, cur) |
1736 | 1744 |
for formdef in FormDef.select(): |
1737 | 1745 |
formdef.data_class().rebuild_security() |
1738 |
if sql_level < 10:
|
|
1746 |
if sql_level < 11:
|
|
1739 | 1747 |
# 7: add backoffice_submission to tables and views |
1740 | 1748 |
# 8: add submission_context to tables |
1741 | 1749 |
# 9: add last_update_time to views |
1742 | 1750 |
# 10: add submission_channel to tables |
1751 |
# 11: add formdef_name and user_name to views |
|
1743 | 1752 |
migrate_views(conn, cur) |
1744 | 1753 | |
1745 | 1754 |
cur.execute('''UPDATE wcs_meta SET value = %s WHERE key = %s''', ( |
1746 |
- |