Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

validators.py 586 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
from django.forms import ValidationError
from django.utils.translation import ugettext as _


def check_no_balance(is_balance):
    """This functions checks that no Paiement with is_balance=True exists

    Args:
        is_balance: True if the model is balance.

    Raises:
        ValidationError: if such a Paiement exists.
    """
    from .models import Paiement
    if not is_balance:
        return
    p = Paiement.objects.filter(is_balance=True)
    if len(p) > 0:
        raise ValidationError(
20
            _("There is already a payment method for user balance.")
21
        )
22