Skip to content

Commit c6de943

Browse files
committed
issue2550831: Make the classic template query.edit page work.
R David Murray had a number of fixes. At least some of the fixes were already present in the devel and responsive templates. I touched up the html a bit and did what I hope aresome improvement for performance by shoving criteria into the filter rather than looping over all issues and filtering at the tal level. Also used R David's method to add a restore feature and work around an issue where a retired (deleted) query could still be in the active list. But because it was retired there was no way to manipulate it.
1 parent 9c4b25b commit c6de943

File tree

3 files changed

+103
-27
lines changed

3 files changed

+103
-27
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ Fixed:
234234
psycopg1. See:
235235
https://sourceforge.net/p/roundup/mailman/message/32855027/
236236
for rational for dropping it.
237+
- issue2550831: Make the classic template query.edit page work.
238+
Many fixes and improvements. See ``upgrading.txt`` for details.
239+
Diagnosis and fix with patch by R David Murray. Support for
240+
restoring retired but active queries, html layout changes and doc
241+
by John Rouillard.
237242

238243
2016-01-11: 1.5.1
239244

doc/upgrading.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,37 @@ If you are running a tracker that **does not** allow read access for
132132
anonymous, you should remove this entry as it can be used to perform
133133
a username guessing attack against a roundup install.
134134

135+
Improvements in Classic Tracker query.edit.html template
136+
--------------------------------------------------------
137+
138+
There is a new query editing template included in the distribution at:
139+
share/roundup/templates/classic/html/query.edit.html
140+
141+
This template fixes:
142+
143+
* Once added, a public query could not be removed from "Your Queries". Trying to do so would cause a permissions error.
144+
* The private yes/no dropdown always showed "yes" regardless of underlying state
145+
* The query Delete button did not work.
146+
* The same query being displayed multiple times
147+
148+
It also adds:
149+
* the table layout displays queries created by the user first, then available public queries.
150+
* public query owners are shown
151+
* better support for deleted queries. When a query is deleted, it is
152+
still available for those who added it to their query list. If you
153+
are the query owner, you can restore (undelete) the query. If you
154+
are not the owner you can remove it from your query list.
155+
(If a query is deleted and nobody had it in their query list, it
156+
will not show up in the "Active retired queries" section. You will
157+
have to use the class editor or roundup_admin command line to
158+
restore it.)
159+
* notifies the user that delete/restore requires javascript. It
160+
always did, but that requirement wasn't displayed.
161+
162+
If you have not modified the query.edit.html template in your tracker, you should be
163+
able to copy the new version from the location above. Otherwise you will
164+
have to merge the changes into your modified template.
165+
135166
Migrating from 1.5.0 to 1.5.1
136167
=============================
137168

share/roundup/templates/classic/html/query.edit.html

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,36 @@
1212
i18n:translate="">You are not allowed to edit queries.</span>
1313

1414
<script language="javascript">
15-
// This exists solely because I can't figure how to get the & into an
16-
// attributes TALES expression, and so it keeps getting quoted.
15+
// This allows us to make the delete button an immediate action.
16+
// The post_to_url function comes from:
17+
// http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit
1718
function retire(qid) {
18-
window.location = 'query'+qid+'?@action=retire&@template=edit';
19+
post_to_url('query'+qid, {'@action': 'retire', '@template': 'edit'});
20+
}
21+
22+
function restore(qid) {
23+
post_to_url('query'+qid, {'@action': 'restore', '@template': 'edit'});
24+
}
25+
function post_to_url(path, params, method) {
26+
method = method || "post"; // Set method to post by default if not specified.
27+
28+
var form = document.createElement("form");
29+
form.setAttribute("method", method);
30+
form.setAttribute("action", path);
31+
32+
for(var key in params) {
33+
if(params.hasOwnProperty(key)) {
34+
var hiddenField = document.createElement("input");
35+
hiddenField.setAttribute("type", "hidden");
36+
hiddenField.setAttribute("name", key);
37+
hiddenField.setAttribute("value", params[key]);
38+
39+
form.appendChild(hiddenField);
40+
}
41+
}
42+
43+
document.body.appendChild(form);
44+
form.submit();
1945
}
2046
</script>
2147

