Re: Form Validation Error NOT Raised When Form Is Submitted

2016-12-22 Thread Chris Kavanagh
I got it working Vijay! Thank you so much for your help, and have a great 
Christmas!!


On Thursday, December 22, 2016 at 9:55:05 PM UTC-5, Vijay Khemlani wrote:
>
> if the form is not valid then form.errors should contain human-readable 
> errors for each field, including the one you validate yourself (the string 
> inside the raise ValidationError call), you can return that.
>
> On Thu, Dec 22, 2016 at 11:49 PM, Chris Kavanagh  > wrote:
>
>> Yeah, I was wrong Vijay. For some odd reason I thought the 
>> ValidationError would catch it BEFORE submitted. . .
>>
>> I re-read the docs and saw I was wrong. .
>>
>> In other words, I I try to submit the form with the input field empty, I 
>> get a small pop up error saying "Please Enter An Email".
>>
>> Or, if I use an invalid email format, I get the same popup error saying 
>> "Please Enter An Email Address."
>>
>> Is there a way to do this with this (with django)?
>>
>> On Thursday, December 22, 2016 at 9:30:22 PM UTC-5, Vijay Khemlani wrote:
>>>
>>> I'm not following
>>>
>>> If you submit the form with incorrect information (non unique email) 
>>> then your view does not return anything because form.is_valid() returns 
>>> False
>>>
>>> Validation errors don't prevent the form from being submitted, they 
>>> prevent the form from validation (making form.is_valid() return False and 
>>> adding values to form.errors)
>>>
>>> On Thu, Dec 22, 2016 at 5:14 PM, Chris Kavanagh  
>>> wrote:
>>>
 I have a model form called *"ContactForm" *that has an email field. I 
 created a custom* forms.ValidationError* in *"clean_email"* method

  which checks to see if the email is already in the database , however 
 it's never raised on submit.


  When submit is called, the view runs and I get the error *"The view 
 customer.views.send_email didn't return an HttpResponse object.*

 * It returned None instead"*, because it's not being passed an actual 
 email. . 

 I don't understand why the *forms.ValidationError* isn't stopping it 
 from being submitted? The query in the *"clean_email"* works fine, so 
 that's not the problem.

 I've used this same code before with no problems. I'm sure it's 
 something easy I'm forgetting or missing, but any help is GREATLY 
 appreciated. .

 Note: I am using django crispy forms


 *#Model:*
 class Customer(models.Model):
 email = models.EmailField(max_length=70,blank=False)
 created = models.DateTimeField(auto_now_add=True)

 class Meta:
 ordering = ('email',)

 def __unicode__(self):
 return self.email




 *#Form:*
 class ContactForm(forms.ModelForm):

 class Meta:
 model = Customer
 fields = ['email']

 def clean_email(self):
 email = self.cleaned_data['email']
 cust_email = Customer.objects.filter(email=email).count()
 if cust_email:
 raise forms.ValidationError('This email is already in use.')
 return email




 *#View:*
 def send_email(request):
 if request.method == 'POST':
 form = ContactForm(request.POST)
 if form.is_valid():
 cd = form.cleaned_data
 email = cd['email']
 new_email = form.save(commit=True)
 to_email = form.cleaned_data['email']   # cd['email']
 subject = 'Newsletter'
 from_email = settings.EMAIL_HOST_USER
 message = 'You Are Now Signed Up For BenGui Newsletter!'
 #send_mail(subject, message, from_email, [to_email,], 
 fail_silently=False)
 return redirect('home')
 else:
 return render(request, 'home.html', context)



 *#customer.urls:*

 urlpatterns = [
 url(r'^send-email/$', views.send_email, name='send_email'),
 ]


 #Template:

 
 {% csrf_token %}
 {{ form|crispy }}
 >>> type='submit' value='Submit'>
 

 -- 
 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...@googlegroups.com.
 To post to this group, send email to django...@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/8ff5313f-3783-4897-afa7-5edd4fe1b436%40googlegroups.com
  
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>> -- 
>> You received this 

Re: Form Validation Error NOT Raised When Form Is Submitted

2016-12-22 Thread Vijay Khemlani
if the form is not valid then form.errors should contain human-readable
errors for each field, including the one you validate yourself (the string
inside the raise ValidationError call), you can return that.

On Thu, Dec 22, 2016 at 11:49 PM, Chris Kavanagh  wrote:

> Yeah, I was wrong Vijay. For some odd reason I thought the ValidationError
> would catch it BEFORE submitted. . .
>
> I re-read the docs and saw I was wrong. .
>
> In other words, I I try to submit the form with the input field empty, I
> get a small pop up error saying "Please Enter An Email".
>
> Or, if I use an invalid email format, I get the same popup error saying
> "Please Enter An Email Address."
>
> Is there a way to do this with this (with django)?
>
> On Thursday, December 22, 2016 at 9:30:22 PM UTC-5, Vijay Khemlani wrote:
>>
>> I'm not following
>>
>> If you submit the form with incorrect information (non unique email) then
>> your view does not return anything because form.is_valid() returns False
>>
>> Validation errors don't prevent the form from being submitted, they
>> prevent the form from validation (making form.is_valid() return False and
>> adding values to form.errors)
>>
>> On Thu, Dec 22, 2016 at 5:14 PM, Chris Kavanagh  wrote:
>>
>>> I have a model form called *"ContactForm" *that has an email field. I
>>> created a custom* forms.ValidationError* in *"clean_email"* method
>>>
>>>  which checks to see if the email is already in the database , however
>>> it's never raised on submit.
>>>
>>>
>>>  When submit is called, the view runs and I get the error *"The view
>>> customer.views.send_email didn't return an HttpResponse object.*
>>>
>>> * It returned None instead"*, because it's not being passed an actual
>>> email. .
>>>
>>> I don't understand why the *forms.ValidationError* isn't stopping it
>>> from being submitted? The query in the *"clean_email"* works fine, so
>>> that's not the problem.
>>>
>>> I've used this same code before with no problems. I'm sure it's
>>> something easy I'm forgetting or missing, but any help is GREATLY
>>> appreciated. .
>>>
>>> Note: I am using django crispy forms
>>>
>>>
>>> *#Model:*
>>> class Customer(models.Model):
>>> email = models.EmailField(max_length=70,blank=False)
>>> created = models.DateTimeField(auto_now_add=True)
>>>
>>> class Meta:
>>> ordering = ('email',)
>>>
>>> def __unicode__(self):
>>> return self.email
>>>
>>>
>>>
>>>
>>> *#Form:*
>>> class ContactForm(forms.ModelForm):
>>>
>>> class Meta:
>>> model = Customer
>>> fields = ['email']
>>>
>>> def clean_email(self):
>>> email = self.cleaned_data['email']
>>> cust_email = Customer.objects.filter(email=email).count()
>>> if cust_email:
>>> raise forms.ValidationError('This email is already in use.')
>>> return email
>>>
>>>
>>>
>>>
>>> *#View:*
>>> def send_email(request):
>>> if request.method == 'POST':
>>> form = ContactForm(request.POST)
>>> if form.is_valid():
>>> cd = form.cleaned_data
>>> email = cd['email']
>>> new_email = form.save(commit=True)
>>> to_email = form.cleaned_data['email']   # cd['email']
>>> subject = 'Newsletter'
>>> from_email = settings.EMAIL_HOST_USER
>>> message = 'You Are Now Signed Up For BenGui Newsletter!'
>>> #send_mail(subject, message, from_email, [to_email,],
>>> fail_silently=False)
>>> return redirect('home')
>>> else:
>>> return render(request, 'home.html', context)
>>>
>>>
>>>
>>> *#customer.urls:*
>>>
>>> urlpatterns = [
>>> url(r'^send-email/$', views.send_email, name='send_email'),
>>> ]
>>>
>>>
>>> #Template:
>>>
>>> 
>>> {% csrf_token %}
>>> {{ form|crispy }}
>>> >> type='submit' value='Submit'>
>>> 
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/ms
>>> gid/django-users/8ff5313f-3783-4897-afa7-5edd4fe1b436%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 

Re: Form Validation Error NOT Raised When Form Is Submitted

2016-12-22 Thread Chris Kavanagh
Yeah, I was wrong Vijay. For some odd reason I thought the ValidationError 
would catch it BEFORE submitted. . .

I re-read the docs and saw I was wrong. .

In other words, I I try to submit the form with the input field empty, I 
get a small pop up error saying "Please Enter An Email".

Or, if I use an invalid email format, I get the same popup error saying 
"Please Enter An Email Address."

Is there a way to do this with this (with django)?

On Thursday, December 22, 2016 at 9:30:22 PM UTC-5, Vijay Khemlani wrote:
>
> I'm not following
>
> If you submit the form with incorrect information (non unique email) then 
> your view does not return anything because form.is_valid() returns False
>
> Validation errors don't prevent the form from being submitted, they 
> prevent the form from validation (making form.is_valid() return False and 
> adding values to form.errors)
>
> On Thu, Dec 22, 2016 at 5:14 PM, Chris Kavanagh  > wrote:
>
>> I have a model form called *"ContactForm" *that has an email field. I 
>> created a custom* forms.ValidationError* in *"clean_email"* method
>>
>>  which checks to see if the email is already in the database , however 
>> it's never raised on submit.
>>
>>
>>  When submit is called, the view runs and I get the error *"The view 
>> customer.views.send_email didn't return an HttpResponse object.*
>>
>> * It returned None instead"*, because it's not being passed an actual 
>> email. . 
>>
>> I don't understand why the *forms.ValidationError* isn't stopping it 
>> from being submitted? The query in the *"clean_email"* works fine, so 
>> that's not the problem.
>>
>> I've used this same code before with no problems. I'm sure it's something 
>> easy I'm forgetting or missing, but any help is GREATLY appreciated. .
>>
>> Note: I am using django crispy forms
>>
>>
>> *#Model:*
>> class Customer(models.Model):
>> email = models.EmailField(max_length=70,blank=False)
>> created = models.DateTimeField(auto_now_add=True)
>>
>> class Meta:
>> ordering = ('email',)
>>
>> def __unicode__(self):
>> return self.email
>>
>>
>>
>>
>> *#Form:*
>> class ContactForm(forms.ModelForm):
>>
>> class Meta:
>> model = Customer
>> fields = ['email']
>>
>> def clean_email(self):
>> email = self.cleaned_data['email']
>> cust_email = Customer.objects.filter(email=email).count()
>> if cust_email:
>> raise forms.ValidationError('This email is already in use.')
>> return email
>>
>>
>>
>>
>> *#View:*
>> def send_email(request):
>> if request.method == 'POST':
>> form = ContactForm(request.POST)
>> if form.is_valid():
>> cd = form.cleaned_data
>> email = cd['email']
>> new_email = form.save(commit=True)
>> to_email = form.cleaned_data['email']   # cd['email']
>> subject = 'Newsletter'
>> from_email = settings.EMAIL_HOST_USER
>> message = 'You Are Now Signed Up For BenGui Newsletter!'
>> #send_mail(subject, message, from_email, [to_email,], 
>> fail_silently=False)
>> return redirect('home')
>> else:
>> return render(request, 'home.html', context)
>>
>>
>>
>> *#customer.urls:*
>>
>> urlpatterns = [
>> url(r'^send-email/$', views.send_email, name='send_email'),
>> ]
>>
>>
>> #Template:
>>
>> 
>> {% csrf_token %}
>> {{ form|crispy }}
>> > type='submit' value='Submit'>
>> 
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/8ff5313f-3783-4897-afa7-5edd4fe1b436%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/39ec5818-92b6-4b2c-ad9a-58e09acd5427%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Form Validation Error NOT Raised When Form Is Submitted

2016-12-22 Thread Vijay Khemlani
I'm not following

If you submit the form with incorrect information (non unique email) then
your view does not return anything because form.is_valid() returns False

Validation errors don't prevent the form from being submitted, they prevent
the form from validation (making form.is_valid() return False and adding
values to form.errors)

On Thu, Dec 22, 2016 at 5:14 PM, Chris Kavanagh  wrote:

