Re: ModelForm "error_css_class" not getting applied to ValidationErrors raised in model.clean()

2019-07-16 Thread Melvyn Sopacua
On dinsdag 16 juli 2019 03:25:11 CEST Jacob Greene wrote:

> Hello! Has anyone dealt with this before? It seems that my forms don't add
> the CSS class to errors raised in model.clean() or model.clean_fields()
> methods.
> 
> I have a form that looks something like this:
> 
> class HttpsFaxBoxForm(forms.ModelForm):
> error_css_class = 'form_error'

> 
> And I run validation in my models(keep the admin page consistent) like this:

But your form is valid, so why should it apply error classes?
 
If you want to keep the admin page consistent, use the same form for admin, 
but your core problem is that you mix input validation (task of form) with 
data consistency (task of model). Keep those separated as much as possible and 
things will go smoother.
-- 
Melvyn Sopacua


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1743720.jJN2cR3phd%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: ModelForm "error_css_class" not getting applied to ValidationErrors raised in model.clean()

2019-07-16 Thread Jani Tiainen
Full_clean is Django internal method which you should't touch.

.clean() method validation errors go to special non-field errors and by
quick look it should get correct css class.

If you could provide minimal project with suspected faulty behavior (for
example in github) it would be easier to see if there is something wrong
there.

ti 16. heinäk. 2019 klo 15.32 Jacob Greene 
kirjoitti:

> Thank you for the reply! And good catch haha, I'm not actually. I editing
> these by hand so I wasn't posting some confusing telephony terminology. I'm
> displaying errors in my templates by marking them with that "form_error"
> css class. They are just red and bold, most errors are shown with the
> correct CSS class like my UniqueConstraints or any exceptions I throw in
> the modelForm clean() method, but any exceptions I throw in the
> Model.clean() or Model.full_clean() do not get the correct css class.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/82018028-f0d8-46f7-a542-1bd7b072b8e8%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91oc4Z9BONy7gP0B6wZrG2NG-OTogXkCTeORm0d274sxL7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelForm "error_css_class" not getting applied to ValidationErrors raised in model.clean()

2019-07-16 Thread Jacob Greene
Thank you for the reply! And good catch haha, I'm not actually. I editing these 
by hand so I wasn't posting some confusing telephony terminology. I'm 
displaying errors in my templates by marking them with that "form_error" css 
class. They are just red and bold, most errors are shown with the correct CSS 
class like my UniqueConstraints or any exceptions I throw in the modelForm 
clean() method, but any exceptions I throw in the Model.clean() or 
Model.full_clean() do not get the correct css class.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/82018028-f0d8-46f7-a542-1bd7b072b8e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelForm "error_css_class" not getting applied to ValidationErrors raised in model.clean()

2019-07-16 Thread Jani Tiainen
At least you should't call super.clean_fields() in clean() method...

Also how are you outputting errors in your template?


ti 16. heinäk. 2019 klo 5.22 Jacob Greene 
kirjoitti:

> Hello! Has anyone dealt with this before? It seems that my forms don't add
> the CSS class to errors raised in model.clean() or model.clean_fields()
> methods.
>
> I have a form that looks something like this:
>
> class HttpsFaxBoxForm(forms.ModelForm):
> error_css_class = 'form_error'
>
>
> class Meta:
> model = FaxBox
> fields = ('outbound_cid_profile', 'id')
>
>
>
> And I run validation in my models(keep the admin page consistent) like
> this:
>
> class FaxBox(models.Model):
>
> something = fields.CharField(max_length=100)
>
>
> def clean(self):
> if self.something == "shouldn't be here":
>
> raise ValidationError('This should not be here! Please fix!')
> super().clean_fields(exclude=None)
>
>
> But when this exception gets raised, the CSS class isn't applied to it in
> the template. Anyone know of a way to work around this? Thanks for reading!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8cfa5a86-ccaf-47f7-8b10-93fbaaaf4386%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91oc%3DSMymVzxKzv%2BjeZJKobc5PUrfwYMfAccVdqk-9GnQ5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


ModelForm "error_css_class" not getting applied to ValidationErrors raised in model.clean()

2019-07-15 Thread Jacob Greene
Hello! Has anyone dealt with this before? It seems that my forms don't add 
the CSS class to errors raised in model.clean() or model.clean_fields() 
methods. 

I have a form that looks something like this: 

class HttpsFaxBoxForm(forms.ModelForm):
error_css_class = 'form_error'


class Meta:
model = FaxBox
fields = ('outbound_cid_profile', 'id')



And I run validation in my models(keep the admin page consistent) like this:

class FaxBox(models.Model):

something = fields.CharField(max_length=100)


def clean(self):
if self.something == "shouldn't be here":

raise ValidationError('This should not be here! Please fix!')
super().clean_fields(exclude=None)


But when this exception gets raised, the CSS class isn't applied to it in 
the template. Anyone know of a way to work around this? Thanks for reading!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8cfa5a86-ccaf-47f7-8b10-93fbaaaf4386%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.