Re: No POST response when using checkbox form

2011-02-08 Thread Ethan Yandow
How bad of an Idea is it to not use Django forms?  I feel like Django forms
are kinda a pain

On Fri, Feb 4, 2011 at 12:06 PM, Tom Evans  wrote:

> On Fri, Feb 4, 2011 at 4:20 PM, Shawn Milochik  wrote:
> > Here's the main piece:
> > http://docs.djangoproject.com/en/1.2/ref/forms/
> > Just make a form with a boolean field.
> > When you've successfully made one form that you submit, validate, and act
> > upon, just throw a bunch in a formset:
> > http://docs.djangoproject.com/en/1.2/topics/forms/formsets/
> > If you get stuck along the way, paste the full error messages and sample
> > code.
> > Shawn
> >
>
> If the fields are semanticly related, then that advice makes a lot of
> sense. However if they are disparate options, and the only thing that
> relates them is that they are boolean options, then it may be easier
> to do this as a single form, with a ChoiceField that uses a
> CheckboxSelectMultiple widget:
>
> QUESTIONS = (
>( 'cheese', 'Do you like cheese?' ),
>( 'meat', 'Do you eat meat?' ),
>( 'stupid', 'Do you like inane questions?' ),
>  )
>
> class QuestionnaireForm(forms.Form):
>  questions = forms.MultipleChoiceField(choices=QUESTIONS,
>  required=False,
>  label='Please answer these questions',
> widget=forms.CheckboxSelectMultiple(),)
>
> 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.
>
>

-- 
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: No POST response when using checkbox form

2011-02-04 Thread Tom Evans
On Fri, Feb 4, 2011 at 4:20 PM, Shawn Milochik  wrote:
> Here's the main piece:
> http://docs.djangoproject.com/en/1.2/ref/forms/
> Just make a form with a boolean field.
> When you've successfully made one form that you submit, validate, and act
> upon, just throw a bunch in a formset:
> http://docs.djangoproject.com/en/1.2/topics/forms/formsets/
> If you get stuck along the way, paste the full error messages and sample
> code.
> Shawn
>

If the fields are semanticly related, then that advice makes a lot of
sense. However if they are disparate options, and the only thing that
relates them is that they are boolean options, then it may be easier
to do this as a single form, with a ChoiceField that uses a
CheckboxSelectMultiple widget:

QUESTIONS = (
( 'cheese', 'Do you like cheese?' ),
( 'meat', 'Do you eat meat?' ),
( 'stupid', 'Do you like inane questions?' ),
  )

class QuestionnaireForm(forms.Form):
  questions = forms.MultipleChoiceField(choices=QUESTIONS,
  required=False,
  label='Please answer these questions',
widget=forms.CheckboxSelectMultiple(),)

Cheers

Tom

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



Re: No POST response when using checkbox form

2011-02-04 Thread Shawn Milochik
Here's the main piece:

http://docs.djangoproject.com/en/1.2/ref/forms/

Just make a form with a boolean field.

When you've successfully made one form that you submit, validate, and act upon, 
just throw a bunch in a formset:

http://docs.djangoproject.com/en/1.2/topics/forms/formsets/

If you get stuck along the way, paste the full error messages and sample code. 

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: No POST response when using checkbox form

2011-02-04 Thread Ethan Yandow
Hmmm, I am having a hard time understanding the django forms... Would
someone mind giving me an example of how I would list my events with check
boxes next to them please :)

On Fri, Feb 4, 2011 at 10:07 AM, Ethan Yandow  wrote:

