general: use a django template for the formdata status page (#20375)

This commit is contained in:
Frédéric Péters 2017-12-03 18:12:55 +01:00
parent d270f6adc7
commit 345f3a5dff
5 changed files with 83 additions and 59 deletions

23
wcs/context_processors.py Normal file
View File

@ -0,0 +1,23 @@
# w.c.s. - web application for online forms
# Copyright (C) 2005-2017 Entr'ouvert
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
from quixote import get_publisher, get_response
def publisher(request):
return {'publisher': get_publisher}
def response(request):
return {'response': get_response}

View File

@ -109,7 +109,9 @@ class FormStatusPage(Directory):
_q_extra_exports = []
form_page_class = None
do_not_call_in_templates = True
history_templates = ['wcs/formdata_history.html']
status_templates = ['wcs/formdata_status.html']
def html_top(self, title = None):
template.html_top(title = title, default_org = _('Forms'))
@ -172,11 +174,7 @@ class FormStatusPage(Directory):
return r.getvalue()
return ''
def receipt_message(self, mine=False):
workflow_messages = self.workflow_messages()
if workflow_messages:
return workflow_messages
def recorded_message(self):
r = TemplateIO(html=True)
# behaviour if workflow doesn't display any message
if self.filled.receipt_time is not None:
@ -184,55 +182,37 @@ class FormStatusPage(Directory):
else:
tm = '???'
r += htmltext('<div id="receipt-intro">')
if self.formdef.only_allow_one:
r += TextsDirectory.get_html_text('form-recorded-allow-one', vars={'date': tm})
else:
r += TextsDirectory.get_html_text('form-recorded',
vars={'date': tm, 'number': self.filled.get_display_id()})
if mine:
handling_role = self.filled.get_handling_role()
if handling_role and handling_role.details:
endpoint_status = self.formdef.workflow.get_endpoint_status()
r += htmltext('<p>')
if self.filled.status in [x.id for x in endpoint_status]:
r += _('Your case has been handled by:')
else:
r += _('Your case is handled by:')
r += htmltext('</p>')
r += htmltext('<p id="receiver">')
r += htmltext(handling_role.details.replace(str('\n'), str('<br />')))
r += htmltext('</p>')
if self.formdef.enable_tracking_codes and self.filled.tracking_code:
r += htmltext('<p id="tracking-code">')
r += _('You can get back to this page using the following '
'tracking code: ')
r += htmltext('<a href="../code/%s/" rel="popup">%s</a>') % (
self.filled.tracking_code, self.filled.tracking_code)
r += htmltext('</p>')
r += htmltext('</div>')
return r.getvalue()
def get_handling_role_info_text(self):
handling_role = self.filled.get_handling_role()
if not (handling_role and handling_role.details):
return None
r = TemplateIO(html=True)
endpoint_status = self.formdef.workflow.get_endpoint_status()
r += htmltext('<p>')
if self.filled.status in [x.id for x in endpoint_status]:
r += _('Your case has been handled by:')
else:
r += _('Your case is handled by:')
r += htmltext('</p>')
r += htmltext('<p id="receiver">')
r += htmltext(handling_role.details.replace(str('\n'), str('<br />')))
r += htmltext('</p>')
return r.getvalue()
def _q_index(self):
mine = self.check_auth()
get_logger().info('form %s - id: %s - view' % (self.formdef.name, self.filled.id))
self.html_top(self.formdef.name)
r = TemplateIO(html=True)
r += self.receipt_message(mine=mine)
r += self.receipt()
r += self.history()
session = get_session()
user = get_request().user
form = self.filled.get_workflow_form(user)
if form and form.is_submitted():
if not form.has_errors():
url = self.submit(form, comment_only = True)
@ -245,24 +225,20 @@ class FormStatusPage(Directory):
response.content_type = 'text/plain'
return "Your browser should redirect you"
if form:
r += form.render()
self.html_top(self.formdef.name)
context = RequestContext(get_request().django_request, {
'view': self,
'mine': mine,
'formdata': self.filled,
'workflow_form': form,
})
r += self.form_status_buttons()
return r.getvalue()
return template.render(self.status_templates, context)
def export_to_json(self, anonymise=False):
get_response().set_content_type('application/json')
return self.filled.export_to_json(anonymise=anonymise)
def form_status_buttons(self):
if not get_response().iframe_mode:
r = TemplateIO(html=True)
r += htmltext('<div class="back-home-button">')
r += htmltext('<a href="%s">%s</a>') % (get_publisher().get_root_url(), _('Back Home'))
r += htmltext('</div>')
return r.getvalue()
def history(self):
if not self.filled.evolution:
return

View File

@ -1572,6 +1572,7 @@ class PublicFormStatusPage(FormStatusPage):
_q_exports_orig = ['', 'download', 'status']
form_page_class = FormPage
history_templates = ['wcs/front/formdata_history.html', 'wcs/formdata_history.html']
status_templates = ['wcs/front/formdata_status.html', 'wcs/formdata_status.html']
def __init__(self, *args, **kwargs):
FormStatusPage.__init__(self, *args, **kwargs)
@ -1586,14 +1587,6 @@ class PublicFormStatusPage(FormStatusPage):
self.formdef.url_name,
str(self.filled.id)))
def form_status_buttons(self):
if not get_response().iframe_mode:
r = TemplateIO(html=True)
r += htmltext('<div class="back-home-button">')
r += htmltext('<a href="%s">%s</a>') % (get_publisher().get_root_url(), _('Back Home'))
r += htmltext('</div>')
return r.getvalue()
TextsDirectory.register('welcome-logged',
N_('Welcome text on home page for logged users'))

View File

@ -120,6 +120,8 @@ TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"wcs.context_processors.publisher",
"wcs.context_processors.response",
)
INSTALLED_APPS = (

View File

@ -0,0 +1,30 @@
{% load i18n %}
{% with workflow_messages=view.workflow_messages %}
{% if workflow_messages %}
{{ workflow_messages|safe }}
{% else %}
<div id="receipt-intro">
{{ view.recorded_message|safe }}
{% if mine %}
{{ view.get_handling_role_info_text|safe }}
{% endif %}
{% if mine and formdata.formdef.enable_tracking_codes and formdata.tracking_code %}
<p id="tracking-code">
{% trans "You can get back to this page using the following tracking code:" %}
<a href="../code/{{ formdata.tracking_code }}/" rel="popup">{{ formdata.tracking_code }}</a>
</p>
{% endif %}
</div>
{% endif %}
{% endwith %}
{{ view.receipt|safe }}
{{ view.history|safe }}
{{ workflow_form.render|safe }}
{% if not response.iframe_mode %}
<div class="back-home-button">
<a href="{{ publisher.get_root_url }}">{% trans "Back Home" %}</a>
</div>
{% endif %}