django form validation error massage not showing. please help me out

2023-09-15 Thread Mohammad Shahidullah
models.py
class Position(models.Model):
title = models.CharField(max_length=50)

def __str__(self):
return self.title

class Department(models.Model):
title = models.CharField(max_length=50)

def __str__(self):
return self.title


class Employee(models.Model):
fullname = models.CharField(max_length=100)
emp_code = models.CharField(max_length=6)
mobile= models.CharField(max_length=11)
email = models.EmailField(max_length=25)
position= models.ForeignKey(Position,on_delete=models.CASCADE)
Department = models.ForeignKey(Department, on_delete=models.CASCADE)
password_first = models.CharField(max_length=25)
password_again = models.CharField(max_length=25)

def __str__ (self):
return self.fullname

forms.py
User = get_user_model()

class EmployeeForm(forms.ModelForm):

class Meta:
model = Employee
fields = ('fullname','mobile','emp_code','position', 'Department',
'email', 'password_first', 'password_again')
labels = {
'fullname':'Full Name',
'emp_code':'Employee Code',
'password_first': 'Password',
'password_again': 'Confirm Password',
}

widgets = {
'password_first': forms.PasswordInput(),
'password_again' : forms.PasswordInput(),
}


def __init__(self, *args, **kwargs):
super(EmployeeForm,self).__init__(*args, **kwargs)
self.fields['position'].empty_label = "Select"
self.fields['Department'].empty_label = "Select"



def clean_username(self):
username = self.cleaned_data.get('emp_code')
qs = User.objects.filter(username=username)
if qs.exists():
raise forms.ValidationError('username already exists')
return username

def clean(self):
cleaned_data = self.cleaned_data
password_first = self.cleaned_data.get('password_first')
password_again = self.cleaned_data.get('password_again')
if password_first and password_again and password_first != 
password_again:
raise forms.ValidationError("Passwords din't match")
return cleaned_data

def clean_email(self):
email_address = self.cleaned_data.get('email')
qs = User.objects.filter(email=email_address)
if qs.exists():
raise forms.ValidationError("This email_id already registered")
return email_address

views.py
def employee_form(request, id=0):
if request.method == "GET":
if id == 0:
form = EmployeeForm()
else:
employee = Employee.objects.get(pk=id)
form = EmployeeForm(instance=employee)
return render(request, "users/employee_form.html", {'form': form})
else:
if id == 0:
form = EmployeeForm(request.POST)
else:
employee = Employee.objects.get(pk=id)
form = EmployeeForm(request.POST,instance= employee)
if form.is_valid():
form.save()
return redirect('/list')


employee_form.html


{% block content %}


{% csrf_token %}
{{form.fullname|as_crispy_field}}
{{form.mobile|as_crispy_field}}
{{form.email|as_crispy_field}}



{{form.emp_code|as_crispy_field}}


{{form.position|as_crispy_field}}


{{form.Department|as_crispy_field}}





{{form.password_first|as_crispy_field}}


{{form.password_again|as_crispy_field}}






<
i class="fas fa-database">
Submit



 Back to list





{% if form.error %}
{% for field in form %}
{% for error in field.error %}
 {{ errors }} 
{% endfor %}
{% endfor %}

{% for error in form.non_field_error %}
 {{ error }} 
{% endfor %}
{% endif %}




{% endblock content %}



-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6ba949b0-0fc4-443c-ba27-136754fbd1f5n%40googlegroups.com.


Re: New user question: Where to put non-form validation code?

2019-07-25 Thread Matt Zand
Hi everyone,
Does anyone know how to post blog at below page:
https://www.djangoproject.com/community/blogs/

I am really frustrated as I submitted last week but nothing is there. Who
is in charge of blog posts on Django site?

Thx,
Matt



On Thu, Jul 25, 2019 at 12:38 AM Mike Dewhirst 
wrote:

> On 25/07/2019 1:03 pm, Jim Illback wrote:
> > I had a slight variation on this thread - where to put some M2M field
> > validation/deletion logic.
> >
> > I have a purely model-based form where a checkbox’s value determines
> > whether another field (it’s a M2M field) in the form should be NULL or
> > keep its values to be saved in the database. So, following the
> > appropriate separation of concerns as advocated below, I added logic
> > in both the models' clean and save override methods. Neither approach
> > set the other field to NULL when it should have been. The reason is
> > the form still contained M2M values even though the model said to
> > delete them (delete the set, actually).
> >
> > After a lot of trial and error, it turns out that the model’s save
> > seems to be run BEFORE the form’s save. To me, that seems backwards.
> > Shouldn’t the model’s processes (which are directly relate to the
> > database, the ultimate data source) occur last and well before the
> > form’s (which are merely an interaction with the user)? What was
> > happening was my model’s delete actually did the deletions (those IDs
> > were gone), but then the form’s processing came along afterwards and
> > re-inserted them again (with brand new IDs).
>
> Don't know what's happening here but you can be sure Django is doing it
> the right way.
>
> Maybe you need to look at your on_delete constants. models.CASCADE
> versus models.SET_NULL or models.PROTECT
>
> >
> > Can someone help me understand why Django has chosen this seemingly
> > “inversion” of processing - first models’ processes, then forms’? And,
> > perhaps more importantly, where should this either/or logic should be
> > placed so it will take effect?
> >
> > Thanks very much,
> > Jim Illback
> >
> >> On Jul 13, 2019, at 11:48 PM, Mike Dewhirst  >> > wrote:
> >>
> >> Well yes it could be called multifaceted.
> >>
> >> Usually but not always the interface with the user is the form. You
> >> can have non-database fields as well as model fields so either way
> >> there has to be a full suite of validation functionality available in
> >> both types of forms. Luckily, model forms automatically call
> >> model.clean() for you.
> >>
> >> Unit tests don't though. You have deliberately call obj.clean() if
> >> you want to test things. obj.save() doesn't call obj.clean().
> >>
> >> Actually, I also do a bit in view code too especially if there are
> >> non-database or hidden fields in the form. I know you are not
> >> supposed to validate data in a view for proper separation of concerns
> >> but it does keep my forms neater.
> >>
> >> The bottom line for me is that if I can imagine non-form access ...
> >> eg through an API ... then all validation possible has to be via
> >> model.clean() and the API has to remember to call clean() before
> >> saving every time there is a POST
> >>
> >> Hence I*always*put business rules validation in model.clean() and
> >> leave 'local' validation for the form.
> >>
> >> You are right. There are quite a few moving parts
> >>
> >> /Connected by Motorola/
> >>
> >>
> >> Dean Karres mailto:dean.kar...@gmail.com>>
> wrote:
> >>
> >> Thank you. There are way more parts to this than I would have imagined.
> >>
> >>
> >>
> >> On Sat, Jul 13, 2019, 8:01 PM Mike Dewhirst  >> > wrote:
> >>
> >> On 14/07/2019 10:37 am, Dean Karres wrote:
> >>> Hi,
> >>>
> >>> I am learning Django.  I am using CBVs.  My default "index.py"
> >>> view is basically a dashboard for the app I am playing with.  As
> >>> my models and views become more complicated I want to be able to
> >>> ask, for any model instance, is this instance "valid" or
> >>> "complete".  Valid means that all Required elements are present
> >>> and have reasonable values.  "Complete" means that an instance
> >>> is "valid" but also some specific bits of additional info are
> >>> also ok.
> >>>
> >>> For example I have a Student model that has name and address
> >>> info.  There is a ManyToMany relation to the Class(es) in which
> >>> that Student is enrolled.  A "student" instance is valid if the
> >>> name and address fields are filled.  A student is "complete" if
> >>> the student is valid and has signed up for one or more classes.
> >>>
> >>> So, my question is: where should the valid and complete methods
> >>> live?  Should they be in the Student model or CBV? Someplace
> >>> else?  Does it matter?
> >>
> >> I like to put that sort of stuff into model methods then add
> >> model.clean() to call them and raise whatever error may be
> >> appropriate if they fail.

Re: New user question: Where to put non-form validation code?

2019-07-24 Thread Mike Dewhirst

On 25/07/2019 1:03 pm, Jim Illback wrote:
I had a slight variation on this thread - where to put some M2M field 
validation/deletion logic.


I have a purely model-based form where a checkbox’s value determines 
whether another field (it’s a M2M field) in the form should be NULL or 
keep its values to be saved in the database. So, following the 
appropriate separation of concerns as advocated below, I added logic 
in both the models' clean and save override methods. Neither approach 
set the other field to NULL when it should have been. The reason is 
the form still contained M2M values even though the model said to 
delete them (delete the set, actually).


After a lot of trial and error, it turns out that the model’s save 
seems to be run BEFORE the form’s save. To me, that seems backwards. 
Shouldn’t the model’s processes (which are directly relate to the 
database, the ultimate data source) occur last and well before the 
form’s (which are merely an interaction with the user)? What was 
happening was my model’s delete actually did the deletions (those IDs 
were gone), but then the form’s processing came along afterwards and 
re-inserted them again (with brand new IDs).


Don't know what's happening here but you can be sure Django is doing it 
the right way.


Maybe you need to look at your on_delete constants. models.CASCADE 
versus models.SET_NULL or models.PROTECT




Can someone help me understand why Django has chosen this seemingly 
“inversion” of processing - first models’ processes, then forms’? And, 
perhaps more importantly, where should this either/or logic should be 
placed so it will take effect?


Thanks very much,
Jim Illback

On Jul 13, 2019, at 11:48 PM, Mike Dewhirst > wrote:


Well yes it could be called multifaceted.

Usually but not always the interface with the user is the form. You 
can have non-database fields as well as model fields so either way 
there has to be a full suite of validation functionality available in 
both types of forms. Luckily, model forms automatically call 
model.clean() for you.


Unit tests don't though. You have deliberately call obj.clean() if 
you want to test things. obj.save() doesn't call obj.clean().


Actually, I also do a bit in view code too especially if there are 
non-database or hidden fields in the form. I know you are not 
supposed to validate data in a view for proper separation of concerns 
but it does keep my forms neater.


The bottom line for me is that if I can imagine non-form access ... 
eg through an API ... then all validation possible has to be via 
model.clean() and the API has to remember to call clean() before 
saving every time there is a POST