> aahhh yes!!! Thank you very much!!!  Alright, ill work on implementing
> those form views :)
>
>
> On Fri, Feb 4, 2011 at 4:25 AM, Daniel Roseman wrote:
>
>> On Friday, February 4, 2011 9:24:48 AM UTC, Daniel Roseman wrote:
>>>
>>> On Friday, February 4, 2011 12:35:20 AM UTC, Ethan Yandow wrote:

 Hey there, I am trying to delete Events as chosen by a by a user using
 check boxes to check of which events they want to be deleted.  But for
 some reason whenever I call request.POST.get('event_list') Nothing is
 received even though boxes are checked and I end up with nothing.
 Here is my template and the view that should be deleting the chosen
 events.

  {% if event_list %}
 {% for event in event_list%}
 {%csrf_token%}
 >>> id="event{{ forloop.counter }}" />
 {{ event.title }}>>> label>
 {% endfor %}
 
 
 {{removal}}{%comment%} this is what should be
 removed{%endcomment%}
 {% if delete_error %}
 {{delete_error}}
 {% endif %}

 views.py

 def EventDelete(request):
 removal = request.POST.get('event_list')
 if removal:
 removal.delete()
 else:
 delete_error = "You didn't delete anything"
 return redner_to_response("detail.html", {'delete_error':
 delete_error, 'removal': removal},
 context_instance=RequestContext(request))

 Im not sure why removal doesn't have anything in it, shouldn't it have
 the titles of the events in it?

>>>
>>> You haven't defined a `value` attribute for each checkbox.
>>>
>>> 
>>>
>>> Also, in your view, you should use `getlist` to get the value - `get`
>>> only gets the first element if it's a multi-valued field.
>>> --
>>> DR.
>>>
>>
>> Meant to add, you should really be using Django's forms framework, as it
>> takes care of all of this for you.
>> --
>> DR.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

-- 
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: No POST response when using checkbox form

2011-02-04 Thread Ethan Yandow
aahhh yes!!! Thank you very much!!!  Alright, ill work on implementing those
form views :)

On Fri, Feb 4, 2011 at 4:25 AM, Daniel Roseman wrote:

> On Friday, February 4, 2011 9:24:48 AM UTC, Daniel Roseman wrote:
>>
>> On Friday, February 4, 2011 12:35:20 AM UTC, Ethan Yandow wrote:
>>>
>>> Hey there, I am trying to delete Events as chosen by a by a user using
>>> check boxes to check of which events they want to be deleted.  But for
>>> some reason whenever I call request.POST.get('event_list') Nothing is
>>> received even though boxes are checked and I end up with nothing.
>>> Here is my template and the view that should be deleting the chosen
>>> events.
>>>
>>>  {% if event_list %}
>>> {% for event in event_list%}
>>> {%csrf_token%}
>>> >> id="event{{ forloop.counter }}" />
>>> {{ event.title }}>> label>
>>> {% endfor %}
>>> 
>>> 
>>> {{removal}}{%comment%} this is what should be
>>> removed{%endcomment%}
>>> {% if delete_error %}
>>> {{delete_error}}
>>> {% endif %}
>>>
>>> views.py
>>>
>>> def EventDelete(request):
>>> removal = request.POST.get('event_list')
>>> if removal:
>>> removal.delete()
>>> else:
>>> delete_error = "You didn't delete anything"
>>> return redner_to_response("detail.html", {'delete_error':
>>> delete_error, 'removal': removal},
>>> context_instance=RequestContext(request))
>>>
>>> Im not sure why removal doesn't have anything in it, shouldn't it have
>>> the titles of the events in it?
>>>
>>
>> You haven't defined a `value` attribute for each checkbox.
>>
>> 
>>
>> Also, in your view, you should use `getlist` to get the value - `get` only
>> gets the first element if it's a multi-valued field.
>> --
>> DR.
>>
>
> Meant to add, you should really be using Django's forms framework, as it
> takes care of all of this for you.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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: No POST response when using checkbox form

