0001-templates-use-a-template-to-render-formdata-history-.patch
MANIFEST.in | ||
---|---|---|
8 | 8 |
recursive-include data/themes/alto/ *.html *.css *.png *.gif *.jpg *.js *.ezt *.xml |
9 | 9 |
recursive-include data/vendor/ *.dat |
10 | 10 |
recursive-include wcs/qommon/static/ *.css *.png *.gif *.jpg *.js *.eot *.svg *.ttf *.woff |
11 |
recursive-include wcs/templates *.html |
wcs/formdata.py | ||
---|---|---|
143 | 143 |
return self._formdata |
144 | 144 | |
145 | 145 |
def get_author_name(self): |
146 |
user_id = self.who |
|
146 | 147 |
if self.who == '_submitter': |
148 |
user_id = self.formdata.user_id |
|
149 |
try: |
|
150 |
return get_publisher().user_class.get(user_id).display_name |
|
151 |
except KeyError: |
|
152 |
return None |
|
153 | ||
154 |
def get_author_qualification(self): |
|
155 |
if self.who == '_submitter' and not self.formdata.is_submitter(get_request().user): |
|
147 | 156 |
return _('Original Submitter') |
148 |
else: |
|
149 |
return get_publisher().user_class.get(self.who).display_name |
|
157 |
return None |
|
150 | 158 | |
151 | 159 |
def add_part(self, part): |
152 | 160 |
if not self.parts: |
... | ... | |
196 | 204 |
del odict['_formdata'] |
197 | 205 |
return odict |
198 | 206 | |
207 |
@property |
|
208 |
def datetime(self): |
|
209 |
return datetime.datetime(*self.time[:6]) |
|
210 | ||
211 |
def is_hidden(self): |
|
212 |
if self.status: |
|
213 |
wf_status = self.formdata.get_status(self.status) |
|
214 |
if wf_status and not wf_status.is_visible(self.formdata, get_request().user): |
|
215 |
return True |
|
216 |
return False |
|
217 | ||
218 |
def get_status(self): |
|
219 |
return self.formdata.get_status(status=self.status) |
|
220 | ||
221 |
def get_status_label(self): |
|
222 |
return self.formdata.get_status_label(status=self.status) |
|
223 | ||
224 |
def is_status_change(self): |
|
225 |
if not self.status: |
|
226 |
return False |
|
227 |
idx = self.formdata.evolution.index(self) |
|
228 |
if idx == 0: |
|
229 |
return True |
|
230 |
while idx: |
|
231 |
if self.formdata.evolution[idx-1].status and self.status != self.formdata.evolution[idx-1].status: |
|
232 |
return True |
|
233 |
idx -= 1 |
|
234 |
return False |
|
199 | 235 | |
200 | 236 |
class FormData(StorableObject): |
201 | 237 |
_names = 'XX' |
wcs/forms/common.py | ||
---|---|---|
25 | 25 |
from wcs.fields import WidgetField, FileField |
26 | 26 |
from wcs.workflows import EditableWorkflowStatusItem |
27 | 27 | |
28 |
from django.template import RequestContext |
|
29 | ||
28 | 30 |
from qommon import _ |
29 | 31 |
from qommon import template |
30 | 32 |
from qommon import get_logger |
... | ... | |
94 | 96 |
_q_extra_exports = [] |
95 | 97 |
form_page_class = None |
96 | 98 | |
99 |
history_templates = ['wcs/formdata_history.html'] |
|
100 | ||
97 | 101 |
def html_top(self, title = None): |
98 | 102 |
template.html_top(title = title, default_org = _('Forms')) |
99 | 103 | |
... | ... | |
251 | 255 |
return |
252 | 256 |
if not self.formdef.is_user_allowed_read_status_and_history(get_request().user, self.filled): |
253 | 257 |
return |
254 |
r = TemplateIO(html=True) |
|
255 |
r += htmltext('<div class="bo-block" id="evolution-log">') |
|
256 |
r += htmltext('<h2 class="foldable">%s</h2>') % _('Log') |
|
257 |
r += htmltext('<ul id="evolutions">') |
|
258 |
hidden = False |
|
259 |
previous_status = None |
|
260 |
for evo in self.filled.evolution: |
|
261 |
status_css_class = '' |
|
262 |
if evo.status: |
|
263 |
wf_status = self.filled.get_status(evo.status) |
|
264 |
if wf_status: |
|
265 |
status_css_class = wf_status.extra_css_class |
|
266 |
if wf_status and not wf_status.is_visible(self.filled, get_request().user): |
|
267 |
hidden = True |
|
268 |
else: |
|
269 |
hidden = False |
|
270 |
if hidden: |
|
271 |
continue |
|
272 | 258 | |
273 |
evo_author = None |
|
274 |
evo_author_more = None |
|
275 |
klass = 'msg-system' |
|
276 |
if evo.who: |
|
277 |
if evo.who == '_submitter': |
|
278 |
klass = 'msg-in' |
|
279 |
evo_author = _('Original Submitter') |
|
280 |
if get_request().user and self.filled.is_submitter(get_request().user): |
|
281 |
evo_author = get_request().user.display_name |
|
282 |
elif self.filled.user_id: |
|
283 |
try: |
|
284 |
evo_author = get_publisher().user_class.get(self.filled.user_id).display_name |
|
285 |
evo_author_more = _('(Original Submitter)') |
|
286 |
except KeyError: |
|
287 |
pass |
|
288 |
else: |
|
289 |
klass = 'msg-out' |
|
290 |
try: |
|
291 |
evo_author = evo.get_author_name() |
|
292 |
except KeyError: |
|
293 |
pass |
|
294 | ||
295 |
status_block = TemplateIO(html=True) |
|
296 |
if evo.status: |
|
297 |
status_block += htmltext('<div class="evolution-metadata">') |
|
298 |
status_block += htmltext('<span class="status">%s</span> ' |
|
299 |
) % self.filled.get_status_label(evo.status) |
|
300 |
status_block += htmltext('<span class="time">%s</span> ' |
|
301 |
) % misc.localstrftime(evo.time) |
|
302 |
status_block += htmltext('</div>') # <-- .evolution-metadata --> |
|
303 | ||
304 |
parts = TemplateIO(html=True) |
|
305 |
if evo_author: |
|
306 |
parts += htmltext('<span class="user">%s') % evo_author |
|
307 |
if evo_author_more: |
|
308 |
parts += htmltext(' <span>%s</span>') % evo_author_more |
|
309 |
parts += htmltext('</span>') |
|
310 |
if not evo.status: |
|
311 |
parts += htmltext('<span class="time">%s</span> ') % misc.localstrftime(evo.time) |
|
312 | ||
313 |
if evo.comment: |
|
314 |
if evo.comment.startswith(str('#pre')): |
|
315 |
parts += htmltext('<div class="comment"><pre>%s</pre></div>') % evo.comment[4:] |
|
316 |
else: |
|
317 |
parts += htmltext('<div class="comment">') |
|
318 |
parts += htmltext('<p>') |
|
319 |
parts += htmltext('\n').join( |
|
320 |
[(x or htmltext('</p><p>')) for x in evo.comment.splitlines()]) |
|
321 |
parts += htmltext('</p>') |
|
322 |
parts += htmltext('</div>') |
|
323 |
for t in evo.display_parts(): |
|
324 |
parts += t |
|
325 | ||
326 |
parts_value = parts.getvalue() |
|
327 | ||
328 |
if not (parts_value or evo.status != previous_status): |
|
329 |
continue |
|
330 | ||
331 |
if evo.status: |
|
332 |
previous_status = evo.status |
|
333 | ||
334 |
try: |
|
335 |
status_colour = self.filled.get_status(previous_status).colour |
|
336 |
except AttributeError: |
|
337 |
status_colour = 'ffffff' |
|
338 |
fg_colour = misc.get_foreground_colour(status_colour) |
|
339 | ||
340 |
r += htmltext('<li class="%s %s">' % (klass, status_css_class)) |
|
341 |
r += htmltext('<span class="item" style="background: #%s; color: %s;"></span>' % |
|
342 |
(status_colour, fg_colour)) |
|
343 |
r += htmltext('<div>') |
|
344 |
r += status_block.getvalue() |
|
345 | ||
346 |
if parts_value: |
|
347 |
r += htmltext('<div class="msg">') |
|
348 |
r += htmltext(parts_value) |
|
349 |
r += htmltext('</div>') |
|
350 | ||
351 |
r += htmltext('</div>') |
|
352 |
r += htmltext('</li>') |
|
353 |
r += htmltext('</ul>') |
|
354 |
r += htmltext('</div>') # .bo-block #evolution-log |
|
355 |
return r.getvalue() |
|
259 |
context = RequestContext(get_request(), {'formdata': self.filled}) |
|
260 |
return template.render(self.history_templates, context) |
|
356 | 261 | |
357 | 262 |
def check_receiver(self): |
358 | 263 |
session = get_session() |
wcs/forms/root.py | ||
---|---|---|
1577 | 1577 |
class PublicFormStatusPage(FormStatusPage): |
1578 | 1578 |
_q_exports_orig = ['', 'download', 'status'] |
1579 | 1579 |
form_page_class = FormPage |
1580 |
history_templates = ['wcs/front/formdata_history.html', 'wcs/formdata_history.html'] |
|
1580 | 1581 | |
1581 | 1582 |
def __init__(self, *args, **kwargs): |
1582 | 1583 |
FormStatusPage.__init__(self, *args, **kwargs) |
wcs/qommon/template.py | ||
---|---|---|
19 | 19 |
import glob |
20 | 20 |
import xml.etree.ElementTree as ET |
21 | 21 | |
22 |
from django.template.loader import render_to_string |
|
23 | ||
22 | 24 |
from quixote import get_session, get_request, get_response, get_publisher |
23 | 25 |
from quixote.directory import Directory |
24 | 26 |
from quixote.util import StaticDirectory, StaticFile |
... | ... | |
405 | 407 | |
406 | 408 |
template.generate(fd, vars) |
407 | 409 |
return fd.getvalue() |
410 | ||
411 | ||
412 |
def render(template_name, context): |
|
413 |
return htmltext(render_to_string(template_name, context).encode('utf-8')) |
wcs/templates/wcs/formdata_history.html | ||
---|---|---|
1 |
{% load i18n %} |
|
2 |
<div class="bo-block" id="evolution-log"> |
|
3 |
<h2 class="foldable">{% trans "Log" %}</h2> |
|
4 |
<ul id="evolutions"> |
|
5 |
{% for evolution in formdata.evolution %} |
|
6 |
{% if not evolution.is_hidden %} |
|
7 |
{% with status=evolution.get_status display_parts=evolution.display_parts %} |
|
8 |
{% if evolution.who or evolution.is_status_change or display_parts %} |
|
9 |
<li class="{% if evolution.who == '_submitter' %}msg-in{% elif evolution.who %}msg-out{% else %}msg-system{% endif %} {{ status.extra_css_class }}"> |
|
10 |
<span class="item" style="background: #{{ status.colour }}; color: {{ status.get_contrast_color}}"></span> |
|
11 |
<div> |
|
12 |
{% if evolution.status %} |
|
13 |
<div class="evolution-metadata"> |
|
14 |
<span class="status">{{evolution.get_status_label}}</span> |
|
15 |
<span class="time">{{evolution.datetime}}</span> |
|
16 |
</div> |
|
17 |
{% endif %} |
|
18 |
<div class="msg"> |
|
19 |
{% if evolution.who %} |
|
20 |
<span class="user">{{evolution.get_author_name}} |
|
21 |
<span>{% if evolution.get_author_qualification %}({{evolution.get_author_qualification}}){% endif %}</span> |
|
22 |
</span> |
|
23 |
{% endif %} |
|
24 |
{% if not evolution.status %} |
|
25 |
<span class="time">{{evolution.datetime}}</span> |
|
26 |
{% endif %} |
|
27 |
{% if evolution.comment %} |
|
28 |
<div class="comment"> |
|
29 |
{{evolution.comment|linebreaks}} |
|
30 |
</div> |
|
31 |
{% endif %} |
|
32 |
{% for part in display_parts %} |
|
33 |
{{part|safe}} |
|
34 |
{% endfor %} |
|
35 |
</div> |
|
36 |
</div> |
|
37 |
</li> |
|
38 |
{% endif %} |
|
39 |
{% endwith %} |
|
40 |
{% endif %} |
|
41 |
{% endfor %} |
|
42 |
</ul> |
|
43 |
</div> |
wcs/workflows.py | ||
---|---|---|
29 | 29 |
from quixote import get_request, redirect |
30 | 30 | |
31 | 31 |
from qommon import _ |
32 |
from qommon.misc import C_, get_as_datetime, file_digest |
|
32 |
from qommon.misc import C_, get_as_datetime, file_digest, get_foreground_colour
|
|
33 | 33 |
from qommon.storage import StorableObject, atomic_write |
34 | 34 |
from qommon.form import * |
35 | 35 |
from qommon.humantime import seconds2humanduration |
... | ... | |
1411 | 1411 |
waitpoint = item.waitpoint or waitpoint |
1412 | 1412 |
return bool(endpoint or waitpoint) |
1413 | 1413 | |
1414 |
def get_contrast_color(self): |
|
1415 |
colour = self.colour or 'ffffff' |
|
1416 |
return misc.get_foreground_colour(colour) |
|
1417 | ||
1414 | 1418 |
def __getstate__(self): |
1415 | 1419 |
odict = self.__dict__.copy() |
1416 | 1420 |
if odict.has_key('parent'): |
1417 |
- |