Hence I*always*put business rules validation in model.clean() and 
leave 'local' validation for the form.


You are right. There are quite a few moving parts

/Connected by Motorola/


Dean Karres mailto:dean.kar...@gmail.com>> wrote:

Thank you. There are way more parts to this than I would have imagined.



On Sat, Jul 13, 2019, 8:01 PM Mike Dewhirst > wrote:


On 14/07/2019 10:37 am, Dean Karres wrote:

Hi,

I am learning Django.  I am using CBVs.  My default "index.py"
view is basically a dashboard for the app I am playing with.  As
my models and views become more complicated I want to be able to
ask, for any model instance, is this instance "valid" or
"complete".  Valid means that all Required elements are present
and have reasonable values.  "Complete" means that an instance
is "valid" but also some specific bits of additional info are
also ok.

For example I have a Student model that has name and address
info.  There is a ManyToMany relation to the Class(es) in which
that Student is enrolled.  A "student" instance is valid if the
name and address fields are filled.  A student is "complete" if
the student is valid and has signed up for one or more classes.

So, my question is: where should the valid and complete methods
live?  Should they be in the Student model or CBV? Someplace
else?  Does it matter?


I like to put that sort of stuff into model methods then add
model.clean() to call them and raise whatever error may be
appropriate if they fail.


https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#interaction-with-model-validation

and


https://docs.djangoproject.com/en/2.1/ref/models/instances/#validating-objects

and


https://docs.djangoproject.com/en/2.1/ref/models/instances/#django.db.models.Model.clean

You can raise your own errors which inherit from ValidationError
to fine tune the process. For example, I differentiate between
BusinessRuleViolation and InvalidToken and a couple of others
where that delivers better control.




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

Re: New user question: Where to put non-form validation code?

2019-07-24 Thread Mike Dewhirst

On 25/07/2019 1:03 pm, Jim Illback wrote:
I had a slight variation on this thread - where to put some M2M field 
validation/deletion logic.


I have a purely model-based form where a checkbox’s value determines 
whether another field (it’s a M2M field) in the form should be NULL or 
keep its values to be saved in the database. So, following the 
appropriate separation of concerns as advocated below, I added logic 
in both the models' clean and save override methods. Neither approach 
set the other field to NULL when it should have been. The reason is 
the form still contained M2M values even though the model said to 
delete them (delete the set, actually).


There's a bit of trapeze happening here. The form is always in mid-air. 
No matter what happens in the form the model save is only called when 
all the validation (ie form first for the obvious errors then model for 
business rules) has succeeded.


So, boolean (or any other) field values don't make it into the database 
until model.save() succeeds.


And, the framework logic has to cope with database rejection of the 
values as well. So the entire transaction needs to be able to roll back 
if something goes awry at the last moment. Keep your eye on 
transactions. I think PostgreSQL is probably the best of the open source 
RDBMSs for that. I know Django seems to have no problems with it.


My typical approach in the model to see things before and after the save 
is ...


def save(self, *args, **kwargs:
    var_to_be_passed = self._pre_save()
    super(ThisModel, self).save(*args, **kwargs)
    self._post_save(var_to_be_passed)

I use self._post_save() usually to do additional database things like 
creating child models.


If your user-initiated change relies on a value in the database then you 
have to save it first so it gets there.


Also, remember that the model's clean() method is only ever called by 
Django when a ModelForm is used. Otherwise you have to call it yourself. 
That's where I put all my business rule validation. I typically have 
separate mofel methods and just call thin in clean() and raise 
validation errors if necessary. That is totally appropriate because a 
Django form knows how to deal with them.


As I said previously, in unti tests you have to call clean() explicitly.



After a lot of trial and error, it turns out that the model’s save 
seems to be run BEFORE the form’s save. To me, that seems backwards. 
Shouldn’t the model’s processes (which are directly relate to the 
database, the ultimate data source) occur last and well before the 
form’s (which are merely an interaction with the user)? What was 
happening was my model’s delete actually did the deletions (those IDs 
were gone), but then the form’s processing came along afterwards and 
re-inserted them again (with brand new IDs).


Can someone help me understand why Django has chosen this seemingly 
“inversion” of processing - first models’ processes, then forms’? And, 
perhaps more importantly, where should this either/or logic should be 
placed so it will take effect?


Thanks very much,
Jim Illback

On Jul 13, 2019, at 11:48 PM, Mike Dewhirst > wrote:


Well yes it could be called multifaceted.

Usually but not always the interface with the user is the form. You 
can have non-database fields as well as model fields so either way 
there has to be a full suite of validation functionality available in 
both types of forms. Luckily, model forms automatically call 
model.clean() for you.


Unit tests don't though. You have deliberately call obj.clean() if 
you want to test things. obj.save() doesn't call obj.clean().


Actually, I also do a bit in view code too especially if there are 
non-database or hidden fields in the form. I know you are not 
supposed to validate data in a view for proper separation of concerns 
but it does keep my forms neater.


The bottom line for me is that if I can imagine non-form access ... 
eg through an API ... then all validation possible has to be via 
model.clean() and the API has to remember to call clean() before 
saving every time there is a POST


Hence I*always*put business rules validation in model.clean() and 
leave 'local' validation for the form.


You are right. There are quite a few moving parts

/Connected by Motorola/


Dean Karres mailto:dean.kar...@gmail.com>> wrote:

Thank you. There are way more parts to this than I would have imagined.



On Sat, Jul 13, 2019, 8:01 PM Mike Dewhirst > wrote:


On 14/07/2019 10:37 am, Dean Karres wrote:

Hi,

I am learning Django.  I am using CBVs.  My default "index.py"
view is basically a dashboard for the app I am playing with.  As
my models and views become more complicated I want to be able to
ask, for any model instance, is this instance "valid" or
"complete".  Valid means that all Required elements are present
and have reasonable values.  "Complete" means that an instance
is "valid" but 

Re: New user question: Where to put non-form validation code?

2019-07-24 Thread Jim Illback
I had a slight variation on this thread - where to put some M2M field 
validation/deletion logic.

I have a purely model-based form where a checkbox’s value determines whether 
another field (it’s a M2M field) in the form should be NULL or keep its values 
to be saved in the database. So, following the appropriate separation of 
concerns as advocated below, I added logic in both the models' clean and save 
override methods. Neither approach set the other field to NULL when it should 
have been. The reason is the form still contained M2M values even though the 
model said to delete them (delete the set, actually).

After a lot of trial and error, it turns out that the model’s save seems to be 
run BEFORE the form’s save. To me, that seems backwards. Shouldn’t the model’s 
processes (which are directly relate to the database, the ultimate data source) 
occur last and well before the form’s (which are merely an interaction with the 
user)? What was happening was my model’s delete actually did the deletions 
(those IDs were gone), but then the form’s processing came along afterwards and 
re-inserted them again (with brand new IDs).

Can someone help me understand why Django has chosen this seemingly “inversion” 
of processing - first models’ processes, then forms’? And, perhaps more 
importantly, where should this either/or logic should be placed so it will take 
effect?

Thanks very much,
Jim Illback

On Jul 13, 2019, at 11:48 PM, Mike Dewhirst 
mailto:mi...@dewhirst.com.au>> wrote:

Well yes it could be called multifaceted.

Usually but not always the interface with the user is the form. You can have 
non-database fields as well as model fields so either way there has to be a 
full suite of validation functionality available in both types of forms. 
Luckily, model forms automatically call model.clean() for you.

Unit tests don't though. You have deliberately call obj.clean() if you want to 
test things. obj.save() doesn't call obj.clean().

Actually, I also do a bit in view code too especially if there are non-database 
or hidden fields in the form. I know you are not supposed to validate data in a 
view for proper separation of concerns but it does keep my forms neater.

The bottom line for me is that if I can imagine non-form access ... eg through 
an API ... then all validation possible has to be via model.clean() and the API 
has to remember to call clean() before saving every time there is a POST

Hence I always put business rules validation in model.clean() and leave 'local' 
validation for the form.

You are right. There are quite a few moving parts 

Connected by Motorola


Dean Karres mailto:dean.kar...@gmail.com>> wrote:

Thank you. There are way more parts to this than I would have imagined.



On Sat, Jul 13, 2019, 8:01 PM Mike Dewhirst 
mailto:mi...@dewhirst.com.au>> wrote:
On 14/07/2019 10:37 am, Dean Karres wrote:
Hi,

I am learning Django.  I am using CBVs.  My default "index.py" view is 
basically a dashboard for the app I am playing with.  As my models and views 
become more complicated I want to be able to ask, for any model instance, is 
this instance "valid" or "complete".  Valid means that all Required elements 
are present and have reasonable values.  "Complete" means that an instance is 
"valid" but also some specific bits of additional info are also ok.

For example I have a Student model that has name and address info.  There is a 
ManyToMany relation to the Class(es) in which that Student is enrolled.  A 
"student" instance is valid if the name and address fields are filled.  A 
student is "complete" if the student is valid and has signed up for one or more 
classes.

So, my question is: where should the valid and complete methods live?  Should 
they be in the Student model or CBV?  Someplace else?  Does it matter?

I like to put that sort of stuff into model methods then add model.clean() to 
call them and raise whatever error may be appropriate if they fail.

https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#interaction-with-model-validation

and

https://docs.djangoproject.com/en/2.1/ref/models/instances/#validating-objects

and

https://docs.djangoproject.com/en/2.1/ref/models/instances/#django.db.models.Model.clean

You can raise your own errors which inherit from ValidationError to fine tune 
the process. For example, I differentiate between BusinessRuleViolation and 
InvalidToken and a couple of others where that delivers better control.



Cheers
--
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 

Re: New user question: Where to put non-form validation code?

2019-07-14 Thread Mike Dewhirst
Well yes it could be called multifaceted.  

Usually but not always the interface with the user is the form. You can have 
non-database fields as well as model fields so either way there has to be a 
full suite of validation functionality available in both types of forms. 
Luckily, model forms automatically call model.clean() for you. 

Unit tests don't though. You have deliberately call obj.clean() if you want to 
test things. obj.save() doesn't call obj.clean().

Actually, I also do a bit in view code too especially if there are non-database 
or hidden fields in the form. I know you are not supposed to validate data in a 
view for proper separation of concerns but it does keep my forms neater.

The bottom line for me is that if I can imagine non-form access ... eg through 
an API ... then all validation possible has to be via model.clean() and the API 
has to remember to call clean() before saving every time there is a POST

Hence I always put business rules validation in model.clean() and leave 'local' 
validation for the form. 

You are right. There are quite a few moving parts  :-) 

