I think the proper paradigm is to use the AnonymousUser.

Rather than trying to destroy the session - something that cannot be
reliably achieved - instead set the user of the session back to
AnonymousUser and test/react to that.


On Mar 23, 8:40 am, grimmus <graham.col...@gmail.com> wrote:
> Basically all i want to do is the following :
>
> Have a newsletter signup form. When the user signs up successfully the
> area where the form was has a thanks message instead of the form.
>
> The form or thanks message is displayed on every page of the site, so
> I thought using a session would be the best way handle whether to show
> the form or the thanks message.
>
> Here is my form
>
> <form class="form subscribe" id="subscribe_form" method="post">
>                 <fieldset class="inlineElements">
>                     {% if form.errors %}
>                     <p>Please enter a valid email address.</p>
>                     {% endif %}
>                     {% if form.thanks %}
>                     <p>Thanks for signing up</p>
>                     {% endif %}
>                     {% if form.alreadyexists %}
>                     <p>The email address already exists</p>
>                     {% endif %}
>                     {% if not form.thanks %}
>                       <input type="text" class="textbox" name="email" 
> value="Email
> address" onfocus="this.select()" />
>                       <input type="submit" id="mailinglist" class="button 
> submit"
> value="Go"/>
>                     {% endif %}
>                 </fieldset>
>               </form>
>
> And my view
>
> if request.POST:
>         form = SignUp(request.POST)
>
>         if form.is_valid():
>
>             email = request.POST.get('email', '')
>
>             try:
>                 entry = MailingList.objects.get(email=email)
>
>                 form.alreadyexists = True
>
>             except (KeyError, MailingList.DoesNotExist):
>
>                 entry = MailingList()
>                 entry.email = email
>                 entry.date_added = datetime.now()
>                 entry.save()
>
>                 request.session['signed_up'] = True
>                 form.thanks = True
>
>             return HttpResponseRedirect(request.get_full_path())
>
>         else:
>             print form.errors
>
>     else:
>
>             form = SignUp()
>
>             t = loader.get_template('home/page.html')
>             c = RequestContext(request,{
>                 'form':form,
>             })
>
>             if request.session.get('signed_up', True):
>                 form.thanks = True
>
>             return HttpResponse(t.render(c))
>
> Any help is greatly appreciated.
>
> On Mar 22, 3:13 pm, Bill Freeman <ke1g...@gmail.com> wrote:
>
>
>
> > And if the user disables javascript, or kills the browser without
> > normal exit, or loses
> > his connection, or pulls the ethernet cable, or has a power failure?
>
> > On Mon, Mar 22, 2010 at 10:06 AM, Wiiboy <jordon...@gmail.com> wrote:
> > > Couldn't you use Javascript for this? For example, on the
> > > onbeforeunload event, delete the sessionid cookie?
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.

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

Reply via email to