@@ -29,12 +55,15 @@
2955
<th i18n:translate="">Include in "Your Queries"</th>
3056
<th i18n:translate="">Edit</th>
3157
<th i18n:translate="">Private to you?</th>
32-
<th>&nbsp;</th>
58+
<th i18n:translate="">delete/restore<br> (javascript<br>required)</th>
59+
</tr>
60+
<tr>
61+
<td colspan="5"><b i18n:translate="">Queries I created</b></td>
3362
</tr>
3463

35-
<tr tal:repeat="query mine">
36-
<tal:block condition="query/is_retired">
37-
64+
<tr tal:define="queries python:db.query.filter(filterspec={'creator': uid})"
65+
tal:repeat="query queries">
66+
<tal:block>
3867
<td><a tal:attributes="href string:${query/klass}?${query/url}"
3968
tal:content="query/name">query</a></td>
4069

@@ -51,26 +80,13 @@
5180
</select>
5281
</td>
5382

54-
<td colspan="3" i18n:translate="">[query is retired]</td>
55-
56-
<!-- <td> maybe offer "restore" some day </td> -->
57-
</tal:block>
58-
</tr>
59-
60-
<tr tal:repeat="query mine">
61-
<tal:block condition="not:query/is_retired">
62-
<td><a tal:attributes="href string:${query/klass}?${query/url}"
63-
tal:content="query/name">query</a></td>
64-
65-
<td metal:use-macro="template/macros/include" />
66-
6783
<td><a tal:attributes="href string:query${query/id}" i18n:translate="">edit</a></td>
6884

6985
<td>
7086
<select tal:attributes="name string:query${query/id}@private_for">
7187
<option tal:attributes="selected python:query.private_for == uid;
7288
value uid" i18n:translate="">yes</option>
73-
<option tal:attributes="selected python:query.private_for == None"
89+
<option tal:attributes="selected python:not query.private_for"
7490
value="-1" i18n:translate="">no</option>
7591
</select>
7692
</td>
@@ -81,20 +97,44 @@
8197
</td>
8298
</tal:block>
8399
</tr>
100+
<tr>
101+
<td colspan="4"><b i18n:translate="">Queries others created</b></td>
102+
<td colspan="4"><b i18n:translate="">Owner</b></td>
103+
</tr>
84104

85-
<tr tal:define="queries python:db.query.filter(filterspec={'private_for':None})"
105+
<tr tal:define="queries
106+
python:db.query.filter(filterspec={'private_for': None})"
86107
tal:repeat="query queries">
87-
<tal:block condition="python: query.creator != uid">
108+
<tal:block tal:condition="python:not query.creator == uid">
88109
<td><a tal:attributes="href string:${query/klass}?${query/url}"
89110
tal:content="query/name">query</a></td>
90111

91112
<td metal:use-macro="template/macros/include" />
92113

93-
<td colspan="3" tal:condition="query/is_edit_ok">
94-
<a tal:attributes="href string:query${query/id}" i18n:translate="">edit</a>
95-
</td>
96-
<td tal:condition="not:query/is_edit_ok" colspan="3"
114+
<td colspan="2" tal:condition="not:query/is_edit_ok"
97115
i18n:translate="">[not yours to edit]</td>
116+
<td colspan="2" tal:condition="query/is_edit_ok"
117+
i18n:translate=""><a tal:attributes="href string:query${query/id}" i18n:translate="">edit</a></td>
118+
<td colspan="2"
119+
tal:content="query/creator" i18n:translate="">put query owner here</td>
120+
</tal:block>
121+
</tr>
122+
123+
<tr>
124+
<td colspan="5"><b i18n:translate="">Active retired queries</b></td>
125+
</tr>
126+
<tr tal:repeat="query request/user/queries">
127+
<tal:block condition="python:path('query/is_retired')">
128+
<td><a tal:attributes="href string:${query/klass}?${query/url}"
129+
tal:content="query/name">query</a></td>
130+
<tal:block tal:condition="python: not query.creator == uid">
131+
<td metal:use-macro="template/macros/include"> </td>
132+
</tal:block>
133+
<td colspan="3" i18n:translate="">[query is retired]</td>
134+
<td tal:condition="python:query.creator == uid">
135+
<input type="button" value="Restore" i18n:attributes="value"
136+
tal:attributes="onClick python:'''restore('%s')'''%query.id">
137+
</td>
98138
</tal:block>
99139
</tr>
100140

0 commit comments

Comments
 (0)