2011-02-04 Thread Daniel Roseman
On Friday, February 4, 2011 9:24:48 AM UTC, Daniel Roseman wrote:
>
> On Friday, February 4, 2011 12:35:20 AM UTC, Ethan Yandow wrote:
>>
>> Hey there, I am trying to delete Events as chosen by a by a user using 
>> check boxes to check of which events they want to be deleted.  But for 
>> some reason whenever I call request.POST.get('event_list') Nothing is 
>> received even though boxes are checked and I end up with nothing. 
>> Here is my template and the view that should be deleting the chosen 
>> events. 
>>
>>  {% if event_list %} 
>> {% for event in event_list%} 
>> {%csrf_token%} 
>> > id="event{{ forloop.counter }}" /> 
>> {{ event.title }}> label> 
>> {% endfor %} 
>>  
>>  
>> {{removal}}{%comment%} this is what should be 
>> removed{%endcomment%} 
>> {% if delete_error %} 
>> {{delete_error}} 
>> {% endif %} 
>>
>> views.py 
>>
>> def EventDelete(request): 
>> removal = request.POST.get('event_list') 
>> if removal: 
>> removal.delete() 
>> else: 
>> delete_error = "You didn't delete anything" 
>> return redner_to_response("detail.html", {'delete_error': 
>> delete_error, 'removal': removal}, 
>> context_instance=RequestContext(request)) 
>>
>> Im not sure why removal doesn't have anything in it, shouldn't it have 
>> the titles of the events in it? 
>>
>
> You haven't defined a `value` attribute for each checkbox. 
>
>  
>
> Also, in your view, you should use `getlist` to get the value - `get` only 
> gets the first element if it's a multi-valued field.
> --
> DR.
>

Meant to add, you should really be using Django's forms framework, as it 
takes care of all of this for you.
--
DR.

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



Re: No POST response when using checkbox form

2011-02-04 Thread Daniel Roseman
On Friday, February 4, 2011 12:35:20 AM UTC, Ethan Yandow wrote:
>
> Hey there, I am trying to delete Events as chosen by a by a user using 
> check boxes to check of which events they want to be deleted.  But for 
> some reason whenever I call request.POST.get('event_list') Nothing is 
> received even though boxes are checked and I end up with nothing. 
> Here is my template and the view that should be deleting the chosen 
> events. 
>
>  {% if event_list %} 
> {% for event in event_list%} 
> {%csrf_token%} 
>  id="event{{ forloop.counter }}" /> 
> {{ event.title }} label> 
> {% endfor %} 
>  
>  
> {{removal}}{%comment%} this is what should be 
> removed{%endcomment%} 
> {% if delete_error %} 
> {{delete_error}} 
> {% endif %} 
>
> views.py 
>
> def EventDelete(request): 
> removal = request.POST.get('event_list') 
> if removal: 
> removal.delete() 
> else: 
> delete_error = "You didn't delete anything" 
> return redner_to_response("detail.html", {'delete_error': 
> delete_error, 'removal': removal}, 
> context_instance=RequestContext(request)) 
>
> Im not sure why removal doesn't have anything in it, shouldn't it have 
> the titles of the events in it? 
>

You haven't defined a `value` attribute for each checkbox. 

 

Also, in your view, you should use `getlist` to get the value - `get` only 
gets the first element if it's a multi-valued field.
--
DR.

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



No POST response when using checkbox form

2011-02-03 Thread Ethan Yandow
Hey there, I am trying to delete Events as chosen by a by a user using
check boxes to check of which events they want to be deleted.  But for
some reason whenever I call request.POST.get('event_list') Nothing is
received even though boxes are checked and I end up with nothing.
Here is my template and the view that should be deleting the chosen
events.

 {% if event_list %}
{% for event in event_list%}
{%csrf_token%}

{{ event.title }}
{% endfor %}


{{removal}}{%comment%} this is what should be
removed{%endcomment%}
{% if delete_error %}
{{delete_error}}
{% endif %}

views.py

def EventDelete(request):
removal = request.POST.get('event_list')
if removal:
removal.delete()
else:
delete_error = "You didn't delete anything"
return redner_to_response("detail.html", {'delete_error':
delete_error, 'removal': removal},
context_instance=RequestContext(request))

Im not sure why removal doesn't have anything in it, shouldn't it have
the titles of the events in it?

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