Connected by Motorola

Dean Karres  wrote:

>Thank you. There are way more parts to this than I would have imagined.
>
>
>
>
>On Sat, Jul 13, 2019, 8:01 PM Mike Dewhirst  wrote:
>
>On 14/07/2019 10:37 am, Dean Karres wrote:
>
>Hi, 
>
>
>I am learning Django.  I am using CBVs.  My default "index.py" view is 
>basically a dashboard for the app I am playing with.  As my models and views 
>become more complicated I want to be able to ask, for any model instance, is 
>this instance "valid" or "complete".  Valid means that all Required elements 
>are present and have reasonable values.  "Complete" means that an instance is 
>"valid" but also some specific bits of additional info are also ok.
>
>
>For example I have a Student model that has name and address info.  There is a 
>ManyToMany relation to the Class(es) in which that Student is enrolled.  A 
>"student" instance is valid if the name and address fields are filled.  A 
>student is "complete" if the student is valid and has signed up for one or 
>more classes.
>
>
>So, my question is: where should the valid and complete methods live?  Should 
>they be in the Student model or CBV?  Someplace else?  Does it matter?
>
>
>I like to put that sort of stuff into model methods then add model.clean() to 
>call them and raise whatever error may be appropriate if they fail.
>
>https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#interaction-with-model-validation
>
>and
>
>https://docs.djangoproject.com/en/2.1/ref/models/instances/#validating-objects
>
>and
>
>https://docs.djangoproject.com/en/2.1/ref/models/instances/#django.db.models.Model.clean
>
>You can raise your own errors which inherit from ValidationError to fine tune 
>the process. For example, I differentiate between BusinessRuleViolation and 
>InvalidToken and a couple of others where that delivers better control.
>
>
>
>Cheers
>
>-- 
>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/22801669-96ec-4a43-a264-fd50c2544604%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/ajujeafh6d4qa4vvpfv2bxf9.1563085360028%40email.android.com.
For more options, visit https://groups.google.com/d/optout.


RE: New user question: Where to put non-form validation code?

2019-07-13 Thread laya
Hi
If I got your meaning Truly. It should be mentioned that as I know there is not 
any difference for using validation in model or View . Usually in model, we use 
regex for validation and in View  it needs to use some methods for Email 
Validation and etc.

Sent from Mail for Windows 10

From: Dean Karres
Sent: Saturday, July 13, 2019 5:40 PM
To: Django users
Subject: New user question: Where to put non-form validation code?

Hi,

I am learning Django.  I am using CBVs.  My default "index.py" view is 
basically a dashboard for the app I am playing with.  As my models and views 
become more complicated I want to be able to ask, for any model instance, is 
this instance "valid" or "complete".  Valid means that all Required elements 
are present and have reasonable values.  "Complete" means that an instance is 
"valid" but also some specific bits of additional info are also ok.

For example I have a Student model that has name and address info.  There is a 
ManyToMany relation to the Class(es) in which that Student is enrolled.  A 
"student" instance is valid if the name and address fields are filled.  A 
student is "complete" if the student is valid and has signed up for one or more 
classes.

So, my question is: where should the valid and complete methods live?  Should 
they be in the Student model or CBV?  Someplace else?  Does it matter?

Cheers
-- 
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/22801669-96ec-4a43-a264-fd50c2544604%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/5d2ab038.1c69fb81.ede47.7dde%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.


Re: New user question: Where to put non-form validation code?

2019-07-13 Thread Dean Karres
Thank you. There are way more parts to this than I would have imagined.



On Sat, Jul 13, 2019, 8:01 PM Mike Dewhirst  wrote:

> On 14/07/2019 10:37 am, Dean Karres wrote:
>
> Hi,
>
> I am learning Django.  I am using CBVs.  My default "index.py" view is
> basically a dashboard for the app I am playing with.  As my models and
> views become more complicated I want to be able to ask, for any model
> instance, is this instance "valid" or "complete".  Valid means that all
> Required elements are present and have reasonable values.  "Complete" means
> that an instance is "valid" but also some specific bits of additional info
> are also ok.
>
> For example I have a Student model that has name and address info.  There
> is a ManyToMany relation to the Class(es) in which that Student is
> enrolled.  A "student" instance is valid if the name and address fields are
> filled.  A student is "complete" if the student is valid and has signed up
> for one or more classes.
>
> So, my question is: where should the valid and complete methods live?
> Should they be in the Student model or CBV?  Someplace else?  Does it
> matter?
>
>
> I like to put that sort of stuff into model methods then add model.clean()
> to call them and raise whatever error may be appropriate if they fail.
>
>
> https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#interaction-with-model-validation
>
> and
>
>
> https://docs.djangoproject.com/en/2.1/ref/models/instances/#validating-objects
>
> and
>
>
> https://docs.djangoproject.com/en/2.1/ref/models/instances/#django.db.models.Model.clean
>
> You can raise your own errors which inherit from ValidationError to fine
> tune the process. For example, I differentiate between
> BusinessRuleViolation and InvalidToken and a couple of others where that
> delivers better control.
>
>
>
> Cheers
> --
> 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/22801669-96ec-4a43-a264-fd50c2544604%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/CAO%2B1Q_uv_PN%3Dm8Ny5zWyQVGbSkY2mnwZJO-dYQy2yL8CbOTgsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: New user question: Where to put non-form validation code?

2019-07-13 Thread Mike Dewhirst

On 14/07/2019 10:37 am, Dean Karres wrote:

Hi,

I am learning Django.  I am using CBVs.  My default "index.py" view is 
basically a dashboard for the app I am playing with.  As my models and 
views become more complicated I want to be able to ask, for any model 
instance, is this instance "valid" or "complete".  Valid means that 
all Required elements are present and have reasonable values.  
"Complete" means that an instance is "valid" but also some specific 
bits of additional info are also ok.


For example I have a Student model that has name and address info.  
There is a ManyToMany relation to the Class(es) in which that Student 
is enrolled.  A "student" instance is valid if the name and address 
fields are filled.  A student is "complete" if the student is valid 
and has signed up for one or more classes.


So, my question is: where should the valid and complete methods live?  
Should they be in the Student model or CBV? Someplace else?  Does it 
matter?


I like to put that sort of stuff into model methods then add 
model.clean() to call them and raise whatever error may be appropriate 
if they fail.


https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#interaction-with-model-validation

and

https://docs.djangoproject.com/en/2.1/ref/models/instances/#validating-objects

and

https://docs.djangoproject.com/en/2.1/ref/models/instances/#django.db.models.Model.clean

You can raise your own errors which inherit from ValidationError to fine 
tune the process. For example, I differentiate between 
BusinessRuleViolation and InvalidToken and a couple of others where that 
delivers better control.





Cheers
--
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/22801669-96ec-4a43-a264-fd50c2544604%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/d97da99d-4d15-1467-251b-487e604f0b18%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


New user question: Where to put non-form validation code?

2019-07-13 Thread Dean Karres
Hi,

I am learning Django.  I am using CBVs.  My default "index.py" view is 
basically a dashboard for the app I am playing with.  As my models and 
views become more complicated I want to be able to ask, for any model 
instance, is this instance "valid" or "complete".  Valid means that all 
Required elements are present and have reasonable values.  "Complete" means 
that an instance is "valid" but also some specific bits of additional info 
are also ok.

For example I have a Student model that has name and address info.  There 
is a ManyToMany relation to the Class(es) in which that Student is 
enrolled.  A "student" instance is valid if the name and address fields are 
filled.  A student is "complete" if the student is valid and has signed up 
for one or more classes.

So, my question is: where should the valid and complete methods live?  
Should they be in the Student model or CBV?  Someplace else?  Does it 
matter?

Cheers

-- 
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/22801669-96ec-4a43-a264-fd50c2544604%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django: Form validation strange behaviour

2017-09-29 Thread Constantine Covtushenko
Hi Paul,

You should return value from 'clean_document'.
>From your code I see you do not do that. When method returns nothing it is
None.
That is why you see 'This field cannot be blank.'

I hope that make sense.

Regards,
Constantine C.

On Fri, Sep 29, 2017 at 7:01 AM, Paul  wrote:

> I want to do file validation(size,type) on a field on inlineformset.
>
>
> class ProductDocumentModelForm(ModelForm):
>
>   class Meta: model = ProductDocument
>fields = ['document']
>
>   def clean_document(self):
>file = self.cleaned_data['document']
>validate_file(file, 'document')
>
>
>
> Because I want to use the same validation in multiple application I
> created a separate function.
>
>
> def validate_file(file, for_model, max_size=5000):
>  if for_model == 'document':
>   max_size = FILE_MAX_DOC_SIZE
>
>  if file.size > max_size:
>   raise ValidationError('Please keep file size under {}. Current file size is 
> {}' .format(filesizeformat(FILE_MAX_DOC_SIZE), filesizeformat(file.size)))
>
>
>
> The file size validation works as intended but introduce a strange
> behavior.
>
>
> If this validation is in place and is passed the "This field cannot be
> blank." default validation is triggered even if the fields are not empty.
>
>
> Without the file size validation in place there are no issue even if the
> fields are empty.
>
>
> I don't understand what is the cause.
>
> --
> 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/a470e4e3-3cb9-489e-930c-8adc6b6210c3%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boWRk%3DScciWGskkmg%2BuWOMzPrtxzBccu2ZyHxrGKKn5ioA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django: Form validation strange behaviour

2017-09-29 Thread Paul
 

I want to do file validation(size,type) on a field on inlineformset. 


class ProductDocumentModelForm(ModelForm): 

  class Meta: model = ProductDocument 
   fields = ['document'] 

  def clean_document(self): 
   file = self.cleaned_data['document'] 
   validate_file(file, 'document')



Because I want to use the same validation in multiple application I created 
a separate function.


def validate_file(file, for_model, max_size=5000): 
 if for_model == 'document': 
  max_size = FILE_MAX_DOC_SIZE 
 
 if file.size > max_size: 
  raise ValidationError('Please keep file size under {}. Current file size is 
{}' .format(filesizeformat(FILE_MAX_DOC_SIZE), filesizeformat(file.size)))



The file size validation works as intended but introduce a strange behavior.


If this validation is in place and is passed the "This field cannot be 
blank." default validation is triggered even if the fields are not empty.


Without the file size validation in place there are no issue even if the 
fields are empty.


I don't understand what is the cause. 

-- 
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/a470e4e3-3cb9-489e-930c-8adc6b6210c3%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 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.


Form Validation Error NOT Raised When Form Is Submitted

2016-12-22 Thread Chris Kavanagh
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 }}



