0001-lingo-add-labels-to-TIPI-regies-18320.patch
combo/apps/lingo/models.py | ||
---|---|---|
19 | 19 |
import datetime |
20 | 20 |
import json |
21 | 21 |
import logging |
22 |
import re |
|
22 | 23 | |
23 | 24 |
from decimal import Decimal |
24 | 25 | |
... | ... | |
737 | 738 |
class TipiPaymentFormCell(CellBase): |
738 | 739 |
title = models.CharField(_('Title'), max_length=150, blank=True) |
739 | 740 |
url = models.URLField(_('TIPI payment service URL'), default='https://www.tipi.budget.gouv.fr/tpa/paiement.web') |
740 |
regies = models.CharField(_('Regies'), help_text=_('separated by commas'), max_length=256) |
|
741 |
regies = models.CharField( |
|
742 |
_('Regies'), |
|
743 |
help_text=_('Values separated by commas. It is possible to add a label after a regie identifier. ' |
|
744 |
'Example: "1234 - Regie A,5678 - Regie B"'), |
|
745 |
max_length=256) |
|
741 | 746 |
control_protocol = models.CharField(_('Control protocol'), max_length=8, choices=TIPI_CONTROL_PROCOTOLS, |
742 | 747 |
default='pesv2') |
743 | 748 |
exer = models.CharField('Exer', max_length=4, blank=True, help_text=_('Default value to be used in form')) |
... | ... | |
797 | 802 |
field['default'] = getattr(self, field['name']) |
798 | 803 |
context['reference_fields'] = reference_fields |
799 | 804 |
for regie in self.regies.split(','): |
800 |
regie_id = regie.strip() |
|
801 |
if not regie_id: |
|
805 |
regie = regie.strip() |
|
806 |
id_search = re.search(r'(\d+)', regie) |
|
807 |
if not id_search: |
|
802 | 808 |
continue |
803 |
context['regies'].append(regie_id) |
|
809 |
regie_id = id_search.group(1) |
|
810 |
context['regies'].append((regie_id, regie)) |
|
804 | 811 |
return extra_context |
combo/apps/lingo/templates/lingo/tipi_form.html | ||
---|---|---|
11 | 11 |
{% if regies|length > 1 %} |
12 | 12 |
<p><label>{% trans "Community identifier" %}</label> |
13 | 13 |
<select id="numcli"> |
14 |
{% for id in regies %}
|
|
15 |
<option value="{{ id }}">{{ id }}</option>
|
|
14 |
{% for regie in regies %}
|
|
15 |
<option value="{{ regie.0 }}">{{ regie.1 }}</option>
|
|
16 | 16 |
{% endfor %} |
17 | 17 |
</select> |
18 | 18 |
</p> |
19 | 19 |
{% else %} |
20 |
<input type="hidden" id="numcli" value="{{ regies.0 }}" /> |
|
20 |
<input type="hidden" id="numcli" value="{{ regies.0.0 }}" />
|
|
21 | 21 |
{% endif %} |
22 | 22 |
<ul class="errorlist" id="refdet_error" style="display: none"> |
23 | 23 |
<li>{% trans "invalid reference" %}</li> |
tests/test_lingo_cells.py | ||
---|---|---|
178 | 178 |
cell = TipiPaymentFormCell() |
179 | 179 |
cell.page = page |
180 | 180 |
cell.title = 'TIPI Payment' |
181 |
cell.regies = "test regie"
|
|
181 |
cell.regies = "1234"
|
|
182 | 182 |
cell.order = 0 |
183 | 183 |
cell.save() |
184 | 184 |
assert cell.control_protocol == 'pesv2' |
... | ... | |
187 | 187 |
html = cell.render({}) |
188 | 188 |
assert "<h2>TIPI Payment</h2>" in html |
189 | 189 |
assert "Community identifier" not in html |
190 |
assert '<input type="hidden" id="numcli" value="test regie" />' in html
|
|
190 |
assert '<input type="hidden" id="numcli" value="1234" />' in html
|
|
191 | 191 |
assert 'id="exer"' in html |
192 | 192 |
assert 'id="idpce"' in html |
193 | 193 |
assert 'id="idligne"' in html |
... | ... | |
197 | 197 |
assert 'data-saisie="M"' in html |
198 | 198 |
assert 'data-pesv2="True"' in html |
199 | 199 | |
200 |
cell.regies = "1234 - test regie" |
|
201 |
cell.save() |
|
202 |
html = cell.render({}) |
|
203 |
assert '<input type="hidden" id="numcli" value="1234" />' in html |
|
204 | ||
205 |
cell.regies = "test regie" |
|
206 |
cell.save() |
|
207 |
html = cell.render({}) |
|
208 |
assert '<input type="hidden" id="numcli" value="" />' in html |
|
209 | ||
200 | 210 |
cell.control_protocol = 'rolmre' |
201 | 211 |
cell.test_mode = True |
202 | 212 |
cell.save() |
... | ... | |
212 | 222 |
cell_media = str(cell.media) |
213 | 223 |
assert "js/tipi.js" in cell_media |
214 | 224 | |
215 |
cell.regies = 'regie1, regie2'
|
|
225 |
cell.regies = '1 regie1, 2- regie2,3 : regie3,4,5regie5 ,bad-format-regie 6'
|
|
216 | 226 |
cell.save() |
217 | 227 |
html = cell.render({}) |
218 | 228 |
assert "Community identifier" in html |
219 | 229 |
assert '<select id="numcli">' in html |
230 |
assert '<option value="1">1 regie1</option>' in html |
|
231 |
assert '<option value="2">2- regie2</option>' in html |
|
232 |
assert '<option value="3">3 : regie3</option>' in html |
|
233 |
assert '<option value="4">4</option>' in html |
|
234 |
assert '<option value="5">5regie5</option>' in html |
|
220 | 235 | |
221 | 236 |
# set reference default values and check they are filled and readonly |
222 | 237 |
cell.exer = '1234' |
223 |
- |