> I have a model form called *"ContactForm" *that has an email field. I
> created a custom* forms.ValidationError* in *"clean_email"* method
>
>  which checks to see if the email is already in the database , however
> it's never raised on submit.
>
>
>  When submit is called, the view runs and I get the error *"The view
> customer.views.send_email didn't return an HttpResponse object.*
>
> * It returned None instead"*, because it's not being passed an actual
> email. .
>
> I don't understand why the *forms.ValidationError* isn't stopping it from
> being submitted? The query in the *"clean_email"* works fine, so that's
> not the problem.
>
> I've used this same code before with no problems. I'm sure it's something
> easy I'm forgetting or missing, but any help is GREATLY appreciated. .
>
> Note: I am using django crispy forms
>
>
> *#Model:*
> class Customer(models.Model):
> email = models.EmailField(max_length=70,blank=False)
> created = models.DateTimeField(auto_now_add=True)
>
> class Meta:
> ordering = ('email',)
>
> def __unicode__(self):
> return self.email
>
>
>
>
> *#Form:*
> class ContactForm(forms.ModelForm):
>
> class Meta:
> model = Customer
> fields = ['email']
>
> def clean_email(self):
> email = self.cleaned_data['email']
> cust_email = Customer.objects.filter(email=email).count()
> if cust_email:
> raise forms.ValidationError('This email is already in use.')
> return email
>
>
>
>
> *#View:*
> def send_email(request):
> if request.method == 'POST':
> form = ContactForm(request.POST)
> if form.is_valid():
> cd = form.cleaned_data
> email = cd['email']
> new_email = form.save(commit=True)
> to_email = form.cleaned_data['email']   # cd['email']
> subject = 'Newsletter'
> from_email = settings.EMAIL_HOST_USER
> message = 'You Are Now Signed Up For BenGui Newsletter!'
> #send_mail(subject, message, from_email, [to_email,],
> fail_silently=False)
> return redirect('home')
> else:
> return render(request, 'home.html', context)
>
>
>
> *#customer.urls:*
>
> urlpatterns = [
> url(r'^send-email/$', views.send_email, name='send_email'),
> ]
>
>
> #Template:
>
> 
> {% csrf_token %}
> {{ form|crispy }}
>  type='submit' value='Submit'>
> 
>
> --
> 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/8ff5313f-3783-4897-afa7-5edd4fe1b436%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/CALn3ei1L-1Lc%2BEst-c9nfJR%3DE8Rk2pZHwRssCXgtWRNpzXHBWg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Mike Dewhirst

On 1/09/2013 2:11am, Gerd Koetje wrote:

to explain myself a bit more:

gerd12 = should be valid
gerd1234   = should be valid
gerd 1234 = should not be valid
%$$%%#$ = should not be valid
gerd123456 - should not be valid


You have just specified five cases for unit tests. Start there and 
experiment with re until they all pass. Beautiful!




etc etc

--
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


--
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje
i gues im learning it the hard way atm.
Just wanna convert my php application to python, but its hard when i miss 
out on some basic stuff. giving me headpains haha :D

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje
yeah i really should do more python learning.
and i will do :D

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje
stupid me, its almost like php

 if testdata == False:
>

fixed it



Thanks alot for your help all.
Appreciated 

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Thomas Orozco
test(data) returns True if the string is acceptable, and False if it's not.

But False is an object, it's not the the string "False" - I'd strongly
recommend you start with a Python tutorial before moving on to your Django
project.

Cheers;


On Sat, Aug 31, 2013 at 7:27 PM, Gerd Koetje wrote:

> think i fixed the true/false thing, return True was on the wrong indent
>
> it still doesnt trow the error , so i gues my if testdata us False:  is
> wrong?
>
> --
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje
think i fixed the true/false thing, return True was on the wrong indent

it still doesnt trow the error , so i gues my if testdata us False:  is 
wrong?

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Thomas Orozco
Because the indentation is not correct, and doesn't correspond to what I
sent you.

`return True` should be 4 chars left of where it currently is.


On Sat, Aug 31, 2013 at 7:23 PM, Gerd Koetje wrote:

