Ejemplo n.º 1
0
	def clean(self):

		cleaned_data = Form.clean(self)

		content = cleaned_data.get('content')
		link = cleaned_data.get('link')

		if content and link: raise ValidationError({ 'content': _('El material debe tener al menos un link o documento, pero no ambos') })
		if not content and not link: raise ValidationError({ 'content': _('El material debe tener al menos un link o documento, pero no ambos') })
Ejemplo n.º 2
0
 def clean(self):
     cleaned_data = ModelForm.clean(self)
     if not self.instance.id:
         # Vérification username unique lors de la création
         first_name = cleaned_data.get("first_name")
         last_name = cleaned_data.get("last_name")
         username = slugify(last_name) + "." + slugify(first_name)
         if User.objects.filter(username=username).exists():
             msg = "Un propriétaire avec ce nom et ce prénom existe déjà, vous ne pouvez pas en créer un nouveau."
             self._errors["first_name"] = self.error_class([msg])
             del cleaned_data["first_name"]
     return cleaned_data
Ejemplo n.º 3
0
    def clean(self):
        from_acc_data = self.cleaned_data['from_acc']
        amount_data = self.cleaned_data['amount']
        to_acc_data = self.cleaned_data['to_acc']

        if amount_data < 0:
            raise ValidationError(
                _('Invalid Amount - Must be greater than or equal to 0'))

        if from_acc_data.acc_type.bal_type == 'D':
            # Check if from_acc has sufficient balance
            if from_acc_data.balance < amount_data:
                raise ValidationError(
                    _('Invalid From Account - Insufficient Funds'))

        if to_acc_data.acc_type.bal_type == 'C':
            # Check if from_acc has sufficient balance
            if to_acc_data.balance + amount_data > 0:
                raise ValidationError(_('Invalid To Account - Excess Funds'))

        ModelForm.clean(self)
Ejemplo n.º 4
0
    def clean(self):
        cleaned_data = ModelForm.clean(self)

        vaccine = cleaned_data.get("vaccine")
        if vaccine == OuiNonChoice.OUI.name:
            date_vaccin = cleaned_data.get("date_dernier_vaccin")
            if not date_vaccin:
                msg = ("Comme l'animal est vacciné, veuillez obligatoirement "
                       "indiquer la date du dernier vaccin")
                self._errors["date_dernier_vaccin"] = self.error_class([msg])
                del cleaned_data["date_dernier_vaccin"]

        return cleaned_data
Ejemplo n.º 5
0
 def clean(self):
     self.cleaned_data = ModelForm.clean(self)
     self.instance.clear_fields()
     for input in self.cleaned_data['layout'].inputs.all():
         all_data = self.data.copy()
         all_data.update(self.files)
         data = get_data_with_prefix(all_data, make_safe_input_name(input.name))
         field = input.field_model(input=input, **data)
         # field.page = self.instance
         try:
             field.full_clean()
         except ValidationError, e:
             # we should handle this
             raise e
         #field.save()
         self.layout_fields.setdefault('%s_%s' %(input.field_model._meta.app_label, input.field_model.__name__.lower()),[]).append(field)