-- 
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.


Re: Possible bug with UploadedFile and form validation?

2016-06-13 Thread Simon Charette
Hi Nick,

`io.TextIOWrapper` objects close their wrapped file when they are garbage
collected (e.g. `__del__()`). This is similar to how `File` objects close 
their
underlying file descriptor when collected.

In the case of your `clean()` method the `file` object can be garbaged 
collected
as soon as the method ends as you don't hold any more references to `reader`
(which is the only object refererencing `file`).

If you want to prevent the underlying file from being closed you'll have to
manually disconnect the `file` object from its stream by using 
`detach()`[1].

Make sure to call it in all cases, even when throwing the `ValidationError`.

Cheers,
Simon

[1] 
https://docs.python.org/3/library/io.html?highlight=textiowrapper#io.BufferedIOBase.detach

Le lundi 13 juin 2016 10:52:36 UTC-4, Nick Sarbicki a écrit :
>
> I've got an odd bug in my system, and while I'm not 100% convinced it is a 
> Django bug, I don't think it is due to me either so thought I'd ask here 
> for some clarification.
>
> Essentially if you upload a file to a form. If that forms clean() method 
> reads that file (in my case it gathers data and makes sure it is valid), 
> and the clean fails, a ValueError is always raised.
>
> ValueError at /
>
> I/O operation on closed file.
>
>
> As far as django is concerned this is happening in the template at:
>
> 31{% if form.non_field_errors %}
> 32{{ 
> form.non_field_errors|striptags 
> }}
> 33
> 34{% endif %}
>
>
> Admittedly, I am wrapping this in a TextIOWrapper.
>
> Example below is a good example of what I'm doing:
>
>
> def clean(self):
>
> cleaned_data = super(ReportScheduleForm, self).clean()
>
> file = TextIOWrapper(self.cleaned_data['uploaded_file'].file, 
> encoding='utf-8')
>
> self.cleaned_data['ids'] = []
> try:
> reader = csv.DictReader(file)
> except KeyError:
> # File doesn't exist, which will raise its own error.
> pass
>
> try:
> for row in reader:
> if row['col_name']:
> self.cleaned_data['ids'].append(row['col_name'])
> except KeyError:
> raise ValidationError('The file must be a csv with a column 
> title col_name.')
>
>
> What I gather is happening is that this clean function is run on the POST 
> request. During this call the file is read through and errors, during which 
> it is *closed*. After when trying to display the non_field_errors the 
> file is still closed and therefore raises the error.
>
> Is this a bug? Should the file be forced to close at this point? Or am I 
> missing something important?
>

-- 
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/26f0b0c0-f3da-4b8d-b2dc-df5898c46698%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Possible bug with UploadedFile and form validation?

2016-06-13 Thread Nick Sarbicki
I've got an odd bug in my system, and while I'm not 100% convinced it is a 
Django bug, I don't think it is due to me either so thought I'd ask here 
for some clarification.

Essentially if you upload a file to a form. If that forms clean() method 
reads that file (in my case it gathers data and makes sure it is valid), 
and the clean fails, a ValueError is always raised.

ValueError at /

I/O operation on closed file.


As far as django is concerned this is happening in the template at:

31{% if form.non_field_errors %}
32{{ form.non_field_errors|striptags 
}}
33
34{% endif %}


Admittedly, I am wrapping this in a TextIOWrapper.

Example below is a good example of what I'm doing:


def clean(self):

cleaned_data = super(ReportScheduleForm, self).clean()

file = TextIOWrapper(self.cleaned_data['uploaded_file'].file, 
encoding='utf-8')

self.cleaned_data['ids'] = []
try:
reader = csv.DictReader(file)
except KeyError:
# File doesn't exist, which will raise its own error.
pass

try:
for row in reader:
if row['col_name']:
self.cleaned_data['ids'].append(row['col_name'])
except KeyError:
raise ValidationError('The file must be a csv with a column 
title col_name.')


What I gather is happening is that this clean function is run on the POST 
request. During this call the file is read through and errors, during which 
it is *closed*. After when trying to display the non_field_errors the file 
is still closed and therefore raises the error.

Is this a bug? Should the file be forced to close at this point? Or am I 
missing something important?

-- 
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/8a1ad6c9-0e24-4aa6-8d47-c87c0ea76805%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Weird form validation question

2014-10-09 Thread Sergiy Khohlov
could you please paste  code in form valid block ?

Many thanks,

Serge


+380 636150445
skype: skhohlov

On Thu, Oct 9, 2014 at 11:23 AM, termopro  wrote:

> I am using form.is_valid()
>
> On Thursday, October 9, 2014 10:54:56 AM UTC+3, Sergiy Khohlov wrote:
>>
>> Are you using form_valid method in view ?
>>
>> Many thanks,
>>
>> Serge
>>
>>
>> +380 636150445
>> skype: skhohlov
>>
>> On Thu, Oct 9, 2014 at 10:10 AM, termopro  wrote:
>>
>>> Hi,
>>>
>>> I am building a user registration page. Page has a form where user can
>>> select his current state and city.
>>>
>>> The problem with that is that i cannot load list of cities into the form
>>> when the page is being generated.
>>> That's because i show the user only cities from his state, not all of
>>> them.
>>>
>>> So i generate a form with a list of states and an empty 'cities'. When
>>> user selects one of the states, i populate 'cities' with ajax.
>>>
>>> Everything works fine, except i don't know how to validate 'cities'
>>> correctly and show form errors.
>>> What is the correct way of doing this ?
>>>
>>> --
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/25d67c01-df04-424c-9171-88def729d3a6%
>>> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/035094d3-4359-4823-a991-e2ac2b08c96e%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTRxJO0eMXVdjbLa9S6Q_8krUBEmxiGYwmwSfO6-58QmQkfew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Weird form validation question

2014-10-09 Thread termopro
I am using form.is_valid()

On Thursday, October 9, 2014 10:54:56 AM UTC+3, Sergiy Khohlov wrote:
>
> Are you using form_valid method in view ? 
>
> Many thanks,
>
> Serge
>
>
> +380 636150445
> skype: skhohlov
>
> On Thu, Oct 9, 2014 at 10:10 AM, termopro  > wrote:
>
>> Hi,
>>
>> I am building a user registration page. Page has a form where user can 
>> select his current state and city.
>>
>> The problem with that is that i cannot load list of cities into the form 
>> when the page is being generated.
>> That's because i show the user only cities from his state, not all of 
>> them.
>>
>> So i generate a form with a list of states and an empty 'cities'. When 
>> user selects one of the states, i populate 'cities' with ajax.
>>
>> Everything works fine, except i don't know how to validate 'cities' 
>> correctly and show form errors.
>> What is the correct way of doing this ?
>>
>> -- 
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/25d67c01-df04-424c-9171-88def729d3a6%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/035094d3-4359-4823-a991-e2ac2b08c96e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Weird form validation question

2014-10-09 Thread Sergiy Khohlov
Are you using form_valid method in view ?

Many thanks,

Serge


+380 636150445
skype: skhohlov

On Thu, Oct 9, 2014 at 10:10 AM, termopro  wrote:

> Hi,
>
> I am building a user registration page. Page has a form where user can
> select his current state and city.
>
> The problem with that is that i cannot load list of cities into the form
> when the page is being generated.
> That's because i show the user only cities from his state, not all of them.
>
> So i generate a form with a list of states and an empty 'cities'. When
> user selects one of the states, i populate 'cities' with ajax.
>
> Everything works fine, except i don't know how to validate 'cities'
> correctly and show form errors.
> What is the correct way of doing this ?
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/25d67c01-df04-424c-9171-88def729d3a6%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTRxJNqQ1FhOKxEVF%3DXBa2mcUsFVTyY%3DTQpMTXfg1__ZyRYFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Weird form validation question

2014-10-09 Thread termopro
Hi,

I am building a user registration page. Page has a form where user can 
select his current state and city.

The problem with that is that i cannot load list of cities into the form 
when the page is being generated.
That's because i show the user only cities from his state, not all of them.

So i generate a form with a list of states and an empty 'cities'. When user 
selects one of the states, i populate 'cities' with ajax.

Everything works fine, except i don't know how to validate 'cities' 
correctly and show form errors.
What is the correct way of doing this ?

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/25d67c01-df04-424c-9171-88def729d3a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


error after form validation

2014-01-16 Thread fabricio
I got the following error 


My model http://pastebin.com/2BuE0N0d 


my view http://pastebin.com/48xEPvQz 


  when it reaches this part of the code 

gr_caixafaccao = form_caixafaccao.save (commit = False) 

gr_caixafaccao the object returns me Unable to get repr is  


hence not caught the id. 

can someone help me?

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bdb87af4-c57b-4458-9a6c-7e4521f91d29%40googlegroups.com.
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 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.


Form validation number and text only no space mac 4 numbers

2013-08-31 Thread Gerd Koetje
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.


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 <roman.kle...@gmail.com> 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.




Form validation vs. DRY

2013-07-03 Thread Roman Klesel
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.




form validation

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

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.




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.


<>

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

2013-05-03 Thread Darren Mansell
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: ignore field during form validation

2013-01-23 Thread Sarfraz ahmad
def clean_A6M1F6_F(self):
data=self.cleaned_data['A6M1F6_F']
if A6M1_mobile.objects.filter(A6M1F6=data).exists():
 raise forms.ValidationError(" already exixts")
return data
i have this clean_field method in the form and given field is not
updatable... whenever i tried to update the record with the form having
initial data as the record already inserted in the database this method
raise an exception while calling the is_valid() method



On Tue, Jan 22, 2013 at 7:39 PM, Sarfraz ahmad wrote:

> gusy i have form which has 5 fields i have defined a clean_field
> method which doesn't allow a duplicate entry in the database.
> bt when i tried to update the model instance while calling form.is_valid()
> method it calls the clean_field() method and returns error that entry
> already exists.
>
>
>
> On Tue, Jan 22, 2013 at 2:57 AM, Mario Gudelj wrote:
>
>> Add required=False to the form field and it won't be validated.
>> On 22 Jan, 2013 2:30 AM, "Jonathan D. Baker" <
>> jonathandavidba...@gmail.com> wrote:
>>
>>>  Hi Sarfraz,
>>>
>>> If your form class inherits from ModelForm, you can use a subset of
>>> fields within your form per the following documentation:
>>> https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form
>>>
>>> If you're not inheriting from ModelForm, then it's a matter of
>>> configuring your model and form fields to allow null/blank. In this case,
>>> seeing your code would help provide more direction.
>>>
>>> Hope this helps,
>>> Jonathan
>>>
>>> On 01/21/2013 04:34 AM, Sarfraz ahmad wrote:
>>>
>>> Hello everyone,
>>>
>>>  i m facing a problem while validating django
>>> form. i have 5 form fields in a form and in the view i want to
>>> validate only three form fields which i need to update .. tell me a
>>> solution if anyone have any
>>> --
>>> 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/-/oZfMAZ8FWt4J.
>>> 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.
>>>
>>>
>>>
>>> --
>>> Software Developerhttps://github.com/jondbaker
>>> GPG: 1F6F3FFD
>>>
>>>  --
>>> 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.
>>
>
>

-- 
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: ignore field during form validation

2013-01-22 Thread Sarfraz ahmad
gusy i have form which has 5 fields i have defined a clean_field method
which doesn't allow a duplicate entry in the database.
bt when i tried to update the model instance while calling form.is_valid()
method it calls the clean_field() method and returns error that entry
already exists.


On Tue, Jan 22, 2013 at 2:57 AM, Mario Gudelj wrote:

> Add required=False to the form field and it won't be validated.
> On 22 Jan, 2013 2:30 AM, "Jonathan D. Baker" 
> wrote:
>
>>  Hi Sarfraz,
>>
>> If your form class inherits from ModelForm, you can use a subset of
>> fields within your form per the following documentation:
>> https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form
>>
>> If you're not inheriting from ModelForm, then it's a matter of
>> configuring your model and form fields to allow null/blank. In this case,
>> seeing your code would help provide more direction.
>>
>> Hope this helps,
>> Jonathan
>>
>> On 01/21/2013 04:34 AM, Sarfraz ahmad wrote:
>>
>> Hello everyone,
>>
>>  i m facing a problem while validating django
>> form. i have 5 form fields in a form and in the view i want to
>> validate only three form fields which i need to update .. tell me a
>> solution if anyone have any
>> --
>> 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/-/oZfMAZ8FWt4J.
>> 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.
>>
>>
>>
>> --
>> Software Developerhttps://github.com/jondbaker
>> GPG: 1F6F3FFD
>>
>>  --
>> 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.
>

-- 
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: ignore field during form validation

2013-01-21 Thread Mario Gudelj
Add required=False to the form field and it won't be validated.
On 22 Jan, 2013 2:30 AM, "Jonathan D. Baker" 
wrote:

>  Hi Sarfraz,
>
> If your form class inherits from ModelForm, you can use a subset of fields
> within your form per the following documentation:
> https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form
>
> If you're not inheriting from ModelForm, then it's a matter of configuring
> your model and form fields to allow null/blank. In this case, seeing your
> code would help provide more direction.
>
> Hope this helps,
> Jonathan
>
> On 01/21/2013 04:34 AM, Sarfraz ahmad wrote:
>
> Hello everyone,
>
>  i m facing a problem while validating django
> form. i have 5 form fields in a form and in the view i want to
> validate only three form fields which i need to update .. tell me a
> solution if anyone have any
> --
> 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/-/oZfMAZ8FWt4J.
> 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.
>
>
>
> --
> Software Developerhttps://github.com/jondbaker
> GPG: 1F6F3FFD
>
>  --
> 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: ignore field during form validation

2013-01-21 Thread Jonathan D. Baker
Hi Sarfraz,

If your form class inherits from ModelForm, you can use a subset of
fields within your form per the following documentation:
https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form

If you're not inheriting from ModelForm, then it's a matter of
configuring your model and form fields to allow null/blank. In this
case, seeing your code would help provide more direction.

Hope this helps,
Jonathan

On 01/21/2013 04:34 AM, Sarfraz ahmad wrote:
> Hello everyone,
>
>  i m facing a problem while validating django
> form. i have 5 form fields in a form and in the view i want to
> validate only three form fields which i need to update .. tell
> me a solution if anyone have any
> -- 
> 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/-/oZfMAZ8FWt4J.
> 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.


-- 
Software Developer
https://github.com/jondbaker
GPG: 1F6F3FFD

-- 
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: ignore field during form validation

2013-01-21 Thread Sarfraz ahmad
Hello everyone,

 i m facing a problem while validating django form. 
i have 5 form fields in a form and in the view i want to validate only 
three form fields which i need to update .. tell me a solution if 
anyone have any

-- 
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/-/oZfMAZ8FWt4J.
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-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" <kristo...@cybernetik.net> 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.



Form validation

2013-01-10 Thread Kristofer
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.



Re: After form validation, need to post and call a perl program to display to a log file

2012-08-26 Thread Pervez Mulla
Hey  Nick,

Thank you for mail,

Can I make use CGI script for this...?
If yes how can I make use of that..? Hint>>!!\

Thank you
pervez

On Fri, Aug 24, 2012 at 8:30 PM, Nick Santos  wrote:

> Obligatory followup (though the docs I believe cover this pretty well) -
> be *very* careful calling subprocess with anything related to a form
> submission. Read the documents that Melvyn linked to carefully because you
> can be opening a massive security hole. If this is just temporary to check
> some output, that's fine, but if you plan on going into production, make
> sure to know the risks and consider alternatives.
> -Nick
>
>
> On Friday, August 24, 2012 6:11:45 AM UTC-7, Melvyn Sopacua wrote:
>>
>> On 24-8-2012 8:41, Pervez Mulla wrote:
>>
>> > Once validation happened (its working good), I wanna call perl script
>> to
>> > disply it content to lof file ...
>> >
>> >
>> > How can I do this ..??
>>
>> >
>>
>> FYI, it don't matter that it's perl, you can do this for anything that
>> can be invoked as a "program".
>>
>> --
>> Melvyn Sopacua
>>
>  --
> 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/-/T4GGbPbHxGoJ.
>
> 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: After form validation, need to post and call a perl program to display to a log file

2012-08-24 Thread Nick Santos
Obligatory followup (though the docs I believe cover this pretty well) - be 
*very* careful calling subprocess with anything related to a form 
submission. Read the documents that Melvyn linked to carefully because you 
can be opening a massive security hole. If this is just temporary to check 
some output, that's fine, but if you plan on going into production, make 
sure to know the risks and consider alternatives.
-Nick

On Friday, August 24, 2012 6:11:45 AM UTC-7, Melvyn Sopacua wrote:
>
> On 24-8-2012 8:41, Pervez Mulla wrote: 
>
> > Once validation happened (its working good), I wanna call perl script to 
> > disply it content to lof file ... 
> > 
> > 
> > How can I do this ..?? 
>
>  
> FYI, it don't matter that it's perl, you can do this for anything that 
> can be invoked as a "program". 
>
> -- 
> Melvyn Sopacua 
>

-- 
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/-/T4GGbPbHxGoJ.
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: After form validation, need to post and call a perl program to display to a log file

2012-08-24 Thread Melvyn Sopacua
On 24-8-2012 8:41, Pervez Mulla wrote:

> Once validation happened (its working good), I wanna call perl script to
> disply it content to lof file ...
> 
> 
> How can I do this ..??


FYI, it don't matter that it's perl, you can do this for anything that
can be invoked as a "program".

-- 
Melvyn Sopacua

-- 
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.



After form validation, need to post and call a perl program to display to a log file

2012-08-24 Thread Pervez Mulla
Hi,

I have written code for form validation for different filed .

Once validation happened (its working good), I wanna call perl script to
disply it content to lof file ...


How can I do this ..??

Please help me
Pervez

-- 
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 <pee...@gmail.com> 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<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 <django-users%2bunsubscr...@googlegroups.com>.
>>> For more options, visit this group at http://groups.google.com/**
>>> group/django-users?hl=en<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 <pee...@gmail.com> 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.



Form validation using model data?

2012-07-29 Thread Paul
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.



Re: ignore field during form validation

2012-07-27 Thread Karen Tracey
On Thu, Jul 26, 2012 at 11:14 AM, Zoltan Szalai wrote:

> Hi all,
>
> Let's assume i have to the following simple form:
>
>
> class Form(forms.Form):
>
> check = forms.BooleanField(
> required=False,
> )
> # take into account only when 'check' is True
> len = forms.IntegerField(
> min_value=3,
> max_value=5,
> required=True,
> )
>
>
> What I want is to validate the 'len' field only when 'check' is True.
> I could define the clean method of the form and validate the required,
> min_value and max_value stuff only when 'check' is True but the case when
> someone types a non integer value into the input is still there. How could
> I skip that? That check is done by the IntegerField.
>

You could use two different Django forms, and only call is_valid() on the
one with the len value if the first one with the check value indicates that
check is True. Both of these Django forms can be rendered in a single HTML
. I think that approach is a little cleaner than inspecting the POST
data yourself.

Karen
-- 
http://tracey.org/kmt/

-- 
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: ignore field during form validation

2012-07-26 Thread Zoltan Szalai
In the end I came up with a solution which seems a bit hacky but does 
exactly what I want.

It looks like this:

def clean(self):
cleaned_data = super(Form, self).clean()
check = cleaned_data.get("check", None)

# ignore 'len' when 'check' is False
if not checkand "len" in self._errors:
del self._errors["len"]

return cleaned_data


one thing to note: "len" won't be available in cleaned_data but that's 
just cool since it's not valid :)



On 2012.07.26. 18:29, Kurtis Mullins wrote:
You could remove "required=True" from 'len' and override clean() to 
perform a multiple-field validation. (pretty much what Thomas mentioned)


len() will execute -- it will check to see if it's an integer. If you 
just want to completely ignore it, then do exactly as Thomas said, 
override. But you'll have to make sure you do the "Integer Validation" 
check in your clean() method if you ignore that validation in clean_len().


clean__len():
return self.cleaned_data['len']

On Thu, Jul 26, 2012 at 12:21 PM, Zoltan Szalai > wrote:


On 2012.07.26. 17 :44, Tomas Neme wrote:

class Form(forms.Form):

 check = forms.BooleanField(
 required=False,
 )
 # take into account only when 'check' is True
 len = forms.IntegerField(
 min_value=3,
 max_value=5,
 required=True,
 )


What I want is to validate the 'len' field only when
'check' is True.
I could define the clean method of the form and validate
the required,
min_value and max_value stuff only when 'check' is True
but the case when
someone types a non integer value into the input is still
there. How could I
skip that? That check is done by the IntegerField.

well, you could override clean_len() and not do anything in
it, and
then override clean() and do your check there.


I don't think that would help. The clean method of the Field
(IntegerField in this case) would still run.



--
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: ignore field during form validation

2012-07-26 Thread Kurtis Mullins
You could remove "required=True" from 'len' and override clean() to perform
a multiple-field validation. (pretty much what Thomas mentioned)

len() will execute -- it will check to see if it's an integer. If you just
want to completely ignore it, then do exactly as Thomas said, override. But
you'll have to make sure you do the "Integer Validation" check in your
clean() method if you ignore that validation in clean_len().

clean__len():
return self.cleaned_data['len']

On Thu, Jul 26, 2012 at 12:21 PM, Zoltan Szalai wrote:

> On 2012.07.26. 17:44, Tomas Neme wrote:
>
>> class Form(forms.Form):
>>>
>>>  check = forms.BooleanField(
>>>  required=False,
>>>  )
>>>  # take into account only when 'check' is True
>>>  len = forms.IntegerField(
>>>  min_value=3,
>>>  max_value=5,
>>>  required=True,
>>>  )
>>>
>>>
>>> What I want is to validate the 'len' field only when 'check' is True.
>>> I could define the clean method of the form and validate the required,
>>> min_value and max_value stuff only when 'check' is True but the case when
>>> someone types a non integer value into the input is still there. How
>>> could I
>>> skip that? That check is done by the IntegerField.
>>>
>> well, you could override clean_len() and not do anything in it, and
>> then override clean() and do your check there.
>>
>>
> I don't think that would help. The clean method of the Field (IntegerField
> in this case) would still run.
>
>
>
>
> --
> 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+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 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: ignore field during form validation

2012-07-26 Thread Zoltan Szalai

On 2012.07.26. 17:44, Tomas Neme wrote:

class Form(forms.Form):

 check = forms.BooleanField(
 required=False,
 )
 # take into account only when 'check' is True
 len = forms.IntegerField(
 min_value=3,
 max_value=5,
 required=True,
 )


What I want is to validate the 'len' field only when 'check' is True.
I could define the clean method of the form and validate the required,
min_value and max_value stuff only when 'check' is True but the case when
someone types a non integer value into the input is still there. How could I
skip that? That check is done by the IntegerField.

well, you could override clean_len() and not do anything in it, and
then override clean() and do your check there.



I don't think that would help. The clean method of the Field 
(IntegerField in this case) would still run.




--
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: ignore field during form validation

2012-07-26 Thread Tomas Neme
> class Form(forms.Form):
>
> check = forms.BooleanField(
> required=False,
> )
> # take into account only when 'check' is True
> len = forms.IntegerField(
> min_value=3,
> max_value=5,
> required=True,
> )
>
>
> What I want is to validate the 'len' field only when 'check' is True.
> I could define the clean method of the form and validate the required,
> min_value and max_value stuff only when 'check' is True but the case when
> someone types a non integer value into the input is still there. How could I
> skip that? That check is done by the IntegerField.

well, you could override clean_len() and not do anything in it, and
then override clean() and do your check there.

The only problem is that you won't be able to raise the issue as a
field-specific error

-- 
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
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.



ignore field during form validation

2012-07-26 Thread Zoltan Szalai

Hi all,

Let's assume i have to the following simple form:


class Form(forms.Form):

check = forms.BooleanField(
required=False,
)
# take into account only when 'check' is True
len = forms.IntegerField(
min_value=3,
max_value=5,
required=True,
)


What I want is to validate the 'len' field only when 'check' is True.
I could define the clean method of the form and validate the required,
min_value and max_value stuff only when 'check' is True but the case when
someone types a non integer value into the input is still there. How 
could I skip that? That check is done by the IntegerField.


The best would be to simply remove the 'len' field of the form when 
'check' is False.
Maybe I could examine request.POST in form's __init__ and according to 
it's content remove the fields I don't care about.

Or is that a terrible idea?


bests
Zoli

--
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.



Incorrect post URL on failed form validation

2012-07-13 Thread Kevin
I'm new to Django so hopefully this will be trivial to solve.

I have a table of data I display in a view along with a simple form to add 
a new row of data to the table:

def my_data_view(request, data_id):
myData = MyData.objects.get(pk=data_id)
if request.method == 'POST':
myForm = MyForm(request.POST)
else:
myForm = MyForm()
return render_to_response('myapp/mydata.html',
  { 'my_data' : myData,
'my_form' : myForm,},
  context_instance=RequestContext(request))


def add_new_row(request, data_id):
myData = MyData.objects.get(pk=data_id)
if request.method == 'POST':
myForm = MyForm(request.POST)
if myForm.is_valid():
# TODO insert new time into DB
return HttpResponseRedirect(reverse('senslog.views.mydata', 
args=(myData.id,)))
return my_data_view(request, data_id)

This works when I submit a valid form. However submitting an invalid form 
directs me from myapp/mydata/3 to myapp/mydata/addNewRow/3 which means when 
I submit the corrected form it posts to myapp/addNewRow/addNewRow/3 which 
is obviously not what I want. Any suggestions?

Thanks much!

Kevin

-- 
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/-/X0x91sUiuzoJ.
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.



How to do form validation for inline formsets?

2012-04-18 Thread Derek
Working with Django 1.3

I can create and run an inline formset without problems using Approach 1.
 However, when I try Approach 2, then I get the error below, triggered by
the line shown.

TypeError at /uploads/details/1
__init__() got an unexpected keyword argument 'instance'

Clearly, my syntax is wrong somewhere, but how do I go about fixing this?

Thanks
Derek


Approach No.1 - NO validation

# view file

UploadFieldFormSet = inlineformset_factory(Upload, UploadField,
max_num=None,
extra=9, can_delete=False)
if request.method == 'POST':
...
else:
formset = UploadFieldFormSet(instance=upload)


Approach No. 2 - Form validation

# form file

class UploadFieldFormSet(BaseFormSet):

def clean(self):
if any(self.errors):
return
# need to add special checks here...

# view file

UploadFieldFormSetFactory = inlineformset_factory(Upload, UploadField,

formset=UploadFieldFormSet,
  max_num=None,
  extra=9,
can_delete=False)
if request.method == 'POST':
...
else:
formset = UploadFieldFormSetFactory(instance=upload)  # returns
error

-- 
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.



Form Validation

2012-04-15 Thread coded kid
I want my form to validate the fields so that only users who fill the
form field should be redirected to the next page. If a user fails to
fill any of the form field, the user should be taken to the same page
where it will output validation error so that the user can fill the
fields.

I tried writing these codes but it’s not working! Even if the user
didn’t fill the form field it will still redirect the user to the next
page which is not meant to be so.

Models.

class Memb(models.Model):
slug=models.CharField(max_length=100)
member=models.CharField(max_length=100)

def __unicode__(self):
return u"%s" % self.member

class MembForm(ModelForm):
class Meta:
model=Memb
fields=('slug','member')

Views:

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))

