misc: add submission context details on front form pages (#9203)
gitea/wcs/pipeline/head Build queued... Details

This commit is contained in:
Frédéric Péters 2024-03-10 13:03:51 +01:00
parent 8598a77b4e
commit f1471ca20c
2 changed files with 78 additions and 2 deletions

View File

@ -10,6 +10,7 @@ from wcs import fields
from wcs.carddef import CardDef
from wcs.formdef import FormDef
from wcs.qommon.http_request import HTTPRequest
from wcs.qommon.ident.password_accounts import PasswordAccount
from wcs.workflows import Workflow, WorkflowBackofficeFieldsFormDef
from wcs.wscalls import NamedWsCall
@ -2245,3 +2246,50 @@ def test_backoffice_submission_no_roles(pub):
assert formdef.data_class().count() == 1
formdata = formdef.data_class().select()[0]
assert formdata.data == {'1': 'xxx'}
def test_backoffice_submission_then_front(pub):
user = create_user(pub)
front_user = pub.user_class()
front_user.name = 'front user'
front_user.email = 'test@invalid'
front_user.store()
account = PasswordAccount(id='front')
account.set_password('front')
account.user_id = front_user.id
account.store()
FormDef.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = [
fields.PageField(id='0', label='1st page'),
fields.StringField(id='1', label='Field on 1st page'),
fields.PageField(id='2', label='2nd page'),
fields.StringField(id='3', label='Field on 2nd page'),
]
formdef.backoffice_submission_roles = user.roles[:]
formdef.workflow_roles = {'_receiver': 1}
formdef.store()
app = login(get_app(pub))
resp = app.get('/backoffice/submission/')
resp = resp.click(formdef.name)
resp.form['user_id'] = str(front_user.id) # happens via javascript
resp.form['submission_channel'] = 'phone'
resp.form['f1'] = 'test submission'
resp = resp.form.submit('submit') # -> 2nd page
resp.form['f3'] = 'baz'
resp = resp.form.submit('submit') # -> validation page
resp = resp.form.submit('submit') # final submit
formdata = formdef.data_class().get(resp.location.split('/')[-2])
resp = login(get_app(pub), username='front', password='front').get(formdata.get_url())
assert (
resp.pyquery('.text-form-recorded').text()
== f'The form has been recorded on {formdata.receipt_time.strftime("%Y-%m-%d %H:%M")} '
f'with the number {formdata.get_display_id()}. It has been submitted for you by '
f'admin after a phone call.'
)

View File

@ -2480,14 +2480,42 @@ TextsDirectory.register(
'form-recorded',
_('Message when a form has been recorded'),
category=_('Forms'),
default=_('The form has been recorded on {{ form_receipt_datetime }} with the number {{ form_number }}.'),
default=_(
'''
The form has been recorded on {{ form_receipt_datetime }} with the number {{ form_number }}.
{% if form_submission_agent_display_name %}
It has been submitted for you by {{ form_submission_agent_display_name }}
{% if form_submission_channel == "phone" %}after a phone call.
{% elif form_submission_channel == "email" %}after an email.
{% elif form_submission_channel == "mail" %}after a mail.
{% elif form_submission_channel == "social-network" %}after a message on a social network.
{% elif form_submission_channel == "counter" %}after your passage at the counter.
{% else %}.
{% endif %}
{% endif %}
'''
),
)
TextsDirectory.register(
'form-recorded-allow-one',
_('Message when a form has been recorded, and the form is set to only allow one per user'),
category=_('Forms'),
default=_('The form has been recorded on {{ form_receipt_datetime }}.'),
default=_(
'''
The form has been recorded on {{ form_receipt_datetime }}.
{% if form_submission_agent_display_name %}
It has been submitted for you by {{ form_submission_agent_display_name }}
{% if form_submission_channel == "phone" %}after a phone call.
{% elif form_submission_channel == "email" %}after an email.
{% elif form_submission_channel == "mail" %}after a mail.
{% elif form_submission_channel == "social-network" %}after a message on a social network.
{% elif form_submission_channel == "counter" %}after your passage at the counter.
{% else %}.
{% endif %}
{% endif %}
'''
),
)
TextsDirectory.register(