0002-lingo-add-default-values-for-TIPI-reference-fields-2.patch
combo/apps/lingo/migrations/0033_tipipaymentformcell_default_reference_values.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
from __future__ import unicode_literals |
|
3 | ||
4 |
from django.db import migrations, models |
|
5 |
import jsonfield.fields |
|
6 | ||
7 | ||
8 |
class Migration(migrations.Migration): |
|
9 | ||
10 |
dependencies = [ |
|
11 |
('lingo', '0032_basketitem_capture_date'), |
|
12 |
] |
|
13 | ||
14 |
operations = [ |
|
15 |
migrations.AddField( |
|
16 |
model_name='tipipaymentformcell', |
|
17 |
name='default_reference_values', |
|
18 |
field=jsonfield.fields.JSONField(default=dict, help_text='Example: {"exer": "1234", "idligne": "345678"}', verbose_name="Default reference fields values", blank=True), |
|
19 |
), |
|
20 |
] |
combo/apps/lingo/models.py | ||
---|---|---|
712 | 712 |
url = models.URLField(_('TIPI payment service URL'), default='https://www.tipi.budget.gouv.fr/tpa/paiement.web') |
713 | 713 |
regies = models.CharField(_('Regies'), help_text=_('separated by commas'), max_length=256) |
714 | 714 |
control_protocol = models.CharField(_('Control protocol'), max_length=8, choices=TIPI_CONTROL_PROCOTOLS, default='pesv2') |
715 |
default_reference_values = JSONField(blank=True, verbose_name=_('Default reference fields values'), |
|
716 |
help_text=_('Example: {"exer": "1234", "idligne": "345678"}')) |
|
715 | 717 |
test_mode = models.BooleanField(_('Test mode'), default=False) |
716 | 718 |
template_name = 'lingo/tipi_form.html' |
717 | 719 | |
... | ... | |
723 | 725 | |
724 | 726 |
def get_cell_extra_context(self, context): |
725 | 727 |
extra_context = super(TipiPaymentFormCell, self).get_cell_extra_context(context) |
726 |
context['reference_fields'] = (
|
|
728 |
reference_fields = (
|
|
727 | 729 |
{'name': 'exer', 'pattern': '[0-9]+', 'length': '4', 'placeholder': '0'*4, 'protocol': 'any'}, |
728 | 730 |
{'name': 'idpce', 'pattern': '[0-9]+', 'length': '8', 'placeholder': '0'*8, 'protocol': 'pesv2'}, |
729 | 731 |
{'name': 'idligne', 'pattern': '[0-9]+', 'length': '6', 'placeholder': '0'*6, 'protocol': 'pesv2'}, |
... | ... | |
737 | 739 |
context['pesv2'] = (self.control_protocol == 'pesv2') |
738 | 740 |
context['control_protocol'] = self.control_protocol |
739 | 741 |
context['regies'] = [] |
742 |
if self.default_reference_values: |
|
743 |
for field in reference_fields: |
|
744 |
if field['name'] in self.default_reference_values: |
|
745 |
field['default'] = self.default_reference_values[field['name']] |
|
746 |
context['reference_fields'] = reference_fields |
|
740 | 747 |
for regie in self.regies.split(','): |
741 | 748 |
regie_id = regie.strip() |
742 | 749 |
if not regie_id: |
combo/apps/lingo/templates/lingo/tipi_form.html | ||
---|---|---|
28 | 28 |
{% for field in fields %} |
29 | 29 |
{% for f in field.list %} |
30 | 30 |
{% if field.grouper == control_protocol or field.grouper == 'any' %} |
31 |
<input type="text" id="{{ f.name }}" required pattern="{{ f.pattern }}" maxlength="{{ f.length }}" size="{{ f.length }}" placeholder="{{ f.placeholder }}" />{% if field.grouper == 'any' or not forloop.last %} - {% endif %} |
|
31 |
<input type="text" id="{{ f.name }}" required pattern="{{ f.pattern }}" maxlength="{{ f.length }}" size="{{ f.length }}" placeholder="{{ f.placeholder }}" {% if f.default %}value="{{ f.default }}" readonly {% endif %}/>{% if field.grouper == 'any' or not forloop.last %} - {% endif %}
|
|
32 | 32 |
{% endif %} |
33 | 33 |
{% endfor %} |
34 | 34 |
{% endfor %} |
tests/test_lingo_cells.py | ||
---|---|---|
199 | 199 |
html = cell.render({}) |
200 | 200 |
assert "Community identifier" in html |
201 | 201 |
assert '<select id="numcli">' in html |
202 | ||
203 |
# set reference default values and check they are filled and readonly |
|
204 |
cell.default_reference_values = {'exer': '1234', 'rolrec': '00'} |
|
205 |
cell.save() |
|
206 |
html = cell.render({}) |
|
207 |
assert 'value="1234" readonly' in html |
|
208 |
assert 'value="00" readonly' in html |
|
202 |
- |