Template:

{% extends "base.html" %}
{% block title %} Add Member {% endblock %}
{% block content %}

  {{MembForm.as_p}}


{% endblock %}

How can I make sure the form validate before taking the user to the
next page? Kindly put me through. 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.



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.



Form Validation and unique_together on update a model

2012-04-13 Thread Massimo Barbierato
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.

-- 
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/-/oeiOo6XO5OMJ.
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.



help with form validation

2012-03-13 Thread Sergiy Khohlov
Hello,
 I would like to ask question about form error handling.
Main target is decreasing count of the code in the template. Of course
it is possible  to display all form in template such as :
{{ form.as_table }} In this case possible to  set some widget in form
and make a template code is simple. But what about field error
handling ?
is it possible to prepare error handling in form ?  and add  to
template simple code such as:

 {% if  form.error %}  {% form.error %} {%endif%}

 at the current moment I'm checking error one by one  using : {%  if
form.field.error %}

Form does validating and possible some simple way to work with error
handling  present , is not it ?

Can anybody know  this ?

 Thanks, Serge

-- 
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.



Form validation with ImageFields

2011-10-03 Thread David
Hello

I need to upload an image through a form. I also need to have the
ability to use the "clear" checkbox built into the imagefield widget
to have the image reference in the database removed. Images should
also be checked for filetype, dimensions and rejected if appropriate.