> it somehow keeps returning True on everything
>
> accepted = string.letters + string.digits
> max_numbers = 4
>
>
> def test(word):
> numbers = 0
> for c in word:
> if c.isdigit():
> numbers += 1
> if not c in accepted or numbers > max_numbers:
>return False
> return True
>
> # profielnaam
> class ProfielenForm(forms.ModelForm):
>
>
> def clean_profielnaam(self):
>
> logger.debug('>>>FORMS< %s', accepted)
>
>
> data = self.cleaned_data['profielnaam']
> testdata = test(data)
> logger.debug('>>>FORMS<< >DATA< %s',
> testdata)
>
> if testdata is "False":
> raise forms.ValidationError("Je mag alleen tekst en cijfers
> gebruiken en geen spaties")
>
> return data
>
> class Meta:
> model = Profielen
> fields = ('profielnaam',)
>
> --
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje
it somehow keeps returning True on everything

accepted = string.letters + string.digits
max_numbers = 4


def test(word):
numbers = 0
for c in word:
if c.isdigit():
numbers += 1
if not c in accepted or numbers > max_numbers:
   return False
return True

# profielnaam
class ProfielenForm(forms.ModelForm):


def clean_profielnaam(self):

logger.debug('>>>FORMS< %s', accepted)


data = self.cleaned_data['profielnaam']
testdata = test(data)
logger.debug('>>>FORMS<< >DATA< %s', 
testdata)

if testdata is "False":
raise forms.ValidationError("Je mag alleen tekst en cijfers 
gebruiken en geen spaties")

return data

class Meta:
model = Profielen
fields = ('profielnaam',)

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje
like this?


import string
accepted = string.letters + string.digits
max_numbers = 4

def test(word):
numbers = 0
for c in word:
if c.isdigit():
numbers += 1
if not c in accepted or numbers > max_numbers:
   return False
return True

# Create profiel

# profielnaam
class ProfielenForm(forms.ModelForm):




def clean_profielnaam(self):
data = self.cleaned_data['profielnaam']
if test(data) is False:
raise forms.ValidationError("Je mag alleen tekst en cijfers 
gebruiken en geen spaties")

return data

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Thomas Orozco
Oh, I thought you needed only 4 total chars.


Using a regex probably is a bit overkill here:

>>> import string
>>> accepted = string.letters + string.digits
>>> max_numbers = 4
>>>
>>> def test(word):
... numbers = 0
... for c in word:
... if c.isdigit():
... numbers += 1
... if not c in accepted or numbers > max_numbers:
... return False
... return True
...
>>>
>>> test('gerd12')
True
>>> test('gerd1234')
True
>>> test('gerd 1234 ')
False
>>> test('gerd 1234')
False
>>> test('%$$%%#$')
False
>>> test('gerd123456')
False



On Sat, Aug 31, 2013 at 6:11 PM, Gerd Koetje wrote:

> to explain myself a bit more:
>
> gerd12 = should be valid
> gerd1234   = should be valid
> gerd 1234 = should not be valid
> %$$%%#$ = should not be valid
> gerd123456 - should not be valid
>
> etc etc
>
> --
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje
im working with this code in my forms.py btw.
I see some guys do it in models.py instead

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje
to explain myself a bit more:

gerd12 = should be valid
gerd1234   = should be valid
gerd 1234 = should not be valid
%$$%%#$ = should not be valid
gerd123456 - should not be valid

etc etc

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje

>
> same result still can input spaces weird chars and more then 4 numbers
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Thomas Orozco
Oh, yes, we need to search for the end of the string:

r'^[a-zA-Z0-9]{1,4}$'


On Sat, Aug 31, 2013 at 6:03 PM, Gerd Koetje wrote:

> that still allows space,weird chars and more then 4 numbers
>
> input:
> dfdfdf565665&^^^ 
> got saved
>
>
>
> def clean_profielnaam(self):
> data = self.cleaned_data['profielnaam']
> if not re.match(r'^[a-zA-Z0-9]{1,4}', data):
> raise forms.ValidationError("Je mag alleen tekst en cijfers
> gebruiken en geen spaties")
>
> return data
>
> --
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje
that still allows space,weird chars and more then 4 numbers

input: 
dfdfdf565665&^^^ 
got saved



def clean_profielnaam(self):
data = self.cleaned_data['profielnaam']
if not re.match(r'^[a-zA-Z0-9]{1,4}', data):
raise forms.ValidationError("Je mag alleen tekst en cijfers 
gebruiken en geen spaties")

return data

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Thomas Orozco
Change you regex to: r'^[a-zA-Z0-9]{1,4}'


On Sat, Aug 31, 2013 at 5:41 PM, Gerd Koetje wrote:

> Hi all,
>
> How do i valididate for this?
>
> - numbers and text only , no spaces
> - max 4 number
>
>
>
>
> def clean_profielnaam(self):
> data = self.cleaned_data['profielnaam']
> if not re.match(r'^[a-z][0-9]+', data):
> raise forms.ValidationError("Je mag alleen tekst en cijfers
> gebruiken en geen spaties")
>
> return data
>
>  --
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Form validation vs. DRY

2013-07-03 Thread Roman Klesel
2013/7/3 Tomas Ehrlich :

> you can use model validation
> https://docs.djangoproject.com/en/dev/ref/models/instances/#validating-objects


This sounds very good! :-)

Thanks!

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Form validation vs. DRY

2013-07-03 Thread Tomas Ehrlich
Hi Roman,
you can use model validation
https://docs.djangoproject.com/en/dev/ref/models/instances/#validating-objects

It works similar to form validation. After, when you create ModelForm,
it will take validation rules from model.

All these validations should be called outside save()


Cheers,
  Tom

Dne Wed, 3 Jul 2013 10:21:51 +0200
Roman Klesel  napsal(a):

> Hello,
> 
> I'm programming a database front end. In many cases I want to
> constrain the data written to the database. Therefore I implement some
> checks either through real database constraints or trough some logic
> in the model, so it will throw an exception when the constraints are
> not met.
> 
> e.g.: unique constraint on a database column.
> 
> Now, when I write my form validation, I have to implement the same
> logic again, since form validation takes place before a save() is even
> considered. Like this:
> 
> >>> if form.is_valid():
> >>>form.save()
> 
> Is there a better way to do it? Is there a good way to avoid this
> duplicate logic?
> 
> Regards
>   Roman
> 

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: form validation

2013-05-11 Thread Roberto López López

Problem solved with BaseInlineFormSet.clean() :-)




On 05/11/2013 06:56 PM, Roberto López López wrote:
>
> Hi everyone,
>
> I need to do some validation in my model. So far, I have been able to
> validate normal forms, but I want to validate forms with an inline, to
> ensure that at least one of those inlines match the requirement.
>
> My code:
>
> class PDMAdminForm(ModelForm):
> class Meta:
> model = PersonDepartmentMembership
>
> def clean(self):
> previous_leaders = []
> if self.instance:  # the instance is already on the db
> previous_leaders =
> self.instance.department.employee_memberships.filter(lead__exact=True)
> lead = self.cleaned_data['lead'] # access fields from the
> form itself
> # do some validations and eventually throw
> ValidationErrrors [...]
> return self.cleaned_data
>
> This works great for a single inline. But if I have several
> PersonDepartmentMembership instances to be created, I don't know how
> to check the value of those other (I just want to ensure that at least
> one fo them has lead==True).
>
> Does anyone know how to do this cross validation? Thank you very much
> for your suggestions.
>
> Regards,
>
> Roberto
>
>
> -- 
> 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 http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Branko Majic
On Fri, 3 May 2013 15:31:05 +0100
Darren Mansell  wrote:

> I had rsync'd the code onto the live server from /home/django/rfc/
> into /home/django/rfc/rfc. As it's inside the pythonpath, the code is
> still valid and will be executed, especially when you have various
> stuff in the same dir names as your app etc.

A friendly suggestion would be to start using a git/hg/any other
distributed version control system instead of rsync.

Although it might seem to look like a bit of a hassle, and there's a
learning curve involved, it will really save you a lot of trouble
related to file management.

And with DVCS you don't really even need a central server to have it
functioning ok.

Best regards

P.S.
Sorry if you already knew all this, but might be good for any newbie
people out there to run into these suggestions from time to time :)

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.


signature.asc
Description: PGP signature


Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Darren Mansell
Solved.

To anyone who may come across this very obscure issue for themselves, it's
entirely an error specific to my setup.

I had rsync'd the code onto the live server from /home/django/rfc/ into
/home/django/rfc/rfc. As it's inside the pythonpath, the code is still
valid and will be executed, especially when you have various stuff in the
same dir names as your app etc.

I grep'd through the django code and found that only BooleanField gave my
specific error and I only didn't have BooleanField anymore. So I did a grep
of my code on live and found my old models.py file buried underneath
everything, which did have the fields as BooleanField.

Wow. 2 whole days to find that.


On 3 May 2013 13:49, Darren Mansell  wrote:

>
>
>
> On 3 May 2013 13:06, Tom Evans  wrote:
>
>> On Fri, May 3, 2013 at 12:38 PM, Darren Mansell
>>  wrote:
>> >
>> > Another bit of info, just in case anyone is currently looking at this..
>> >
>> > The error is coming from
>> >
>> /usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py
>> >
>> > …
>> >
>> > So it's failing validation because it's seeing the field as a
>> > BooleanField, when I quite obviously have set it as a CharField.
>> >
>> > I'm absolutely stuck.
>>
>> In your second mail, you say that the only failing case is "live
>> server with Apache 2.2.22-1ubuntu1.3 / mod-wsgi 3.3-4build1". Are you
>> sure you have fully updated and restarted this server to pick up your
>> changes?
>>
>> Cheers
>>
>> Tom
>>
>> Hey Tom, thanks for the reply.
>
> Yeah the live server is Ubuntu 12.04 and the dev server is actually my
> laptop running Ubuntu 13.10 which accounts for the version differences.
>
> I'm rsyncing files from one to the other and have checked the code gets
> copied which it does.
>
> I'm now thinking that because I've got another copy of this project
> running on the server, but with older code, it's failing with that.
>
> I'll clone the VM and run it fully separate.
>
> Thanks.
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Darren Mansell
On 3 May 2013 13:06, Tom Evans  wrote:

> On Fri, May 3, 2013 at 12:38 PM, Darren Mansell
>  wrote:
> >
> > Another bit of info, just in case anyone is currently looking at this..
> >
> > The error is coming from
> >
> /usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py
> >
> > …
> >
> > So it's failing validation because it's seeing the field as a
> > BooleanField, when I quite obviously have set it as a CharField.
> >
> > I'm absolutely stuck.
>
> In your second mail, you say that the only failing case is "live
> server with Apache 2.2.22-1ubuntu1.3 / mod-wsgi 3.3-4build1". Are you
> sure you have fully updated and restarted this server to pick up your
> changes?
>
> Cheers
>
> Tom
>
> Hey Tom, thanks for the reply.

Yeah the live server is Ubuntu 12.04 and the dev server is actually my
laptop running Ubuntu 13.10 which accounts for the version differences.

I'm rsyncing files from one to the other and have checked the code gets
copied which it does.

I'm now thinking that because I've got another copy of this project running
on the server, but with older code, it's failing with that.

I'll clone the VM and run it fully separate.

Thanks.

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Tom Evans
On Fri, May 3, 2013 at 12:38 PM, Darren Mansell
 wrote:
>
> Another bit of info, just in case anyone is currently looking at this..
>
> The error is coming from
> /usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py
>
> …
>
> So it's failing validation because it's seeing the field as a
> BooleanField, when I quite obviously have set it as a CharField.
>
> I'm absolutely stuck.

In your second mail, you say that the only failing case is "live
server with Apache 2.2.22-1ubuntu1.3 / mod-wsgi 3.3-4build1". Are you
sure you have fully updated and restarted this server to pick up your
changes?

Cheers

Tom

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Darren Mansell
Another bit of info, just in case anyone is currently looking at this..

The error is coming from
/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py

class BooleanField(Field):
empty_strings_allowed = False
default_error_messages = {
*'invalid': _("'%s' value must be either True or False."),*
}
description = _("Boolean (Either True or False)")

def __init__(self, *args, **kwargs):
kwargs['blank'] = True
if 'default' not in kwargs and not kwargs.get('null'):
kwargs['default'] = False
Field.__init__(self, *args, **kwargs)

def get_internal_type(self):
return "BooleanField"

def to_python(self, value):
if value in (True, False):
# if value is 1 or 0 than it's equal to True or False, but we
want
# to return a true bool for semantic reasons.
return bool(value)
if value in ('t', 'True', '1'):
return True
if value in ('f', 'False', '0'):
return False
*msg = self.error_messages['invalid'] % value*
raise exceptions.ValidationError(msg)


So it's failing validation because it's seeing the field as a BooleanField,
when I quite obviously have set it as a CharField.

I'm absolutely stuck.

On 3 May 2013 11:13, Darren Mansell  wrote:

> Bit more info (all pointing to the same database / db server):
>
> test server with Django dev server : works
> test server with Apache 2.2.22-6ubuntu5 / mod-wsgi 3.4-0ubuntu3 : works
>
> live server with Django dev server : works
> live server with Apache 2.2.22-1ubuntu1.3 / mod-wsgi 3.3-4build1 : doesn't
> work
>
>
>
>
> On 3 May 2013 10:35, Darren Mansell  wrote:
>
>> Hi all. Really really confused by this one. Can someone show me where I'm
>> being stupid please?
>>
>> Standard Django 1.5.1 app with MySQL. Trying to save to a VARCHAR(3)
>> column with a forms.CharField form field and a models.CharField model field.
>>
>> When I try to save the form I get this validation error:
>>
>> [image: Inline images 1]
>>
>>
>> This is the MySQL column definition:
>>
>> `customers_impacted` varchar(3) DEFAULT NULL,
>>
>>
>> This is from forms.py (it's a ModelForm):
>>
>> YES_NO = (
>> ('No', 'No'),
>> ('Yes', 'Yes'),
>> )
>> customers_impacted =
>> forms.CharField(widget=forms.Select(choices=YES_NO),max_length=3)
>>
>>
>> This is from models.py:
>>
>> customers_impacted = models.CharField(max_length=3)
>>
>>
>> The field was originally a BooleanField but I changed it to CharField and
>> I can't see anywhere it could still be getting the Boolean / True / False
>> info from.
>>
>> Strangely, it works fine using the development server, but this error
>> happens when using Apache + mod_wsgi. I've rebooted the server, restarted
>> everything, tried changing collation etc.
>>
>> Could anyone suggest anything? Any extra logging etc I can turn on
>> somewhere to show where the validation is failing?
>>
>> Thanks.
>> Darren (confused)
>>
>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


<>

Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Darren Mansell
Bit more info (all pointing to the same database / db server):

test server with Django dev server : works
test server with Apache 2.2.22-6ubuntu5 / mod-wsgi 3.4-0ubuntu3 : works

live server with Django dev server : works
live server with Apache 2.2.22-1ubuntu1.3 / mod-wsgi 3.3-4build1 : doesn't
work



On 3 May 2013 10:35, Darren Mansell  wrote:

> Hi all. Really really confused by this one. Can someone show me where I'm
> being stupid please?
>
> Standard Django 1.5.1 app with MySQL. Trying to save to a VARCHAR(3)
> column with a forms.CharField form field and a models.CharField model field.
>
> When I try to save the form I get this validation error:
>
> [image: Inline images 1]
>
>
> This is the MySQL column definition:
>
> `customers_impacted` varchar(3) DEFAULT NULL,
>
>
> This is from forms.py (it's a ModelForm):
>
> YES_NO = (
> ('No', 'No'),
> ('Yes', 'Yes'),
> )
> customers_impacted =
> forms.CharField(widget=forms.Select(choices=YES_NO),max_length=3)
>
>
> This is from models.py:
>
> customers_impacted = models.CharField(max_length=3)
>
>
> The field was originally a BooleanField but I changed it to CharField and
> I can't see anywhere it could still be getting the Boolean / True / False
> info from.
>
> Strangely, it works fine using the development server, but this error
> happens when using Apache + mod_wsgi. I've rebooted the server, restarted
> everything, tried changing collation etc.
>
> Could anyone suggest anything? Any extra logging etc I can turn on
> somewhere to show where the validation is failing?
>
> Thanks.
> Darren (confused)
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


<>

RE: Form validation

2013-01-12 Thread Babatunde Akinyanmi
Over ride the post method of your wizard class. There you can call
get_all_cleaned_data or get_cleaned_data_for_step. Use the default
implementation and adjust it to work according to you logic. From your post
method you can raise ValidationError but it will crash the app. If you want
the normal form behavior where ValidationError will render the form with
the error at the top, you will need to do that in your form's clean method.

Sent from my Windows Phone
--
From: Kristofer
Sent: 1/11/2013 4:48 PM
To: Babatunde Akinyanmi
Cc: django-users@googlegroups.com
Subject: Re: Form validation

More details on the form and why there is a field that depends on 6 pages:

In steps 2-5, I am prompting the user for questions and choices about a
particular service.

On page 6 they are given the opportunity to select a date/time for the
service. The validation will calculate how how much time is required based
on steps 2-5 and see if the time they pick fits in the calendar. If it
doesn't, it will ask them to pick a different time.

I'm still not sure where I can use it, because I can't call
get_cleaned_data_for_step from the forms validation/clean field, and I'm
not sure where else I can access the required form steps and also be able
to raise a validation error.


--
*From: *"Babatunde Akinyanmi" <tundeba...@gmail.com>
*To: *"Kristofer" <kristo...@cybernetik.net>, django-users@googlegroups.com
*Sent: *Friday, January 11, 2013 8:05:59 AM
*Subject: *RE: Form validation

Hi,
You can use the wizard's get_cleaned_data_for_step(step) method where step
is 0-indexed so step 2 form data would be:
get_cleaned_data_for_step('1').
It would return a dictionary of the cleaned data for that step.

Ignorable comment: I would be very pissed if I had to fill 6 form pages
only to be told I can't continue because of something I did 4 pages ago.

Sent from my Windows Phone
--
From: Kristofer
Sent: 1/11/2013 8:00 AM
To: django-users@googlegroups.com
Subject: Form validation

Hello,

I am using FormWizard with a 12-step form.

On step 6, I want to perform verification on a field but it depends on
fields that were entered in steps 2-5.

I cannot figure out how to get data from the previous steps in the form
validation for step 6.

Where is a point in the FormWizard where I can access previous form data
and can also raise ValidationError on a field?

Thanks,

 --
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation

2013-01-11 Thread Kristofer
More details on the form and why there is a field that depends on 6 pages: 

In steps 2-5, I am prompting the user for questions and choices about a 
particular service. 

On page 6 they are given the opportunity to select a date/time for the service. 
The validation will calculate how how much time is required based on steps 2-5 
and see if the time they pick fits in the calendar. If it doesn't, it will ask 
them to pick a different time. 

I'm still not sure where I can use it, because I can't call 
get_cleaned_data_for_step from the forms validation/clean field, and I'm not 
sure where else I can access the required form steps and also be able to raise 
a validation error. 


- Original Message -

From: "Babatunde Akinyanmi" <tundeba...@gmail.com> 
To: "Kristofer" <kristo...@cybernetik.net>, django-users@googlegroups.com 
Sent: Friday, January 11, 2013 8:05:59 AM 
Subject: RE: Form validation 

Hi, 
You can use the wizard's get_cleaned_data_for_step(step) method where step is 
0-indexed so step 2 form data would be: 
get_cleaned_data_for_step('1'). 
It would return a dictionary of the cleaned data for that step. 

Ignorable comment: I would be very pissed if I had to fill 6 form pages only to 
be told I can't continue because of something I did 4 pages ago. 

Sent from my Windows Phone 

From: Kristofer 
Sent: 1/11/2013 8:00 AM 
To: django-users@googlegroups.com 
Subject: Form validation 

Hello, 

I am using FormWizard with a 12-step form. 

On step 6, I want to perform verification on a field but it depends on fields 
that were entered in steps 2-5. 

I cannot figure out how to get data from the previous steps in the form 
validation for step 6. 

Where is a point in the FormWizard where I can access previous form data and 
can also raise ValidationError on a field? 

Thanks, 



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group. 
To post to this group, send email to django-users@googlegroups.com . 
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com . 
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en . 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



RE: Form validation

2013-01-11 Thread Babatunde Akinyanmi
Hi,
You can use the wizard's get_cleaned_data_for_step(step) method where step
is 0-indexed so step 2 form data would be:
get_cleaned_data_for_step('1').
It would return a dictionary of the cleaned data for that step.

Ignorable comment: I would be very pissed if I had to fill 6 form pages
only to be told I can't continue because of something I did 4 pages ago.

Sent from my Windows Phone
--
From: Kristofer
Sent: 1/11/2013 8:00 AM
To: django-users@googlegroups.com
Subject: Form validation

Hello,

I am using FormWizard with a 12-step form.

On step 6, I want to perform verification on a field but it depends on
fields that were entered in steps 2-5.

I cannot figure out how to get data from the previous steps in the form
validation for step 6.

Where is a point in the FormWizard where I can access previous form data
and can also raise ValidationError on a field?

Thanks,

 --
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation

2013-01-11 Thread iñigo medina
El 11/01/2013 08:00, "Kristofer"  escribió:
>
>
> On step 6, I want to perform verification on a field but it depends on
fields that were entered in steps 2-5.

Do you save such data anywhere (database, session...)? You might get from
this source and use as you need.

Iñigo

>
> I cannot figure out how to get data from the previous steps in the form
validation for step 6.
>
> Where is a point in the FormWizard where I can access previous form data
and can also raise ValidationError on a field?
>
> Thanks,
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation using model data?

2012-07-31 Thread Kurtis Mullins
ahh okay,

then I simply create two model forms.

class CreateURLForm(ModelForm):
class Meta:
fields = ('url', 'name') # This will restrict the user to only
modifying this data
model = URLModel # Or whatever your model is called

class UpdateURLForm(ModelForm):
class Meta:
fields = ('name',) # Restrict user only to modifying the name
model = URLModel

On Mon, Jul 30, 2012 at 5:00 PM, Paul  wrote:

> That would be an option as well indeed. In fact i have 1 (base)-form for
> the model that i subclass for create, read and update operations. The
> difference is that create and update have a submit button, read doesn't,
> and in the read view, the fields are read-only.
>
> The website becomes authenticated using a background process, the idea is
> that as soon as it becomes authenticated the url cannot be changed any more.
>
> I have tested with readonly=True which works correctly apart from the fact
> that i don't think it's safe to only make the field readonly, i want to add
> some logic in the post-logic as well (so for example using custom
> validation).
>
> A simpler alternative is to remove the 'update' button altogether, but
> also in this case the view should also throw a 404 or 500 just in case
> someone manually modifies the url (which is by the way very easy to do
> so).
>
> Paul
>
>
>
> Op maandag 30 juli 2012 00:00:48 UTC+2 schreef Kurtis het volgende:
>>
>> Just to get some more information about the problem; Do you allow your
>> users to initially insert the Name+URL? When does this become
>> "authenticated"?
>>
>> Maybe you could have two forms. One that allows users to add new Name+URL
>> Objects (not sure what your object/Model is called) and another to allow
>> them to edit (Using Django's 'fields' meta attribute to limit them to only
>> modify the "Name" of the object)
>>
>> On Sun, Jul 29, 2012 at 5:47 PM, Paul wrote:
>>
>>> I have a model for Websites that has 3 fields: name, url and
>>> authenticated. With a form both the name and url can be changed, but when
>>> the website is authenticated i don't want to allow that the url changes.
>>>
>>> I'm thinking about making the url (form) field readonly but in html the
>>> field becomes still an input field (just with readonly="True"), so i have
>>> doubts whether hackers will be able to post a changed value anyhow (i'll
>>> need to test this).
>>>
>>> Another approach is to add some custom form validation against the
>>> (current) model, but i have doubts whether validation is the solution for
>>> this?
>>>
>>> Thanks for any directions
>>> Paul
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To view this discussion on the web visit https://groups.google.com/d/**
>>> msg/django-users/-/**urE06kkuNBIJ
>>> .
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to django-users+unsubscribe@*
>>> *googlegroups.com .
>>> For more options, visit this group at http://groups.google.com/**
>>> group/django-users?hl=en
>>> .
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/xn9xV2ukteUJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation using model data?

2012-07-30 Thread Paul
That would be an option as well indeed. In fact i have 1 (base)-form for 
the model that i subclass for create, read and update operations. The 
difference is that create and update have a submit button, read doesn't, 
and in the read view, the fields are read-only.

The website becomes authenticated using a background process, the idea is 
that as soon as it becomes authenticated the url cannot be changed any more.

I have tested with readonly=True which works correctly apart from the fact 
that i don't think it's safe to only make the field readonly, i want to add 
some logic in the post-logic as well (so for example using custom 
validation).

A simpler alternative is to remove the 'update' button altogether, but also 
in this case the view should also throw a 404 or 500 just in case someone 
manually modifies the url (which is by the way very easy to do so).

Paul



Op maandag 30 juli 2012 00:00:48 UTC+2 schreef Kurtis het volgende:
>
> Just to get some more information about the problem; Do you allow your 
> users to initially insert the Name+URL? When does this become 
> "authenticated"?
>
> Maybe you could have two forms. One that allows users to add new Name+URL 
> Objects (not sure what your object/Model is called) and another to allow 
> them to edit (Using Django's 'fields' meta attribute to limit them to only 
> modify the "Name" of the object)
>
> On Sun, Jul 29, 2012 at 5:47 PM, Paul wrote:
>
>> I have a model for Websites that has 3 fields: name, url and 
>> authenticated. With a form both the name and url can be changed, but when 
>> the website is authenticated i don't want to allow that the url changes.
>>
>> I'm thinking about making the url (form) field readonly but in html the 
>> field becomes still an input field (just with readonly="True"), so i have 
>> doubts whether hackers will be able to post a changed value anyhow (i'll 
>> need to test this).
>>
>> Another approach is to add some custom form validation against the 
>> (current) model, but i have doubts whether validation is the solution for 
>> this?
>>
>> Thanks for any directions
>> Paul
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/urE06kkuNBIJ.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/xn9xV2ukteUJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation using model data?

2012-07-29 Thread Kurtis Mullins
Just to get some more information about the problem; Do you allow your
users to initially insert the Name+URL? When does this become
"authenticated"?

Maybe you could have two forms. One that allows users to add new Name+URL
Objects (not sure what your object/Model is called) and another to allow
them to edit (Using Django's 'fields' meta attribute to limit them to only
modify the "Name" of the object)

On Sun, Jul 29, 2012 at 5:47 PM, Paul  wrote:

> I have a model for Websites that has 3 fields: name, url and
> authenticated. With a form both the name and url can be changed, but when
> the website is authenticated i don't want to allow that the url changes.
>
> I'm thinking about making the url (form) field readonly but in html the
> field becomes still an input field (just with readonly="True"), so i have
> doubts whether hackers will be able to post a changed value anyhow (i'll
> need to test this).
>
> Another approach is to add some custom form validation against the
> (current) model, but i have doubts whether validation is the solution for
> this?
>
> Thanks for any directions
> Paul
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/urE06kkuNBIJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation

2012-04-15 Thread Daniel Roseman
On Sunday, 15 April 2012 10:22:43 UTC+1, coded kid wrote:
>
>
> def my_memb(request): 
> if request.method=="POST": 
> form=MembForm(request.POST) 
> if form.is_valid(): 
> data=form.cleaned_data 
> form.save() 
> return HttpResponseRedirect('/test/') 
> else: 
> form=MembForm() 
> return render_to_response('member.html', 
> {'MembForm':MembForm}, context_instance=RequestContext(request)) 
>
>
Take another look at the code above. If it's a POST, it checks the form's 
validity and if it's valid it saves. But the redirect is being executed 
whether or not the form is valid. It should be fairly clear how to fix that.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/qPwVh6Zl2isJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation and unique_together on update a model

2012-04-13 Thread Massimo Barbierato
Thanks Tom, you're right!!!
I solved it passing 'edit' again.

Thanks again

Max


(I'm speculating a little)
>
> In your code snippet, lines 36-38:
>
> sale = None
> if 'edit' in request.GET:
> sale = Sales.objects.get(sale_id=request.GET['edit'])
>
> When you submit the form again, 'edit' is not in request.GET, so
> 'sale' never gets a value. When you then subsequently save the form,
> it tries to save a new instance, which fails because it already
> matches a row in the database.
>
> Cheers
>
> Tom
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/shSrqRlsfa4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation and unique_together on update a model

2012-04-13 Thread Tom Evans
On Fri, Apr 13, 2012 at 1:08 PM, Massimo Barbierato
 wrote:
> Hi all, i'm new. I searched  in the group for answers to my problem, but i
> didn't find anything :(
>
> My problem is this:
>
> i have a model with two fields in unique_together, the related ModelForm and
> the view.
> When i pass an instance of my model to the form to update it and then save
> it, i receive an error that says me that there is already a row with the
> specified fields.
> I can't understand why.
>
> Here you can read my code: http://pastebin.com/vDiHvpiV
>
> Thanks a lot.

(I'm speculating a little)

In your code snippet, lines 36-38:

sale = None
if 'edit' in request.GET:
sale = Sales.objects.get(sale_id=request.GET['edit'])

When you submit the form again, 'edit' is not in request.GET, so
'sale' never gets a value. When you then subsequently save the form,
it tries to save a new instance, which fails because it already
matches a row in the database.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation - Redisplay With Error

2011-05-27 Thread Robin
Thanks, Derek!  Wikipedia makes good sense.

On May 27, 1:14 am, Derek  wrote:
> On May 26, 1:07 am, Robin  wrote:> I'm very 
> comfortable with SQL and more traditional programming.  Would
> > you recommend some specific HTTP primer, or anything  else for those
> > making the transition to web dev?
>
> Assuming good faith in the wisdom of the crowd... 
> :http://en.wikipedia.org/wiki/Http
> An older intro (ignore 
> CGI!):http://www.orion.it/~alf/whitepapers/HTTPPrimer.html
> Formal specs:http://www.w3.org/standards/techs/http#w3c_all

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation - Redisplay With Error

2011-05-27 Thread Derek
On May 26, 1:07 am, Robin  wrote:
> I'm very comfortable with SQL and more traditional programming.  Would
> you recommend some specific HTTP primer, or anything  else for those
> making the transition to web dev?
>
Assuming good faith in the wisdom of the crowd... :
http://en.wikipedia.org/wiki/Http
An older intro (ignore CGI!):
http://www.orion.it/~alf/whitepapers/HTTPPrimer.html
Formal specs:
http://www.w3.org/standards/techs/http#w3c_all

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation

2011-05-26 Thread Daniel Roseman

On Thursday, May 26, 2011 4:50:17 PM UTC+1, Nikhil Somaru wrote:
>
> Apologies for the font.
>
> Would you guys mind elaborating how I would re-display the form, with the 
> validation errors? I am trying to follow the print version of the 
> Djangobook, and it's been brilliant up to this point. There's nothing 
> mentioned in the template about errors.
>

The code you have, with the modification I mentioned, does this already.
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation

2011-05-26 Thread Nikhil Somaru
Apologies for the font.

Would you guys mind elaborating how I would re-display the form, with the
validation errors? I am trying to follow the print version of the
Djangobook, and it's been brilliant up to this point. There's nothing
mentioned in the template about errors.

On Thu, May 26, 2011 at 5:16 PM, Daniel Roseman wrote:

> On Thursday, May 26, 2011 11:18:39 AM UTC+1, Nikhil Somaru wrote:
>
>> Hi all,
>>
>> I am testing the form validation. When I try and submit an empty form, I
>> get:
>>
>> ValueError at /contact/
>>
>> The view djangobook.contact.views.contact didn't return an HttpResponse 
>> object.
>>
>>
>> # -- contact.views:
>> ---#
>>
>> from django.core.mail import send_mail
>> from django.template import RequestContext
>> from django.shortcuts import render_to_response
>> from django.http import HttpResponseRedirect
>> from djangobook.contact.forms import ContactForm
>>
>> def contact(request):
>> if request.method == 'POST':
>> form = ContactForm(request.POST)
>> if form.is_valid():
>> cd = form.cleaned_data
>> send_mail(
>> cd['subject'],
>> cd['message'],
>> cd.get('email', 'nso...@gmail.com'),
>> ['nso...@gmail.com'],
>>
>> fail_silently=False,
>> )
>> return HttpResponseRedirect('/contact/thanks')
>> else:
>> form = ContactForm()
>> return render_to_response('books/contact_form.html',
>>   RequestContext(request, {'form': form}))
>> # Required for CSRF?
>>
>> # -- forms.py:
>> ---#
>> from django import forms
>>
>> class ContactForm(forms.Form):
>> subject = forms.CharField()
>> email = forms.EmailField(required=False)
>> message = forms.CharField()
>>
>>
>> # -- books/contact_form.html:
>> ---#
>> 
>> 
>> Contact Us
>> 
>> 
>> Contact Us
>> {% if form.errors %}
>> 
>> Please correct the error{{ form.errors|pluralize }} below.
>> 
>> {% endif %}
>> {% csrf_token %}
>> 
>> {{ form.as_table }}
>> 
>> 
>> 
>> 
>> 
>> #
>> #
>>
>> Could anyone explain:
>> 1) why the form is not validating
>> 2) How exactly the errors will be displayed?
>>
>>
>> --
>> Yours,
>> Nikhil Somaru
>>
>>
> You need to move the final `return render_to_response` back one indentation
> level.
>
> Please fix your font size when posting here.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Yours,
Nikhil Somaru

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation

2011-05-26 Thread Daniel Roseman
On Thursday, May 26, 2011 11:18:39 AM UTC+1, Nikhil Somaru wrote:
>
> Hi all,
>
> I am testing the form validation. When I try and submit an empty form, I 
> get:
>
> ValueError at /contact/
>
> The view djangobook.contact.views.contact didn't return an HttpResponse 
> object.
>
>
> # -- contact.views: 
> ---#
>
> from django.core.mail import send_mail
> from django.template import RequestContext
> from django.shortcuts import render_to_response
> from django.http import HttpResponseRedirect
> from djangobook.contact.forms import ContactForm
>
> def contact(request):
> if request.method == 'POST':
> form = ContactForm(request.POST)
> if form.is_valid():
> cd = form.cleaned_data
> send_mail(
> cd['subject'],
> cd['message'],
> cd.get('email', 'nso...@gmail.com'),
> ['nso...@gmail.com'],
> fail_silently=False,
> )
> return HttpResponseRedirect('/contact/thanks')
> else:
> form = ContactForm()
> return render_to_response('books/contact_form.html',
>   RequestContext(request, {'form': form})) 
> # Required for CSRF?
>
> # -- forms.py: 
> ---#
> from django import forms
>
> class ContactForm(forms.Form):
> subject = forms.CharField()
> email = forms.EmailField(required=False)
> message = forms.CharField()
>
>
> # -- books/contact_form.html: 
> ---#
> 
> 
> Contact Us
> 
> 
> Contact Us
> {% if form.errors %}
> 
> Please correct the error{{ form.errors|pluralize }} below.
> 
> {% endif %}
> {% csrf_token %}
> 
> {{ form.as_table }}
> 
> 
> 
> 
> 
> # 
> #
>
> Could anyone explain:
> 1) why the form is not validating
> 2) How exactly the errors will be displayed?
>
>
> -- 
> Yours,
> Nikhil Somaru
>
>
You need to move the final `return render_to_response` back one indentation 
level.

Please fix your font size when posting here. 
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation

2011-05-26 Thread Lucian Nicolescu
>From what I see and if the you pasted correct indentations I think the
"render_to_response" instruction should be outside the "else"
statement (in the view code).

Lucian

On Thu, May 26, 2011 at 1:18 PM, Nikhil Somaru  wrote:
> Hi all,
>
> I am testing the form validation. When I try and submit an empty form, I
> get:
>
> ValueError at /contact/
>
> The view djangobook.contact.views.contact didn't return an HttpResponse
> object.
>
>
>
> # -- contact.views:
> ---#
>
> from django.core.mail import send_mail
> from django.template import RequestContext
> from django.shortcuts import render_to_response
> from django.http import HttpResponseRedirect
> from djangobook.contact.forms import ContactForm
>
> def contact(request):
>     if request.method == 'POST':
>     form = ContactForm(request.POST)
>     if form.is_valid():
>     cd = form.cleaned_data
>     send_mail(
>     cd['subject'],
>     cd['message'],
>     cd.get('email', 'nsom...@gmail.com'),
>     ['nsom...@gmail.com'],
>     fail_silently=False,
>     )
>     return HttpResponseRedirect('/contact/thanks')
>     else:
>     form = ContactForm()
>     return render_to_response('books/contact_form.html',
>   RequestContext(request, {'form': form})) #
> Required for CSRF?
>
> # -- forms.py:
> ---#
> from django import forms
>
> class ContactForm(forms.Form):
>     subject = forms.CharField()
>     email = forms.EmailField(required=False)
>     message = forms.CharField()
>
>
> # -- books/contact_form.html:
> ---#
> 
> 
>     Contact Us
> 
> 
>     Contact Us
>     {% if form.errors %}
>     
>     Please correct the error{{ form.errors|pluralize }} below.
>     
>     {% endif %}
>     {% csrf_token %}
>     
>     {{ form.as_table }}
>     
>     
>     
> 
> 
> #
> #
>
> Could anyone explain:
> 1) why the form is not validating
> 2) How exactly the errors will be displayed?
>
>
> --
> Yours,
> Nikhil Somaru
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation - Redisplay With Error

2011-05-25 Thread Robin
I'm very comfortable with SQL and more traditional programming.  Would
you recommend some specific HTTP primer, or anything  else for those
making the transition to web dev?

On May 25, 8:24 am, bruno desthuilliers
 wrote:
> On May 25, 3:54 pm, Robin  wrote:
>
> > Because that would be too easy? ;)
>
> Well... 
>
> >  Sincere thanks, Bruno.  A lot of
> > this is new to me...python, Django, web dev, and even open source.
> > Didn't even think of that!
>
> Surprisingly enough, it took me a couple weeks realizing I could as
> well just read the source code when I started working on / with oss.
>
> wrt/ web dev, I think the most important thing to learn is the HTTP
> protocol itself (and a couple others related specs like cookies etc).
> Once you get it, lot of things in Django (or any other decent web
> framework) starts to make sense, and it's easier to know what to look
> for in the doc.
>
> (ok, I assume you already have a decent knowledge of things like SQL,
> HTML, text processing, Python etc).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation - Redisplay With Error

2011-05-25 Thread bruno desthuilliers
On May 25, 3:54 pm, Robin  wrote:
> Because that would be too easy? ;)

Well... 

>  Sincere thanks, Bruno.  A lot of
> this is new to me...python, Django, web dev, and even open source.
> Didn't even think of that!

Surprisingly enough, it took me a couple weeks realizing I could as
well just read the source code when I started working on / with oss.

wrt/ web dev, I think the most important thing to learn is the HTTP
protocol itself (and a couple others related specs like cookies etc).
Once you get it, lot of things in Django (or any other decent web
framework) starts to make sense, and it's easier to know what to look
for in the doc.

(ok, I assume you already have a decent knowledge of things like SQL,
HTML, text processing, Python etc).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation - Redisplay With Error

2011-05-25 Thread Ndungi Kyalo
sorry, i'll repost under the appropriate subject.

On 25 May 2011 17:11, Ndungi Kyalo  wrote:
> Am trying to pre-select a radio button created with the django.forms library
> :
>     vote = forms.ChoiceField(
>         widget = forms.RadioSelect(),
>         choices = [
>             ['a', 'i liked it'],
>             ['b', 'i did not like it']
>         ],
>         required=True
>     )
> How would I go about getting the 'a' choice pre-selected on an unbound form
> ?
> --
> Ndungi Kyalo

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation - Redisplay With Error

2011-05-25 Thread Ndungi Kyalo
Am trying to pre-select a radio button created with the django.forms library
:

vote = forms.ChoiceField(
widget = forms.RadioSelect(),
choices = [
['a', 'i liked it'],
['b', 'i did not like it']
],
required=True
)

How would I go about getting the 'a' choice pre-selected on an unbound form
?

--
Ndungi Kyalo

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation - Redisplay With Error

2011-05-25 Thread Robin
Because that would be too easy? ;)  Sincere thanks, Bruno.  A lot of
this is new to me...python, Django, web dev, and even open source.
Didn't even think of that!  There's so much to learn, it can be
overwhelming.  Thank you again, I'll have a look through the code
today.

On May 25, 1:02 am, bruno desthuilliers
 wrote:
> On May 25, 4:48 am, Robin  wrote:
>
> > I've tried to track down this information (new to Django and web dev)
> > and I'm certainly not expecting a spoon-fed answer.  A nudge in the
> > right direction would be most appreciated. :)
>
> Why don't you just have a look at the code of the builtin auth
> form ?-)
>
> https://code.djangoproject.com/browser/django/trunk/django/contrib/au...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation - Redisplay With Error

2011-05-25 Thread bruno desthuilliers
On May 25, 4:48 am, Robin  wrote:
> I've tried to track down this information (new to Django and web dev)
> and I'm certainly not expecting a spoon-fed answer.  A nudge in the
> right direction would be most appreciated. :)

Why don't you just have a look at the code of the builtin auth
form ?-)

https://code.djangoproject.com/browser/django/trunk/django/contrib/auth/forms.py#L80

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation - Redisplay With Error

2011-05-24 Thread Robin
Apologies...it seems I misunderstood clean_message().  It's not a
method, but clean_* is something for each field.  I'll continue my
research, but would still love to hear from you all about custom login
forms and how you handle them.

On May 24, 8:48 pm, Robin  wrote:
> I'm writing a basic login form using the Django built in
> authentication system, but my own login form.  This may be a mistake,
> but it can't hurt to learn how to get it to work? :)
>
> I have this Django Form:
>
> class SignInForm(forms.Form):
>     username = forms.CharField(label='User Name', max_length=30)
>     password = forms.CharField(label='Password', max_length=30,
>         widget=forms.PasswordInput(render_value=False))
>
> One of the things I'm not sure how to handle is the idea of
> redisplaying the form with an error if the login doesn't succeed.  The
> fields will validate alright, but the authentication may fail.  Rather
> than redirect to a failure page when I call authenticate(), I would
> like to return the user to the sign in page and display an error
> message.  Is this something I should treat as a custom validation
> issue for this form?  If so, I've seen mention of a clean_message
> function on djangobook.com for 1.0, but it's not in the documentation
> for 1.3...is this an old idea I should avoid?
>
> I've tried to track down this information (new to Django and web dev)
> and I'm certainly not expecting a spoon-fed answer.  A nudge in the
> right direction would be most appreciated. :)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: form validation for empty checkboxes that are not required (and they are the only fields present)

2010-09-28 Thread Skylar Saveland
class Asset(models.Model):
languages = models.ManyToManyField('account.Language', null=True,
blank=True)


class AssetLanguageForm(forms.ModelForm):
languages = forms.ModelMultipleChoiceField(
queryset=Language.objects.all(),
required=False,
widget=forms.CheckboxSelectMultiple
)

class Meta:
model = Asset
fields = ('languages',)


Adding a hidden garbage field works.  Seems like it's just a little
edge-case bug/gotcha.



On Sep 28, 8:49 am, Brian Neal  wrote:
> On Sep 27, 11:35 am, Skylar Saveland 
> wrote:> I have some modelforms within a .  Each form has one
> > checkboxselectmultiple that is not required.  If I post nothing (all
> > checkboxes are empty) then all of the forms are invalid.  If I post
> > anything then all of the forms are valid.  This anything could be that
> > one of the forms has a box checked, or that I add  > name='omg' value='wtf'> to the form.
>
> Can you please post your model and form code? Perhaps in a pastebin?
>
> BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: form validation for empty checkboxes that are not required (and they are the only fields present)

2010-09-28 Thread Brian Neal
On Sep 27, 11:35 am, Skylar Saveland 
wrote:
> I have some modelforms within a .  Each form has one
> checkboxselectmultiple that is not required.  If I post nothing (all
> checkboxes are empty) then all of the forms are invalid.  If I post
> anything then all of the forms are valid.  This anything could be that
> one of the forms has a box checked, or that I add  name='omg' value='wtf'> to the form.
>
Can you please post your model and form code? Perhaps in a pastebin?

BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation

2010-07-30 Thread Daniel Roseman
On Jul 30, 4:49 pm, rupert  wrote:
> Here's the view template:
>
> def respondant(request):
>
>         user = request.user
>
>         if set(RESPONDANT_FIELDS).issubset(set([key for key,value in
> request.POST.items()])):
>                 form = RespondantForm(request.POST)
>                 if form.is_valid():
>                         form.save()
>                         template = "feedback/success.html"
>                 else:
>                         form = RespondantForm()
>                         return render_to_response('feedback/index.html', {
>                         'form': form,
>                 })
>
>         else:
>                 key = request.REQUEST.get('key')
>                 if key:
>                         respondant = Respondant.objects.check_key(key)
>                 else:
>                         form = RespondantForm()
>                         return render_to_response('feedback/index.html', {
>                         'form': form,
>                 })
>
>         return render_to_response(template)

This is an unusual structure for a form view, but the problem happens
in the first `else` clause. Previously you've instantiated the form,
passing it the POSTed values, and checked it for errors. But now you
re-instantiate a *blank* form, which obviously won't have any errors
attached to it. Instead of doing that, you should simply be passing
the existing form object into the template - in other words, you don't
need that `else` clause at all (I'm assuming that the extra
indentation of `return render_to_response` is just a cut-and-paste
error, and it's actually at the same level as the `if form.is_valid()`
line.)
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation

2010-07-30 Thread rupert
Here's the view template:

def respondant(request):

user = request.user

if set(RESPONDANT_FIELDS).issubset(set([key for key,value in
request.POST.items()])):
form = RespondantForm(request.POST)
if form.is_valid():
form.save()
template = "feedback/success.html"
else:
form = RespondantForm()
return render_to_response('feedback/index.html', {
'form': form,
})

else:
key = request.REQUEST.get('key')
if key:
respondant = Respondant.objects.check_key(key)
else:
form = RespondantForm()
return render_to_response('feedback/index.html', {
'form': form,
})

return render_to_response(template)

On Jul 30, 11:44 am, Daniel Roseman  wrote:
> On Jul 30, 4:42 pm, rupert  wrote:
>
> > I'm trying to use this line of code in form validation, and it is not
> > working:
>
> > {{ form.field_name.errors }}
>
> > The following lines do output:
> > {{ form.filed_name}}
> > {{ form.field_name.help_text }}
>
> > Any thoughts? Could it be something in the view?
>
> Very likely. Has the form been validated?
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation

2010-07-30 Thread Daniel Roseman
On Jul 30, 4:42 pm, rupert  wrote:
> I'm trying to use this line of code in form validation, and it is not
> working:
>
> {{ form.field_name.errors }}
>
> The following lines do output:
> {{ form.filed_name}}
> {{ form.field_name.help_text }}
>
> Any thoughts? Could it be something in the view?

Very likely. Has the form been validated?
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation

2010-07-27 Thread Renne Rocha
  Send your model and form codes, than it will be easier to see what is wrong.


On Tue, Jul 27, 2010 at 4:45 AM, S.Selvam  wrote:
> Hi all,
> I have two model fields (text and file ) and i want either one of the field
> to be filled out.
>
> I set null=True,blank=True for both fields in model.
>
> Still the form validation requires both fields.
>
> In form i tried to have required=False attribute, which makes it impossible
> to upload file(via HTTP Post from a applet )
>
>
> --
> Regards,
> S.Selvam
>
>    " I am because we are "
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation and template errors - need n00b help

2010-07-14 Thread reduxdj
Great,

Tom I looked a the django book carefully and did the following:

return render_to_response('listing.html', {'form':form,'error': True})

and works...

thanks for responding as well

On Jul 14, 7:37 am, Tom Evans  wrote:
> On Tue, Jul 13, 2010 at 4:06 PM, reduxdj  wrote:
> > HI,
>
> > Forgive me, here's another n00b doozie. I've created a form, which
> > extends form, however, my form is not validating and I can't get the
> > form to print errors next to my form fields. What's curious, at the
> > form.is_valid()
> > in all the examples, I don't see an else: clause. Which leads me to
> > believe that a validation error should be
> > raised at this point, so an else is not neccessary??
>
> > So, my form should hold clean_fieldname methods for each field name
> > correct? and if an error is raised,
> > automagically, django handles the error messages, as long as it's
> > defined in my template, correct or not?
> > So every property needs a clean method?
>
> > Sorry, I've read the resources and I'm a little unclear on this?
>
> > Thanks for your time,
> > Django and the community rocks
>
> > from my views:
>
> > def listing(request):
> >    if request.method == 'POST': # If the form has been submitted...
> >        new_listing = Listing()
> >        form = ListingForm(data=request.POST,instance=new_listing)
> >        #form.save()
> >        if form.is_valid(): # All validation rules pass
> >            form.save()
> >            return HttpResponseRedirect('/listing/') # Redirect after
> > POST
> >        #else:
> >            #return HttpResponseRedirect('/listing/') # Redirect after
> > POST
> >            #return HttpResponse('form is a failure, like you.')
> >            #return HttpResponseRedirect('/create/') # Redirect after
> > POST
> >    else:
> >        form = ListingForm() # An unbound form
> >        return render_to_response('listing.html', {
> >            'form': form,
> >        })
>
> Unindent the 'return render_to_response(...' lines, so that they are
> executed when you have an invalid form. The form will be re-rendered,
> except this time the form instance will be bound, and have appropriate
> error messages in it.
>
> eg:
>
> if request.method == 'POST':
>   form = ...
>   if form.is_valid():
>     ...
> else:
>   form = ...
> return render_to_response(...)
>
> Cheers
>
> Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation and template errors - need n00b help

2010-07-14 Thread Tom Evans
On Tue, Jul 13, 2010 at 4:06 PM, reduxdj  wrote:
> HI,
>
> Forgive me, here's another n00b doozie. I've created a form, which
> extends form, however, my form is not validating and I can't get the
> form to print errors next to my form fields. What's curious, at the
> form.is_valid()
> in all the examples, I don't see an else: clause. Which leads me to
> believe that a validation error should be
> raised at this point, so an else is not neccessary??
>
> So, my form should hold clean_fieldname methods for each field name
> correct? and if an error is raised,
> automagically, django handles the error messages, as long as it's
> defined in my template, correct or not?
> So every property needs a clean method?
>
> Sorry, I've read the resources and I'm a little unclear on this?
>
> Thanks for your time,
> Django and the community rocks
>
> from my views:
>
> def listing(request):
>    if request.method == 'POST': # If the form has been submitted...
>        new_listing = Listing()
>        form = ListingForm(data=request.POST,instance=new_listing)
>        #form.save()
>        if form.is_valid(): # All validation rules pass
>            form.save()
>            return HttpResponseRedirect('/listing/') # Redirect after
> POST
>        #else:
>            #return HttpResponseRedirect('/listing/') # Redirect after
> POST
>            #return HttpResponse('form is a failure, like you.')
>            #return HttpResponseRedirect('/create/') # Redirect after
> POST
>    else:
>        form = ListingForm() # An unbound form
>        return render_to_response('listing.html', {
>            'form': form,
>        })
>

Unindent the 'return render_to_response(...' lines, so that they are
executed when you have an invalid form. The form will be re-rendered,
except this time the form instance will be bound, and have appropriate
error messages in it.

eg:

if request.method == 'POST':
  form = ...
  if form.is_valid():
...
else:
  form = ...
return render_to_response(...)

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation

2010-05-19 Thread Dejan Noveski
>
>
>user = User.objects.get(pk=request.user.id)

   from = UpdateUserForm(user, ...initialstuff...)
>

First off, change this to form = UpdateUserForm(request.user,...)
request.user is django.contrib.auth.User object. You have to have


-- 
--
Dejan Noveski
Web Developer
dr.m...@gmail.com
Twitter: http://twitter.com/dekomote | LinkedIn:
http://mk.linkedin.com/in/dejannoveski

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation

2010-05-19 Thread Dejan Noveski
On Wed, May 19, 2010 at 3:11 PM, Dejan Noveski  wrote:

>
>>user = User.objects.get(pk=request.user.id)
>
>from = UpdateUserForm(user, ...initialstuff...)
>>
>
> First off, change this to form = UpdateUserForm(request.user,...)
> request.user is django.contrib.auth.User object. You have to have
>

AuthenticationMiddleware in settings


> --
> --
> Dejan Noveski
> Web Developer
> dr.m...@gmail.com
> Twitter: http://twitter.com/dekomote | LinkedIn:
> http://mk.linkedin.com/in/dejannoveski
>



-- 
--
Dejan Noveski
Web Developer
dr.m...@gmail.com
Twitter: http://twitter.com/dekomote | LinkedIn:
http://mk.linkedin.com/in/dejannoveski

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation question

2010-05-13 Thread Daniel Roseman
On May 13, 5:17 pm, zweb  wrote:
> I am doing this
>
>  form = ContactForm(request.POST) # A form bound to the POST data
>  if form.is_valid(): # All validation rules pass
>
> As clean is called by is_valid() and at this point form in bound to
> POST data, I cannot use self.instance unless I do this
>
>         form = ContactForm(request.POST, instance= contact)
>
> Any downside to doing this ... as I have done either form =
> ContactForm(request.POST) or  form = ContactForm( instance= contact)
> but never both together.

No downside, this is what you should be doing to update an existing
instance.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation question

2010-05-13 Thread zweb

I am doing this

 form = ContactForm(request.POST) # A form bound to the POST data
 if form.is_valid(): # All validation rules pass


As clean is called by is_valid() and at this point form in bound to
POST data, I cannot use self.instance unless I do this

form = ContactForm(request.POST, instance= contact)

Any downside to doing this ... as I have done either form =
ContactForm(request.POST) or  form = ContactForm( instance= contact)
but never both together.

On May 13, 7:51 am, Shawn Milochik  wrote:
> "Also, a model form instance bound to a model object will contain a 
> self.instance attribute that gives model form methods access to that specific 
> model instance."
>
> From:http://docs.djangoproject.com/en/1.1/topics/forms/modelforms/
>
> So you can refer to self.instance in your validation code, assuming the form 
> is bound (not a new, unsaved instance created by the current form submission).
>
> Shawn
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation question

2010-05-13 Thread Jeff Green
I have used sessions to store the initial db record so that when I go into
my form I retrieve the value
such as

stationrec = request.session['stationrec']

On Thu, May 13, 2010 at 9:36 AM, zweb  wrote:

> I am using a model form to edit (change) an exisiting row in db.
>
> in clean_xxx() method I want to compare the old (existing) value
> versus new value.
>
> I can get new value from cleaned_data.
>
>
> How do I get the old (existing) value?
>
> If I do a db query to get the existing row from DB how do I get the PK
> as it is not a form field.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation question

2010-05-13 Thread Shawn Milochik
"Also, a model form instance bound to a model object will contain a 
self.instance attribute that gives model form methods access to that specific 
model instance."

From: 
http://docs.djangoproject.com/en/1.1/topics/forms/modelforms/

So you can refer to self.instance in your validation code, assuming the form is 
bound (not a new, unsaved instance created by the current form submission).

Shawn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation changes since 1.1.1? (Autocomplete errors)

2010-03-17 Thread john2095
There has been some change between 1.1 and trunk regarding questions
whether to enforce defaults at the form or the model level.  Might be
relevant, or provide a clue:
http://stackoverflow.com/questions/1436327/does-model-charfieldblankfalse-work-with-save

On Mar 17, 12:11 pm, Karen Tracey  wrote:
> Yeah but, if it worked previously under 1.1, it ought not be broken by
> updating to 1.2.
>
> Sounds like under 1.1 required=False on the form field overrode blank=False
> on the model field, whereas with the current trunk required=False on the
> form field is being ignored in favor of blank=False on the model field.
>
> It's probably worth opening a ticket; I don't recall hearing this reported
> before.
>
> Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation changes since 1.1.1? (Autocomplete errors)

2010-03-16 Thread Karen Tracey
On Tue, Mar 16, 2010 at 8:51 PM, saxon75  wrote:

> I guess I should try a little harder before asking for help.  Turns
> out that I also needed to define the slug field in the model with
> "blank=True."
>

Yeah but, if it worked previously under 1.1, it ought not be broken by
updating to 1.2.

Sounds like under 1.1 required=False on the form field overrode blank=False
on the model field, whereas with the current trunk required=False on the
form field is being ignored in favor of blank=False on the model field.

It's probably worth opening a ticket; I don't recall hearing this reported
before.

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation changes since 1.1.1? (Autocomplete errors)

2010-03-16 Thread saxon75
I guess I should try a little harder before asking for help.  Turns
out that I also needed to define the slug field in the model with
"blank=True."

Sorry for the spam.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation changes since 1.1.1? (Autocomplete errors)

2010-03-16 Thread saxon75
I should also note that in the AddArticleForm class, the slug field
has the "required" attribute set to False, like so:

slug = forms.CharField(max_length=25, required=False)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form validation changes since 1.1.1? (Autocomplete errors)

2010-03-16 Thread saxon75
Ah, small mistake: my current Django revision is r12794, not r11794.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Form Validation in Admin

2010-01-12 Thread Sasuke

thanks very much.
it seems self.instance always exists but its pk(id) is None when it's an add 
and not None when it's modification.



- Original Message - 
From: "Daniel Roseman" <dan...@roseman.org.uk>

To: "Django users" <django-users@googlegroups.com>
Sent: Monday, January 11, 2010 9:27 PM
Subject: Re: Form Validation in Admin


On Jan 11, 3:24 am, "Sasuke" <zhouj...@gmail.com> wrote:

Hi all,
I'm using the form's clean() method to do validation for models in admin. 
The validation we need to do is to make sure there are no more than a 
certain number of items totally submitted. So I calculate the total number 
of items in the clean() method and check whether it is in the given range. 
But the exact total number is difficult ot get because I don't know 
whether the newly submitted form'data is a modified item that is already 
submitted or it's a newly added item. So is there any way in the clean() 
method to know whether the form's data is a newly added item or a modified 
one?

Thanks to all.


Check the value of self.instance. If it exists, and it has a pk, then
it is a modification rather than an add.
--
DR.







--
You received this message because you are subscribed to the Google Groups 
"Django users" group.

To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.






-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Form Validation in Admin

2010-01-11 Thread Daniel Roseman
On Jan 11, 3:24 am, "Sasuke"  wrote:
> Hi all,
> I'm using the form's clean() method to do validation for models in admin. The 
> validation we need to do is to make sure there are no more than a certain 
> number of items totally submitted. So I calculate the total number of items 
> in the clean() method and check whether it is in the given range. But the 
> exact total number is difficult ot get because I don't know whether the newly 
> submitted form'data is a modified item that is already submitted or it's a 
> newly added item. So is there any way in the clean() method to know whether 
> the form's data is a newly added item or a modified one?
> Thanks to all.

Check the value of self.instance. If it exists, and it has a pk, then
it is a modification rather than an add.
--
DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Form validation

2009-11-26 Thread Karen Tracey
On Thu, Nov 26, 2009 at 5:49 AM, pinco  wrote:

> Hi there.
>
> I’m not able to figure out how to solve in a simple and clean way the
> following problem.
> Basically what I want to do is to edit the instances of the following
> model:
>
> Models.py
> class Seller(models.Model):
>brand = models.CharField(max_length=250)
>  ...
>slug = models.SlugField(unique=True)
>
> The form is generated using the following code. The validator should
> ensure that the entered brand is unique among the registered users. I
> would use the same form both to create and to edit Seller instances.
>

If you add unique=True to the brand model field (see
http://docs.djangoproject.com/en/dev/ref/models/fields/#unique) then a model
form created for that model will automatically do the uniqueness checking
for you.

Karen

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Form validation: Add at least one item to inline model

2009-11-23 Thread Brandon Taylor
http://wadofstuff.blogspot.com/2009/08/requiring-at-least-one-inline-formset.html

On Nov 23, 6:06 pm, Brandon Taylor  wrote:
> Hi everyone,
>
> I need to validate that at lease one item has been added to an inline
> model in Django admin. I'm not quite sure where to put this
> validation...can someone help me out?
>
> TIA,
> Brandon

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Form validation in Admin Panel

2009-04-13 Thread eli

On 13 Kwi, 21:10, Alex Gaynor  wrote:
> Provide a custom form to the ModelAdmin using the form 
> option:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form
>
> Alex
>

Oh, it's so simple.. :-)

Thank You Alex

regards.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation in Admin Panel

2009-04-13 Thread Alex Gaynor
On Mon, Apr 13, 2009 at 2:52 PM, eli  wrote:

>
> Hi,
>
> How can I to validate data from form in Django Admin Panel? (like:
> clena_fieldname in form.ModelForm) ?
>
> regards.
> >
>
Provide a custom form to the ModelAdmin using the form option:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form validation in XMLHttp submission

2009-02-05 Thread adrian

It is true that I was accessing the error message incorrectly in
python - it should be
my_form.errors['date'] and it is set.   However the doc says you can
access that same value with form.name_of_field.errors in a template
like this:



{{ form.date.errors }}
Date:
{{ form.date}}

But it is not showing up in my view.  I also tried form.errors.date
but that does not work either.

Any help appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form validation in XMLHttp submission

2009-02-04 Thread Malcolm Tredinnick

On Wed, 2009-02-04 at 11:23 -0800, adrian wrote:
> 
> I'm using the standard pattern for handling a  POST request form
> submission, even though the form is submitted by  JavaScript as an
> XMLHttpRequest, and the date validation is not working.   I added some
> logging statements to find the problem and I get the error message
> "MyModelForm' object has no attribute 'date' " even though it
> definitely has that attribute, as shown in the logs below.  

The error message is correct. Your form has a form field called "date",
but the form class does not have an *attribute* called date. The form
fields are stored in an attribute on the form called "fields".

So my_form.field["date"] will access the date form field.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form validation does not work

2008-12-31 Thread Chuck22

Thanks for the reference. The problem is solved with this code
modification:

def contact(request):
if request.method == 'POST':
f = ContactForm(request.POST)
if f.is_valid():
email = f.cleaned_data['email']
... #send email
return HttpResponseRedirect(reverse('contact_success'))
   else:
 f=ContactForm()

   return render_to_response(
'post_contact.html',
{ 'form':f },
context_instance = RequestContext(request)
)



On Dec 31, 12:36 pm, Daniel Roseman 
wrote:
> On Dec 31, 12:18 am, Chuck22  wrote:
>
>
>
>
>
> > class ContactForm(forms.Form):
> >           email = forms.EmailField(required=True,
> >                              widget=forms.TextInput(attrs=
> > {'size':'30'}),
> >                             error_messages={'required':'Please fill
> > out your Email'})
> >           ...
>
> > in my form html file:
> > ...
> > label for="id_full_name">Your email address
> >             {{ form.email.errors }}
> >             {{ form.email }}
> > ...
>
> > in my view:
> > def contact(request):
> >     if request.method == 'POST':
> >         f = ContactForm(request.POST)
> >         if f.is_valid():
> >             email = f.cleaned_data['email']
> >             ...
> >             return HttpResponseRedirect(reverse('contact_success'))
>
> > When user submit the contact form without fill out email field, the
> > form get submitted without displaying error message 'Please fill out
> > your Email'. Instead, I got error: The view app.views.contact didn't
> > return an HttpResponse object.
>
> > it seems f.is_valud return false, which is correct. But I think form
> > validation should kick in at this point and return error message to
> > {{ form.email.errors }} field in template. Why doesn't the validation
> > work? Did I miss anything?
>
> As Alex says, we'll need to see the full view function to really help.
> But assuming the last line what you've posted is actually the last
> line of the function, you are indeed missing something - the code to
> return something if the form fails validation.
>
> The error message you've posted tells you exactly what's happening -
> your view is not returning an HttpResponse. It's always your
> responsibility to do this - Django won't ever do something by default
> (except 404 and 500 errors). Look more closely at the example given in
> the 
> documentation:http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-...
> You'll see that in that view, the return at the end is called in both
> the case of the initial GET, and if the POST failed validation.
> --
> DR.- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form validation does not work

2008-12-31 Thread Daniel Roseman

On Dec 31, 12:18 am, Chuck22  wrote:
> class ContactForm(forms.Form):
>           email = forms.EmailField(required=True,
>                              widget=forms.TextInput(attrs=
> {'size':'30'}),
>                             error_messages={'required':'Please fill
> out your Email'})
>           ...
>
> in my form html file:
> ...
> label for="id_full_name">Your email address
>             {{ form.email.errors }}
>             {{ form.email }}
> ...
>
> in my view:
> def contact(request):
>     if request.method == 'POST':
>         f = ContactForm(request.POST)
>         if f.is_valid():
>             email = f.cleaned_data['email']
>             ...
>             return HttpResponseRedirect(reverse('contact_success'))
>
> When user submit the contact form without fill out email field, the
> form get submitted without displaying error message 'Please fill out
> your Email'. Instead, I got error: The view app.views.contact didn't
> return an HttpResponse object.
>
> it seems f.is_valud return false, which is correct. But I think form
> validation should kick in at this point and return error message to
> {{ form.email.errors }} field in template. Why doesn't the validation
> work? Did I miss anything?

As Alex says, we'll need to see the full view function to really help.
But assuming the last line what you've posted is actually the last
line of the function, you are indeed missing something - the code to
return something if the form fails validation.

The error message you've posted tells you exactly what's happening -
your view is not returning an HttpResponse. It's always your
responsibility to do this - Django won't ever do something by default
(except 404 and 500 errors). Look more closely at the example given in
the documentation:
http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view
You'll see that in that view, the return at the end is called in both
the case of the initial GET, and if the POST failed validation.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form validation does not work

2008-12-31 Thread Chuck22

def contact(request):
if request.method == 'POST':
f = ContactForm(request.POST)
if f.is_valid():
email = f.cleaned_data['email']
... #send email
return HttpResponseRedirect(reverse('contact_success'))
   else:
 f=ContactForm()
 return render_to_response(
'post_contact.html',
{ 'form':f },
context_instance = RequestContext(request)
)

I am still workong on the view code to send email when users submit
the form. The problem is that required field did not validate and
block the form submission. User is able to submit the form without
providing email which is a required field.

On Dec 31, 1:50 am, "Alex Koshelev"  wrote:
> Please post here entire view code
>
>
>
> On Wed, Dec 31, 2008 at 8:18 AM, Chuck22  wrote:
>
> > class ContactForm(forms.Form):
> >          email = forms.EmailField(required=True,
> >                             widget=forms.TextInput(attrs=
> > {'size':'30'}),
> >                            error_messages={'required':'Please fill
> > out your Email'})
> >          ...
>
> > in my form html file:
> > ...
> > label for="id_full_name">Your email address
> >            {{ form.email.errors }}
> >            {{ form.email }}
> > ...
>
> > in my view:
> > def contact(request):
> >    if request.method == 'POST':
> >        f = ContactForm(request.POST)
> >        if f.is_valid():
> >            email = f.cleaned_data['email']
> >            ...
> >            return HttpResponseRedirect(reverse('contact_success'))
>
> > When user submit the contact form without fill out email field, the
> > form get submitted without displaying error message 'Please fill out
> > your Email'. Instead, I got error: The view app.views.contact didn't
> > return an HttpResponse object.
>
> > it seems f.is_valud return false, which is correct. But I think form
> > validation should kick in at this point and return error message to
> > {{ form.email.errors }} field in template. Why doesn't the validation
> > work? Did I miss anything?- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form validation does not work

2008-12-30 Thread Alex Koshelev
Please post here entire view code


On Wed, Dec 31, 2008 at 8:18 AM, Chuck22  wrote:

>
> class ContactForm(forms.Form):
>  email = forms.EmailField(required=True,
> widget=forms.TextInput(attrs=
> {'size':'30'}),
>error_messages={'required':'Please fill
> out your Email'})
>  ...
>
> in my form html file:
> ...
> label for="id_full_name">Your email address
>{{ form.email.errors }}
>{{ form.email }}
> ...
>
> in my view:
> def contact(request):
>if request.method == 'POST':
>f = ContactForm(request.POST)
>if f.is_valid():
>email = f.cleaned_data['email']
>...
>return HttpResponseRedirect(reverse('contact_success'))
>
> When user submit the contact form without fill out email field, the
> form get submitted without displaying error message 'Please fill out
> your Email'. Instead, I got error: The view app.views.contact didn't
> return an HttpResponse object.
>
> it seems f.is_valud return false, which is correct. But I think form
> validation should kick in at this point and return error message to
> {{ form.email.errors }} field in template. Why doesn't the validation
> work? Did I miss anything?
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation problem for model with ForeignKey having unique=True,blank=True,null=True

2008-09-11 Thread Nathaniel Griswold

Thanks, created Ticket #9039

> I don't think the ModelForm validation should prohibit something the
> databases generally allow. I'd open a ticket (search first though to see if
> it's already been reported/decided on...I could be missing something).
>
> Karen
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation problem for model with ForeignKey having unique=True,blank=True,null=True

2008-09-11 Thread Karen Tracey
On Thu, Sep 11, 2008 at 8:14 AM, krylatij <[EMAIL PROTECTED]> wrote:

>
> You can create only one model with empty 'other' field.
> If you could  create one more, field 'other'  will not be unique more.
> That's why validation fails.
>

This is not generally true at the database level, as Nathaniel showed by the
fact that he could indeed create multiple objects with null values, just not
via a ModelForm.  From the PostgreSQL doc (
http://www.postgresql.org/docs/8.3/interactive/indexes-unique.html):

"When an index is declared unique, multiple table rows with equal indexed
values will not be allowed. Null values are not considered equal."

and MySQL (http://dev.mysql.com/doc/refman/5.0/en/create-index.html):

"A UNIQUE index creates a constraint such that all values in the index must
be distinct. An error occurs if you try to add a new row with a key value
that matches an existing row. This constraint does not apply to NULL values
except for the BDB storage engine. For other engines, a UNIQUE index allows
multiple NULL values for columns that can contain NULL."

I don't think the ModelForm validation should prohibit something the
databases generally allow. I'd open a ticket (search first though to see if
it's already been reported/decided on...I could be missing something).

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation problem for model with ForeignKey having unique=True,blank=True,null=True

2008-09-11 Thread krylatij

You can create only one model with empty 'other' field.
If you could  create one more, field 'other'  will not be unique more.
That's why validation fails.




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation problem for model with ForeignKey having unique=True,blank=True,null=True

2008-09-11 Thread Nathaniel Griswold

My django version is 1.0-final-SVN-9013

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation

2008-08-25 Thread julianb

On Aug 23, 11:17 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> This seems to have done the trick. Thanks for your help.
>
> def index(request):
>     if request.method == 'POST':
>         form = pasteForm(request.POST)
>         if form.is_valid():
>             name = form.cleaned_data['name']
>             log = form.cleaned_data['log']
>             return HttpResponseRedirect('/success/')
>         else:
>             return render_to_response('pastebin.html', {'form': form})
>     else:
>         form = pasteForm()
>         return render_to_response('pastebin.html', {'form': form})

Why not

def index(request):
if request.method == 'POST':
form = pasteForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
log = form.cleaned_data['log']
return HttpResponseRedirect('/success/')
else:
form = pasteForm()
return render_to_response('pastebin.html', {'form': form})

like in the docs?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation

2008-08-23 Thread [EMAIL PROTECTED]

Thanks :-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation

2008-08-23 Thread [EMAIL PROTECTED]

This seems to have done the trick. Thanks for your help.

def index(request):
if request.method == 'POST':
form = pasteForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
log = form.cleaned_data['log']
return HttpResponseRedirect('/success/')
else:
return render_to_response('pastebin.html', {'form': form})
else:
form = pasteForm()
return render_to_response('pastebin.html', {'form': form})
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation

2008-08-23 Thread [EMAIL PROTECTED]

Thanks for your reply Karen.

I have been following those docs. If I use it literally it is missing
an else after is_valid. Otherwise it tests for POST - if exist test is
valid - if is invalid and is POST it returns no response object. That
is why I felt I had to return the form again - I was expecting to be
missing some syntax for passing the error dictionary to the form.

As it stands I still don't see any errors.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation

2008-08-23 Thread Karen Tracey
On Sat, Aug 23, 2008 at 4:34 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]>wrote:

>
> OK, I've found why it wasn't returning an httpresponseobject. It was
> because I wasn't returning a render_to_response on validation fail.
> However I cannot get my errors to show on the form. Any ideas ?
>

Follow the pattern from the docs:

http://www.djangoproject.com/documentation/forms/#simple-view-example

The code you had was recreating an empty form in the case where the original
form did not validate. You don't want to that.  If is_valid() returns False
you want to leave the the form as-is and redisplay it (that is, fall through
to the render_to_response at the bottom).  That way the user will see what
they have entered plus whatever error messages were added to the fields
during validation.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation

2008-08-23 Thread [EMAIL PROTECTED]

OK, I've found why it wasn't returning an httpresponseobject. It was
because I wasn't returning a render_to_response on validation fail.
However I cannot get my errors to show on the form. Any ideas ?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-14 Thread [EMAIL PROTECTED]

I always use

if(len(request.GET)>0):
  form=TestForm(request.GET)
  if(form.is_valid()):
#process form
else:
  form=Testform()
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-13 Thread Bartek Gniado
Maybe because you actually have to pass `action`? ;)

Pass it through your form. Maybe my use of 'action' confused you with the
's action property. Not what I meant, sorry.

I didn't realize you had an actual form (Wait, why do you .. Ok, beyond the
point) but in this case you can just check for any value within your form
and see if it's True
If your form has a "name" field you could do: if request.GET.get('name'):
...

Your initial problem is when you load a page, that Is a GET request so
that's why it was going through.





On Fri, Jun 13, 2008 at 10:45 PM, ichbindev <[EMAIL PROTECTED]> wrote:

>
> This is what my template looks like:
>
> {{ form.as_table }}  table>
>
> This is what my view looks like:
>
> ...
> myform = MyForm()
> if request.method=="GET":
>myform = MyForm(request.GET)
> if request.GET.get('action') == True:
> if myform.is_valid():
>...
> ...
> return render_to_response ('template.html', {'form' : myform})
>
> When I first go to the page, requet.GET.get('action') is None. When I
> click the 'submit' button, again requet.GET.get('action') is None. I
> used HttpResponse to return requet.GET.get('action') as a string.
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-13 Thread ichbindev

This is what my template looks like:

{{ form.as_table }} 

This is what my view looks like:

...
myform = MyForm()
if request.method=="GET":
myform = MyForm(request.GET)
if request.GET.get('action') == True:
if myform.is_valid():
...
...
return render_to_response ('template.html', {'form' : myform})

When I first go to the page, requet.GET.get('action') is None. When I
click the 'submit' button, again requet.GET.get('action') is None. I
used HttpResponse to return requet.GET.get('action') as a string.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-13 Thread Bartek Gniado
If errors are showing when you first load the page then you need to check
that the user has actually completed an action before validating the form.

In this case, doing something like
if request.GET.get('action') == True:
   # your form validation here

In your links back to the system, simply add an ?action=true (or whatever)
and that'll fix your issue there.


On Fri, Jun 13, 2008 at 10:03 PM, ichbindev <[EMAIL PROTECTED]> wrote:

>
> The problem is when I use
>
> myform = MyForm(request.GET)
> if myform.is_valid():
> ...
>
> Any fields which are required have their error message activated on
> first visit to page. Also, any 'initial' value that I put in the forms
> is not shown.
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-13 Thread ichbindev

The problem is when I use

myform = MyForm(request.GET)
if myform.is_valid():
...

Any fields which are required have their error message activated on
first visit to page. Also, any 'initial' value that I put in the forms
is not shown.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-13 Thread Russell Keith-Magee

On Sat, Jun 14, 2008 at 9:05 AM, ichbindev <[EMAIL PROTECTED]> wrote:
>
> However, form.is_valid() is for POST only. Is there an is_valid() kind
> of thing for forms where method is GET so that data may be validated?

I don't know what gave you the idea that is_valid() is just for POST
data. There is nothing in the newforms framework that is tied
specifically to POST data. You can bind _any_ data to a form, whatever
the source.

Most of the examples you will see use POST data, because that's the
most common way to use forms. However, if you can call:

myform = MyForm(request.POST)
if myform.is_valid():
   ...

you could also call:

myform = MyForm(request.GET)
if myform.is_valid():
   ...

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation

2008-06-11 Thread Adi

Thanks,

I will make that change so that the database integrity is maintained.
But I also want to do this on the form level. I can do this outside
the form in the view but i think that might be inelegant. I will have
to create the validation errors by hand and put it in the
error_messages for the form.

-Adi

On Jun 11, 9:09 am, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> Just an idea, not sure if it will work for you as I don't know a whole lot
> about how it works, but wouldn't setting unique_together on the Relation
> class for owner and pet accomplish what you want?  The validation happens at
> the DB level, but I believe it propogates back to the form.
> hth,
> -richard
>
> On 6/11/08, Adi <[EMAIL PROTECTED]> wrote:
>
>
>
> > Right.. I do that for setting the foreign key..
> > But I want to know how to do form validation when I need a related
> > model object inside the validation logic.
>
> > On Jun 11, 12:29 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > wrote:
> > > on a modelform you can do: form.save(commit=False), which will return
> > > an instance of the model, but doesn't save it to the db, so you can
> > > just assign request.user to owner and than save it.
>
> > > On Jun 11, 12:07 am, Adi <[EMAIL PROTECTED]> wrote:
>
> > > > I guess... the more deeper question is.. how can I pass a related
> > > > model object and potentiall an unrelated model object into the form's
> > > > validations methods?
>
> > > > On Jun 10, 10:42 pm, Adi <[EMAIL PROTECTED]> wrote:
>
> > > > > Hi,
> > > > > I have a model  Owner and a model Relation.
>
> > > > > class  Relation(models.Model):
> > > > > pet=models.CharField(max_length=2)
> > > > > owner = models.ForeignKey (Owner)
>
> > > > > then I have a ModelForm
>
> > > > > class RelationForm(ModelForm):
> > > > >class Meta:
> > > > >fields  = ('pet')
>
> > > > > The application flow works like this: You create a Relation object
> > > > > within the context of an Owner Object. There is a rule that says that
> > > > > a owner cannot have two Relation with the same pet value. How can I
> > > > > create a validation on the form that can check this rule. Basically,
> > > > > How can i pass owner object that I have in the view when I call
> > > > > RelationForm.is_valid()
>
> > > > > -Adi- Hide quoted text -
>
> > > - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



  1   2   >