lingo: add labels to TIPI regies (#18320)

This commit is contained in:
Lauréline Guérin 2020-01-24 10:20:24 +01:00
parent e3ae82a7be
commit 4e6a7f4a5d
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 32 additions and 10 deletions

View File

@ -19,6 +19,7 @@
import datetime
import json
import logging
import re
from decimal import Decimal
@ -737,7 +738,11 @@ TIPI_CONTROL_PROCOTOLS = (
class TipiPaymentFormCell(CellBase):
title = models.CharField(_('Title'), max_length=150, blank=True)
url = models.URLField(_('TIPI payment service URL'), default='https://www.tipi.budget.gouv.fr/tpa/paiement.web')
regies = models.CharField(_('Regies'), help_text=_('separated by commas'), max_length=256)
regies = models.CharField(
_('Regies'),
help_text=_('Values separated by commas. It is possible to add a label after a regie identifier. '
'Example: "1234 - Regie A,5678 - Regie B"'),
max_length=256)
control_protocol = models.CharField(_('Control protocol'), max_length=8, choices=TIPI_CONTROL_PROCOTOLS,
default='pesv2')
exer = models.CharField('Exer', max_length=4, blank=True, help_text=_('Default value to be used in form'))
@ -797,8 +802,10 @@ class TipiPaymentFormCell(CellBase):
field['default'] = getattr(self, field['name'])
context['reference_fields'] = reference_fields
for regie in self.regies.split(','):
regie_id = regie.strip()
if not regie_id:
regie = regie.strip()
id_search = re.search(r'(\d+)', regie)
if not id_search:
continue
context['regies'].append(regie_id)
regie_id = id_search.group(1)
context['regies'].append((regie_id, regie))
return extra_context

View File

@ -11,13 +11,13 @@
{% if regies|length > 1 %}
<p><label>{% trans "Community identifier" %}</label>
<select id="numcli">
{% for id in regies %}
<option value="{{ id }}">{{ id }}</option>
{% for regie in regies %}
<option value="{{ regie.0 }}">{{ regie.1 }}</option>
{% endfor %}
</select>
</p>
{% else %}
<input type="hidden" id="numcli" value="{{ regies.0 }}" />
<input type="hidden" id="numcli" value="{{ regies.0.0 }}" />
{% endif %}
<ul class="errorlist" id="refdet_error" style="display: none">
<li>{% trans "invalid reference" %}</li>

View File

@ -178,7 +178,7 @@ def test_tipi_cell():
cell = TipiPaymentFormCell()
cell.page = page
cell.title = 'TIPI Payment'
cell.regies = "test regie"
cell.regies = "1234"
cell.order = 0
cell.save()
assert cell.control_protocol == 'pesv2'
@ -187,7 +187,7 @@ def test_tipi_cell():
html = cell.render({})
assert "<h2>TIPI Payment</h2>" in html
assert "Community identifier" not in html
assert '<input type="hidden" id="numcli" value="test regie" />' in html
assert '<input type="hidden" id="numcli" value="1234" />' in html
assert 'id="exer"' in html
assert 'id="idpce"' in html
assert 'id="idligne"' in html
@ -197,6 +197,16 @@ def test_tipi_cell():
assert 'data-saisie="M"' in html
assert 'data-pesv2="True"' in html
cell.regies = "1234 - test regie"
cell.save()
html = cell.render({})
assert '<input type="hidden" id="numcli" value="1234" />' in html
cell.regies = "test regie"
cell.save()
html = cell.render({})
assert '<input type="hidden" id="numcli" value="" />' in html
cell.control_protocol = 'rolmre'
cell.test_mode = True
cell.save()
@ -212,11 +222,16 @@ def test_tipi_cell():
cell_media = str(cell.media)
assert "js/tipi.js" in cell_media
cell.regies = 'regie1, regie2'
cell.regies = '1 regie1, 2- regie2,3 : regie3,4,5regie5 ,bad-format-regie 6'
cell.save()
html = cell.render({})
assert "Community identifier" in html
assert '<select id="numcli">' in html
assert '<option value="1">1 regie1</option>' in html
assert '<option value="2">2- regie2</option>' in html
assert '<option value="3">3 : regie3</option>' in html
assert '<option value="4">4</option>' in html
assert '<option value="5">5regie5</option>' in html
# set reference default values and check they are filled and readonly
cell.exer = '1234'