So I did this:

def clean_image(self):
image = self.cleaned_data['image']
if image:
from django.core.files.images import get_image_dimensions
w, h = get_image_dimensions(image)
if not image.content_type in settings.VALID_IMAGE_FORMATS:
raise forms.ValidationError(u'Only *.gif, *.jpg and
*.png images are allowed.')
if w > settings.VALID_IMAGE_WIDTH or h >
settings.VALID_IMAGE_HEIGHT:
raise forms.ValidationError(u'That image is too big.
The image needs to be ' + str(settings.VALID_IMAGE_WIDTH) + 'px * ' +
str(settings.VALID_IMAGE_HEIGHT) + 'px (or less).')
return image

This does all of what I need it to do, however when I use the clear
checkbox nothing happens. The form just validates and appears to be
successful. The database reference doesn't get removed.

If I remove the code above from my forms.py the checkbox works but I
then miss out on my dimension checking.

Am I missing something please?

Thank you

-- 
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: Django form validation.. does anyone else find it awkward??

2011-07-13 Thread Matteius
"""
Devs: ALWAYS call model.full_clean() OR form.is_valid() to protect
Database from radical or duplicate DB entries!
* Calling model.full_clean() OR form.is_valid() calls 3 underlying
methods (clean, clean_fields, validate_unique)
"""

I haven't had to do much with form validation beyond what is default
and beyond what I have included in my model definitions.  Rendering
forms and displaying any error messages is standard fare included in
Django as far as I see it.

-Matteius

On Jul 12, 12:35 pm, Andre Terra <andrete...@gmail.com> wrote:
> On Tue, Jul 12, 2011 at 2:25 PM, Venkatraman S <venka...@gmail.com> wrote:
>
> > On Tue, Jul 12, 2011 at 9:12 PM, Andre Terra <andrete...@gmail.com> wrote:
>
> >> May I ask if you are managing to do this (and, if so, how) without
> >>> writing duplicate logic?
>
> >> This, to me, is a key area for improvement. Aside from the development
> >> challenge the idea imposes, an extra issue with writing DRY validation for
> >> django and javascript is that the project doesn't officially endorse any
> >> javascript library (there's been extensive discussion about this), but
> >> nobody says it's not okay to write an app that uses jQuery, for example.
>
> > A probable approach would be , probably, for the form renderer to
> > *automatically* clone the validation logic written in clean() to js? (!!)
>
> Cloning validation from clean() would be nearly impossible, as the developer
> is free to write any python code in that logic. A small, achievable step
> would be adding things like required fields to a on-the-fly generated js
> validator.
>
>
>
> >> My issue with uni-form and the like is that these apps get hard to extend
> >> once you find a fringe-case for your app. I tried using it once and soon
> >> enough I was writing so much custom code that I decided to drop uni-form
> >> altogether.
>
> > Can you educate us on the use-case; i am just curious.
>
> I don't remember correctly as it was a long time ago, but I think it had
> something to do with customizing how fieldsets were rendered, and how I
> needed different html markup. I can dig up the source later if you really
> want to know.
>
> History shows good ideas *do *get implemented, and Alex Gaynor is, imho, the
>
> >> developer to look at for examples on how to write quality django apps (for
> >> instance, take a look athttps://github.com/alex/django-filter/
> >> <https://github.com/alex/django-filter/%20>which is pretty small, but
> >> very django-like, even though he's not really proud of the API for that app
> >> in particular)
>
> > An awsum app that is! I was even more excited when i looked at its code. So
> > little, but so powerful!
>
> It's a great app indeed, I use it on every single project now.
>
> That's what he gets from knowing django's internals so well =)
>
> Cheers!

-- 
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: Django form validation.. does anyone else find it awkward??

2011-07-12 Thread Andre Terra
On Tue, Jul 12, 2011 at 2:25 PM, Venkatraman S  wrote:

>
>
> On Tue, Jul 12, 2011 at 9:12 PM, Andre Terra  wrote:
>
>> May I ask if you are managing to do this (and, if so, how) without
>>> writing duplicate logic?
>>>
>>
>> This, to me, is a key area for improvement. Aside from the development
>> challenge the idea imposes, an extra issue with writing DRY validation for
>> django and javascript is that the project doesn't officially endorse any
>> javascript library (there's been extensive discussion about this), but
>> nobody says it's not okay to write an app that uses jQuery, for example.
>>
>
>
> A probable approach would be , probably, for the form renderer to
> *automatically* clone the validation logic written in clean() to js? (!!)
>

Cloning validation from clean() would be nearly impossible, as the developer
is free to write any python code in that logic. A small, achievable step
would be adding things like required fields to a on-the-fly generated js
validator.


>
>
>> My issue with uni-form and the like is that these apps get hard to extend
>> once you find a fringe-case for your app. I tried using it once and soon
>> enough I was writing so much custom code that I decided to drop uni-form
>> altogether.
>>
>
> Can you educate us on the use-case; i am just curious.
>

I don't remember correctly as it was a long time ago, but I think it had
something to do with customizing how fieldsets were rendered, and how I
needed different html markup. I can dig up the source later if you really
want to know.


History shows good ideas *do *get implemented, and Alex Gaynor is, imho, the
>> developer to look at for examples on how to write quality django apps (for
>> instance, take a look at https://github.com/alex/django-filter/
>> which is pretty small, but
>> very django-like, even though he's not really proud of the API for that app
>> in particular)
>>
>
> An awsum app that is! I was even more excited when i looked at its code. So
> little, but so powerful!
>

It's a great app indeed, I use it on every single project now.

That's what he gets from knowing django's internals so well =)


Cheers!

-- 
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: Django form validation.. does anyone else find it awkward??

2011-07-12 Thread Venkatraman S
On Tue, Jul 12, 2011 at 9:12 PM, Andre Terra  wrote:

> May I ask if you are managing to do this (and, if so, how) without
>> writing duplicate logic?
>>
>
> This, to me, is a key area for improvement. Aside from the development
> challenge the idea imposes, an extra issue with writing DRY validation for
> django and javascript is that the project doesn't officially endorse any
> javascript library (there's been extensive discussion about this), but
> nobody says it's not okay to write an app that uses jQuery, for example.
>


A probable approach would be , probably, for the form renderer to
*automatically* clone the validation logic written in clean() to js? (!!)



> My issue with uni-form and the like is that these apps get hard to extend
> once you find a fringe-case for your app. I tried using it once and soon
> enough I was writing so much custom code that I decided to drop uni-form
> altogether.
>

Can you educate us on the use-case; i am just curious.


> History shows good ideas *do *get implemented, and Alex Gaynor is, imho,
> the developer to look at for examples on how to write quality django apps
> (for instance, take a look at https://github.com/alex/django-filter/
> which is pretty small, but very
> django-like, even though he's not really proud of the API for that app in
> particular)
>

An awsum app that is! I was even more excited when i looked at its code. So
little, but so powerful!

-V

-- 
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: Django form validation.. does anyone else find it awkward??

2011-07-12 Thread Cal Leeming [Simplicity Media Ltd]
Some interesting thoughts here. I once attempted to make a merge between
Django validation and jQuery validation (spent several weeks on it), but my
approach wasn't dynamic enough, and ended up not being used again.

Personally, I'd like to see some sort of standardized JS library which
works seamlessly with Django form validation, but it is an absolute PITA.

Cal

On Tue, Jul 12, 2011 at 4:42 PM, Andre Terra <andrete...@gmail.com> wrote:

> May I ask if you are managing to do this (and, if so, how) without
>> writing duplicate logic?
>>
>
> This, to me, is a key area for improvement. Aside from the development
> challenge the idea imposes, an extra issue with writing DRY validation for
> django and javascript is that the project doesn't officially endorse any
> javascript library (there's been extensive discussion about this), but
> nobody says it's not okay to write an app that uses jQuery, for example.
>
> My issue with uni-form and the like is that these apps get hard to extend
> once you find a fringe-case for your app. I tried using it once and soon
> enough I was writing so much custom code that I decided to drop uni-form
> altogether.
>
> The issue of form validation being complex has also been discussed on
> django-developers, and I don't mind to be rude, but this kind of "wouldn't
> it be nice" discussions usually end in some core developer saying "go ahead
> and show us some code, then we can think about merging it into django".
> Django has an extensive to-do list (we're only at version 1.4!) and Keith is
> usually the first to say that unless there's code to go along with the
> proposal, there's not a lot they can do about it.
>
> History shows good ideas *do *get implemented, and Alex Gaynor is, imho,
> the developer to look at for examples on how to write quality django apps
> (for instance, take a look at https://github.com/alex/django-filter/
> <https://github.com/alex/django-filter/%20>which is pretty small, but very
> django-like, even though he's not really proud of the API for that app in
> particular).
>
>
> If any of you take a step into writing a better API for form validation,
> I'm sure the core devs will be more than excited to take a look at,
> considering how the current implementation is still obscure in some steps
> (or lacking sugar), e.g. self._errors["subject"] = self.error_class([msg])
>
> But first one needs to decide if he's cleaning up django's API (hard) or
> writing integrated js-python validation (harder).
>
>
> Cheers,
> André Terra
>
>
>
> On Tue, Jul 12, 2011 at 12:08 PM, Derek <gamesb...@gmail.com> wrote:
>
>>
>> On Jul 12, 10:15 am, Venkatraman S <venka...@gmail.com> wrote:
>> > On Tue, Jul 12, 2011 at 1:23 PM, Cal Leeming [Simplicity Media Ltd] <
>> >
>> >
>> > cal.leem...@simplicitymedialtd.co.uk> wrote:
>> > > On 12 Jul 2011 08:13, "bruno desthuilliers" <
>> bruno.desthuilli...@gmail.com>
>> > > wrote:
>> >
>> > > > On Jul 12, 3:37 am, Venkatraman S <venka...@gmail.com> wrote:
>> >
>> > > > > On the validation, yes, it is a little pesky. But, offlate, i am
>> trying
>> > > to
>> > > > > *understand* it better and trying to move the logic
>> > > > > to the client. For eg. jquery-validate does bulk of the stuff on
>> client
>> > > side
>> > > > > - atleast for required fields. So, moving
>> > > > > bulk of the validation to the client helps in avoiding a few http
>> > > calls.
>> >
>> > > > Client-side validation may be fine from a UX POV, but you just CAN
>> NOT
>> > > > rely on it - I mean, unless you're happy with unvalidated user
>> > > > inputs
>> >
>> > > +1
>> >
>> > True; the validation *should* be present in the server, but i am trying
>> to
>> > move the *same*
>> > validation(as much as possible) to the client *too*, so that the http
>> calls
>> > be avoided.
>>
>> May I ask if you are managing to do this (and, if so, how) without
>> writing duplicate logic?
>>
>> --
>> 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.
>

-- 
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: Django form validation.. does anyone else find it awkward??

2011-07-12 Thread Andre Terra
>
> May I ask if you are managing to do this (and, if so, how) without
> writing duplicate logic?
>

This, to me, is a key area for improvement. Aside from the development
challenge the idea imposes, an extra issue with writing DRY validation for
django and javascript is that the project doesn't officially endorse any
javascript library (there's been extensive discussion about this), but
nobody says it's not okay to write an app that uses jQuery, for example.

My issue with uni-form and the like is that these apps get hard to extend
once you find a fringe-case for your app. I tried using it once and soon
enough I was writing so much custom code that I decided to drop uni-form
altogether.

The issue of form validation being complex has also been discussed on
django-developers, and I don't mind to be rude, but this kind of "wouldn't
it be nice" discussions usually end in some core developer saying "go ahead
and show us some code, then we can think about merging it into django".
Django has an extensive to-do list (we're only at version 1.4!) and Keith is
usually the first to say that unless there's code to go along with the
proposal, there's not a lot they can do about it.

History shows good ideas *do *get implemented, and Alex Gaynor is, imho, the
developer to look at for examples on how to write quality django apps (for
instance, take a look at https://github.com/alex/django-filter/
<https://github.com/alex/django-filter/%20>which is pretty small, but very
django-like, even though he's not really proud of the API for that app in
particular).


If any of you take a step into writing a better API for form validation, I'm
sure the core devs will be more than excited to take a look at, considering
how the current implementation is still obscure in some steps (or lacking
sugar), e.g. self._errors["subject"] = self.error_class([msg])

But first one needs to decide if he's cleaning up django's API (hard) or
writing integrated js-python validation (harder).


Cheers,
André Terra


On Tue, Jul 12, 2011 at 12:08 PM, Derek <gamesb...@gmail.com> wrote:

>
> On Jul 12, 10:15 am, Venkatraman S <venka...@gmail.com> wrote:
> > On Tue, Jul 12, 2011 at 1:23 PM, Cal Leeming [Simplicity Media Ltd] <
> >
> >
> > cal.leem...@simplicitymedialtd.co.uk> wrote:
> > > On 12 Jul 2011 08:13, "bruno desthuilliers" <
> bruno.desthuilli...@gmail.com>
> > > wrote:
> >
> > > > On Jul 12, 3:37 am, Venkatraman S <venka...@gmail.com> wrote:
> >
> > > > > On the validation, yes, it is a little pesky. But, offlate, i am
> trying
> > > to
> > > > > *understand* it better and trying to move the logic
> > > > > to the client. For eg. jquery-validate does bulk of the stuff on
> client
> > > side
> > > > > - atleast for required fields. So, moving
> > > > > bulk of the validation to the client helps in avoiding a few http
> > > calls.
> >
> > > > Client-side validation may be fine from a UX POV, but you just CAN
> NOT
> > > > rely on it - I mean, unless you're happy with unvalidated user
> > > > inputs
> >
> > > +1
> >
> > True; the validation *should* be present in the server, but i am trying
> to
> > move the *same*
> > validation(as much as possible) to the client *too*, so that the http
> calls
> > be avoided.
>
> May I ask if you are managing to do this (and, if so, how) without
> writing duplicate logic?
>
> --
> 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: Django form validation.. does anyone else find it awkward??

2011-07-12 Thread Derek

On Jul 12, 10:15 am, Venkatraman S  wrote:
> On Tue, Jul 12, 2011 at 1:23 PM, Cal Leeming [Simplicity Media Ltd] <
>
>
> cal.leem...@simplicitymedialtd.co.uk> wrote:
> > On 12 Jul 2011 08:13, "bruno desthuilliers" 
> > wrote:
>
> > > On Jul 12, 3:37 am, Venkatraman S  wrote:
>
> > > > On the validation, yes, it is a little pesky. But, offlate, i am trying
> > to
> > > > *understand* it better and trying to move the logic
> > > > to the client. For eg. jquery-validate does bulk of the stuff on client
> > side
> > > > - atleast for required fields. So, moving
> > > > bulk of the validation to the client helps in avoiding a few http
> > calls.
>
> > > Client-side validation may be fine from a UX POV, but you just CAN NOT
> > > rely on it - I mean, unless you're happy with unvalidated user
> > > inputs
>
> > +1
>
> True; the validation *should* be present in the server, but i am trying to
> move the *same*
> validation(as much as possible) to the client *too*, so that the http calls
> be avoided.

May I ask if you are managing to do this (and, if so, how) without
writing duplicate logic?

-- 
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: Django form validation.. does anyone else find it awkward??

2011-07-12 Thread Venkatraman S
On Tue, Jul 12, 2011 at 1:23 PM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> On 12 Jul 2011 08:13, "bruno desthuilliers" 
> wrote:
> >
> > On Jul 12, 3:37 am, Venkatraman S  wrote:
> > >
> > > On the validation, yes, it is a little pesky. But, offlate, i am trying
> to
> > > *understand* it better and trying to move the logic
> > > to the client. For eg. jquery-validate does bulk of the stuff on client
> side
> > > - atleast for required fields. So, moving
> > > bulk of the validation to the client helps in avoiding a few http
> calls.
> >
> > Client-side validation may be fine from a UX POV, but you just CAN NOT
> > rely on it - I mean, unless you're happy with unvalidated user
> > inputs
>
> +1
>

True; the validation *should* be present in the server, but i am trying to
move the *same*
validation(as much as possible) to the client *too*, so that the http calls
be avoided.

-- 
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: Django form validation.. does anyone else find it awkward??

2011-07-12 Thread Cal Leeming [Simplicity Media Ltd]
On 12 Jul 2011 08:13, "bruno desthuilliers" 
wrote:
>
> On Jul 12, 3:37 am, Venkatraman S  wrote:
> >
> > On the validation, yes, it is a little pesky. But, offlate, i am trying
to
> > *understand* it better and trying to move the logic
> > to the client. For eg. jquery-validate does bulk of the stuff on client
side
> > - atleast for required fields. So, moving
> > bulk of the validation to the client helps in avoiding a few http calls.
>
> Client-side validation may be fine from a UX POV, but you just CAN NOT
> rely on it - I mean, unless you're happy with unvalidated user
> inputs

+1

>
> --
> 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: Django form validation.. does anyone else find it awkward??

2011-07-12 Thread bruno desthuilliers
On Jul 12, 3:37 am, Venkatraman S  wrote:
>
> On the validation, yes, it is a little pesky. But, offlate, i am trying to
> *understand* it better and trying to move the logic
> to the client. For eg. jquery-validate does bulk of the stuff on client side
> - atleast for required fields. So, moving
> bulk of the validation to the client helps in avoiding a few http calls.

Client-side validation may be fine from a UX POV, but you just CAN NOT
rely on it - I mean, unless you're happy with unvalidated user
inputs

-- 
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: Django form validation.. does anyone else find it awkward??

2011-07-11 Thread Venkatraman S
On Tue, Jul 12, 2011 at 4:26 AM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> Does anyone else find working with form validation in Django to be a bit
> awkward and/or tedious?
>
> I can't say exactly why I don't like it, because I don't really know
> myself, I just always disliked working with it.
>
> Am I being a fussy little fuzz ball, or does anyone else have this same
> view towards it..?
>

Well, i had my own cribs w.r.t form rendering ...as_p and as_table looked
neanderthal.
However, i moved to uni-form, and am loving it since then.

On the validation, yes, it is a little pesky. But, offlate, i am trying to
*understand* it better and trying to move the logic
to the client. For eg. jquery-validate does bulk of the stuff on client side
- atleast for required fields. So, moving
bulk of the validation to the client helps in avoiding a few http calls.

-V

-- 
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.



Django form validation.. does anyone else find it awkward??

2011-07-11 Thread Cal Leeming [Simplicity Media Ltd]
Does anyone else find working with form validation in Django to be a bit 
awkward and/or tedious?


I can't say exactly why I don't like it, because I don't really know 
myself, I just always disliked working with it.


Am I being a fussy little fuzz ball, or does anyone else have this same 
view towards it..?


Cal

--
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: Possible bug in form validation

2011-06-21 Thread Shawn Milochik

On 06/21/2011 12:17 AM, Ian Clelland wrote:
On Mon, Jun 20, 2011 at 1:49 PM, Shawn Milochik > wrote:


I know that, whenever someone finds a "bug" in Django they're
usually doing something incorrectly. Hopefully someone will point
out what I need to do to make this work.


I don't know if it's considered 'correct' or not, but the max_value 
constructor parameter is only used at instantiation time, to add a 
validator to the field.


You can easily add the validator manually in your own constructor if 
you need to. You may also want to set the max_value attribute, if you 
use it elsewhere, but it is not used internally by the form machinery.




Ian,

Considering that other things, such as setting 'initial' values and 
widgets work after the super().__init__() and that it's impossible to do 
them before said __init__, I think it's definitely a bug. And 
considering that the max_value lives beyond that point but isn't 
enforced certainly violates the "least surprising" rule.


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-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: Possible bug in form validation

2011-06-20 Thread Ian Clelland
On Mon, Jun 20, 2011 at 1:49 PM, Shawn Milochik  wrote:

> I know that, whenever someone finds a "bug" in Django they're usually doing
> something incorrectly. Hopefully someone will point out what I need to do to
> make this work.
>

I don't know if it's considered 'correct' or not, but the max_value
constructor parameter is only used at instantiation time, to add a validator
to the field.

You can easily add the validator manually in your own constructor if you
need to. You may also want to set the max_value attribute, if you use it
elsewhere, but it is not used internally by the form machinery.


>
> However, this is looking like a legitimate bug to me.
>
> http://dpaste.com/hold/556603/
>
>
I've updated with a working example, as http://dpaste.com/hold/556805/

-- 
Regards,
Ian Clelland


-- 
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.



Possible bug in form validation

2011-06-20 Thread Shawn Milochik
I know that, whenever someone finds a "bug" in Django they're usually 
doing something incorrectly. Hopefully someone will point out what I 
need to do to make this work.


However, this is looking like a legitimate bug to me.

http://dpaste.com/hold/556603/

Environment:
Django: (1, 3, 0, 'final', 0)
Python: 2.7.0+

Am I missing something, or should I file a ticket?

Thanks,
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-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.



  1   2   3   4   >