diff -r 267d9eee024b -r ec6e58c639bf project/scipycon/registration/views.py --- a/project/scipycon/registration/views.py Wed Jul 21 02:05:33 2010 +0530 +++ b/project/scipycon/registration/views.py Wed Jul 21 02:06:51 2010 +0530 @@ -1,36 +1,30 @@ -import cStringIO as StringIO -import csv - -from django.shortcuts import render_to_response -from django.template.loader import render_to_string -from django.shortcuts import get_object_or_404 -from django.template import RequestContext -from django.core.urlresolvers import reverse -from django.http import HttpResponse - +from django.contrib.auth import authenticate +from django.contrib.auth import login from django.contrib.auth.decorators import login_required from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.models import User from django.core.exceptions import ObjectDoesNotExist +from django.core.urlresolvers import reverse +from django.shortcuts import render_to_response +from django.template import RequestContext -from project.scipycon.utils import set_message_cookie +from project.scipycon.base.models import Event +from project.scipycon.registration.forms import RegistrationEditForm +from project.scipycon.registration.forms import RegistrationSubmitForm +from project.scipycon.registration.forms import WifiForm +from project.scipycon.registration.models import Registration +from project.scipycon.registration.models import Wifi +from project.scipycon.registration.utils import send_confirmation +from project.scipycon.user.forms import RegistrantForm from project.scipycon.user.models import UserProfile from project.scipycon.user.utils import scipycon_createregistrant -from project.scipycon.user.forms import RegistrantForm -from project.scipycon.talk.models import Talk +from project.scipycon.utils import set_message_cookie -from project.scipycon.registration.models import Registration -from project.scipycon.registration.forms import RegistrationSubmitForm -from project.scipycon.registration.forms import RegistrationEditForm -from project.scipycon.registration.forms import RegistrationAdminSelectForm -from project.scipycon.registration.forms import WifiForm -from project.scipycon.registration.utils import send_confirmation - -from .forms import IC REG_TOTAL = 1000 +@login_required def registrations(request, scope, template_name='registration/registrations.html'): """Simple page to count registrations""" @@ -48,6 +42,7 @@ """ reg = Registration.objects.get(pk=id) + wifi = Wifi.objects.get(user=reg.registrant) if reg.registrant != request.user: redirect_to = reverse('scipycon_account', kwargs={'scope': scope}) @@ -58,40 +53,63 @@ + ' is not your own.') if request.method == 'POST': - form = RegistrationEditForm(data=request.POST) - if form.is_valid(): - reg.organisation = form.data.get('organisation') - reg.occupation = form.data.get('occupation') - reg.city = form.data.get('city') - reg.tshirt = form.data.get('tshirt') - reg.allow_contact = form.data.get('allow_contact') and True or False - reg.conference = form.data.get('conference') and True or False - reg.tutorial = form.data.get('tutorial') and True or False - reg.sprint = form.data.get('sprint') and True or False + registration_form = RegistrationEditForm(data=request.POST) + wifi_form = WifiForm(data=request.POST) + + if registration_form.is_valid() and wifi_form.is_valid(): + reg.organisation = registration_form.data.get('organisation') + reg.occupation = registration_form.data.get('occupation') + reg.city = registration_form.data.get('city') + reg.phone_num = registration_form.data.get('phone_num') + reg.postcode = registration_form.data.get('postcode') + #reg.tshirt = registration_form.data.get('tshirt') + reg.allow_contact = registration_form.data.get( + 'allow_contact') and True or False + reg.conference = registration_form.data.get( + 'conference') and True or False + reg.tutorial = registration_form.data.get( + 'tutorial') and True or False + reg.sprint = registration_form.data.get( + 'sprint') and True or False reg.save() + wifi = wifi_form.save(reg.registrant, reg.scope) + # Saved.. redirect redirect_to = reverse('scipycon_account', kwargs={'scope': scope}) return set_message_cookie(redirect_to, msg = u'Your changes have been saved.') + else: + import logging + logging.error(registration_form.data) + raise "Bow Bow" else: - form = RegistrationEditForm(initial={ - 'id' : id, - 'organisation' : reg.organisation, - 'occupation' : reg.occupation, - 'city' : reg.city, - 'tshirt' : reg.tshirt, - 'conference': reg.conference, - 'tutorial': reg.tutorial, - 'postcode' : reg.postcode, - 'sprint' : reg.sprint, - 'allow_contact' : reg.allow_contact, + registration_form = RegistrationEditForm(initial={ + 'id' : id, + 'organisation' : reg.organisation, + 'occupation' : reg.occupation, + 'city' : reg.city, + 'phone_num': reg.phone_num, + #'tshirt' : reg.tshirt, + 'conference': reg.conference, + 'tutorial': reg.tutorial, + 'postcode' : reg.postcode, + 'sprint' : reg.sprint, + 'allow_contact' : reg.allow_contact, + }) + wifi_form = WifiForm(initial={ + 'user': wifi.user, + 'scope': wifi.scope, + 'wifi': wifi.wifi }) return render_to_response( template_name, RequestContext(request, { - 'params': {'scope': scope}})) + 'params': {'scope': scope}, + 'registration': {'id': id}, + 'registration_form': registration_form, + 'wifi_form': wifi_form})) def submit_registration(request, scope, template_name='registration/submit-registration.html'): @@ -101,11 +119,14 @@ user = request.user reg_count = Registration.objects.all().count() + scope_entity = Event.objects.get(scope=scope) + if user.is_authenticated(): try: profile = user.get_profile() except: - profile, new = UserProfile.objects.get_or_create(user=user) + profile, new = UserProfile.objects.get_or_create( + user=user, scope=scope_entity) if new: profile.save() try: @@ -130,7 +151,6 @@ login_form = AuthenticationForm(data=request.POST) if login_form.is_valid(): - from django.contrib.auth import login login(request, login_form.get_user()) redirect_to = reverse('scipycon_submit_registration', @@ -143,12 +163,14 @@ passwd = None if not user.is_authenticated(): if registrant_form.is_valid(): - newuser = scipycon_createregistrant(request, registrant_form.data) + newuser = scipycon_createregistrant( + request, registrant_form.data) + # Log in user passwd = User.objects.make_random_password() newuser.set_password(passwd) newuser.save() - from django.contrib.auth import authenticate + user = authenticate(username=newuser.username, password=passwd) login(request, user) @@ -158,36 +180,28 @@ else: newuser = user - if registration_form.is_valid() and newuser: - allow_contact = registration_form.data.get('allow_contact') and \ + if registration_form.is_valid() and newuser and wifi_form.is_valid(): + allow_contact = registration_form.cleaned_data.get( + 'allow_contact') and True or False + conference = registration_form.cleaned_data.get( + 'conference') and True or False + tutorial = registration_form.cleaned_data.get('tutorial') and \ True or False - conference = registration_form.data.get('conference') and \ - True or False - tutorial = registration_form.data.get('tutorial') and \ - True or False - sprint = registration_form.data.get('sprint') and \ + sprint = registration_form.cleaned_data.get('sprint') and \ True or False registrant = User.objects.get(pk=newuser.id) - presenter = None - talks = Talk.objects.filter( - speaker=registrant).filter(approved=True) - if talks: - for talk in talks: - if talk.duration == '30': - presenter = True - elif talk.duration == '60': - presenter = True - reg = Registration( - # slug = newuser.username, + scope=scope_entity, registrant = registrant, - organisation = registration_form.data.get('organisation'), - occupation = registration_form.data.get('occupation'), - city = registration_form.data.get('city'), - tshirt = registration_form.data.get('tshirt'), + organisation = registration_form.cleaned_data.get( + 'organisation'), + occupation = registration_form.cleaned_data.get('occupation'), + city = registration_form.cleaned_data.get('city'), + #tshirt = registration_form.data.get('tshirt'), postcode = registration_form.cleaned_data.get('postcode'), + phone_num = registration_form.cleaned_data.get('phone_num'), allow_contact = allow_contact, conference = conference, tutorial = tutorial, @@ -196,14 +210,12 @@ # get id and use as slug and invoice number id = reg.id - slug = 'SPYIN10%03d' % id + slug = 'SPYIN10%05d' % id reg.slug = slug reg.save() - # additional tasks: - if wifi_form.is_valid(): - wifi = wifi_form.save(registrant) - + wifi = wifi_form.save(registrant, scope_entity) + # 1. include random password if we are a new user if passwd: send_confirmation(registrant, slug, password=passwd)