From 5915485d89cf3b625bbba5e0e695b24f55165079 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Mon, 16 Jul 2018 21:46:13 +0200 Subject: [PATCH] =?UTF-8?q?Oubli=20d'import=20+=20form=20vide=20pas=20vali?= =?UTF-8?q?d=C3=A9=20remplac=C3=A9=20par=20None?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cotisations/forms.py | 1 + cotisations/payment_methods/forms.py | 6 ++---- cotisations/views.py | 6 ++++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cotisations/forms.py b/cotisations/forms.py index 4c4721a8..d7a2e2ba 100644 --- a/cotisations/forms.py +++ b/cotisations/forms.py @@ -42,6 +42,7 @@ from django.forms import ModelForm, Form from django.core.validators import MinValueValidator from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy as _l +from django.shortcuts import get_object_or_404 from re2o.field_permissions import FieldPermissionFormMixin from re2o.mixins import FormRevMixin diff --git a/cotisations/payment_methods/forms.py b/cotisations/payment_methods/forms.py index 0a3f1dd2..d4d55a74 100644 --- a/cotisations/payment_methods/forms.py +++ b/cotisations/payment_methods/forms.py @@ -30,7 +30,7 @@ def payment_method_factory(payment, *args, creation=True, **kwargs): If the payment has a payment method, returns a ModelForm of it. Else if it is the creation of the payment, a `PaymentMethodForm`. - Else an empty form. + Else `None`. Args: payment: The payment @@ -39,7 +39,7 @@ def payment_method_factory(payment, *args, creation=True, **kwargs): **kwargs: passed to the form Returns: - A form + A form or None """ payment_method = kwargs.pop('instance', find_payment_method(payment)) if payment_method is not None: @@ -50,8 +50,6 @@ def payment_method_factory(payment, *args, creation=True, **kwargs): ) elif creation: return PaymentMethodForm(*args, **kwargs) - else: - return forms.Form() class PaymentMethodForm(forms.Form): diff --git a/cotisations/views.py b/cotisations/views.py index c6403a1f..8b9fe79e 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -463,9 +463,11 @@ def edit_paiement(request, paiement_instance, **_kwargs): creation=False ) - if payment.is_valid() and payment_method.is_valid(): + if payment.is_valid() and \ + (payment_method is None or payment_method.is_valid()): payment.save() - payment_method.save() + if payment_method is not None: + payment_method.save() messages.success( request, _("The payement method has been successfully edited.")