Projet

Général

Profil

0002-lingo-validate-service_options-in-forms-41439.patch

Benjamin Dauvergne, 08 avril 2020 18:57

Télécharger (1,92 ko)

Voir les différences:

Subject: [PATCH 2/2] lingo: validate service_options in forms (#41439)

 combo/apps/lingo/models.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
combo/apps/lingo/models.py
35 35
from django.utils import timezone, dateparse, six
36 36
from django.core.mail import EmailMultiAlternatives
37 37
from django.urls import reverse
38
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
38
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied, ValidationError
39 39
from django.utils.encoding import python_2_unicode_compatible
40 40
from django.utils.formats import localize
41 41
from django.utils.http import urlencode
......
89 89
                      no_online_payment_reason=data.get('no_online_payment_reason'))
90 90

  
91 91

  
92
def validate_dict(value):
93
    if not isinstance(value, dict):
94
        raise ValidationError(_('Value must a JSON object'))
95

  
96

  
92 97
@python_2_unicode_compatible
93 98
class PaymentBackend(models.Model):
94 99
    label = models.CharField(verbose_name=_('Label'), max_length=64)
......
97 102
        help_text=_('The identifier is used in webservice calls.'))
98 103
    service = models.CharField(
99 104
        verbose_name=_('Payment Service'), max_length=64, choices=SERVICES)
100
    service_options = JSONField(blank=True, verbose_name=_('Payment Service Options'))
105
    service_options = JSONField(
106
        blank=True,
107
        verbose_name=_('Payment Service Options'),
108
        validators=[validate_dict])
101 109

  
102 110
    def __str__(self):
103 111
        return self.label
104
-