diff options
author | Madhusudan.C.S | 2010-07-21 02:06:51 +0530 |
---|---|---|
committer | Madhusudan.C.S | 2010-07-21 02:06:51 +0530 |
commit | 128e5621c9ae269c12294ede5ad234333743b829 (patch) | |
tree | ef036c58c3264743fad2a44a3dc4fb791e76a4bc | |
parent | 260030733f0c1f760203186f587b654bb88c63e2 (diff) | |
download | scipycon-128e5621c9ae269c12294ede5ad234333743b829.tar.gz scipycon-128e5621c9ae269c12294ede5ad234333743b829.tar.bz2 scipycon-128e5621c9ae269c12294ede5ad234333743b829.zip |
Added phone number, modified Occupation to be choice field.
-rw-r--r-- | project/scipycon/registration/forms.py | 72 | ||||
-rw-r--r-- | project/scipycon/registration/models.py | 19 | ||||
-rw-r--r-- | project/scipycon/registration/views.py | 158 |
3 files changed, 135 insertions, 114 deletions
diff --git a/project/scipycon/registration/forms.py b/project/scipycon/registration/forms.py index 820c084..8e5c27a 100644 --- a/project/scipycon/registration/forms.py +++ b/project/scipycon/registration/forms.py @@ -1,43 +1,39 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - -#django from django import forms from django.core.exceptions import ObjectDoesNotExist -#django.contrib -from django.contrib.auth.models import User - -from .models import SIZE_CHOICES -from .models import Registration -from .models import Wifi +from project.scipycon.registration.models import SIZE_CHOICES +from project.scipycon.registration.models import OCCUPATION_CHOICES +from project.scipycon.registration.models import Wifi class RegistrationSubmitForm(forms.Form): - """PyCon registration form + """SciPyCon registration form """ - tshirt = forms.ChoiceField(choices=SIZE_CHOICES, required=True, - label=u'T-shirt size', help_text=u'Yes, we all get a t-shirt!') + #tshirt = forms.ChoiceField(choices=SIZE_CHOICES, required=True, + # label=u'T-shirt size', help_text=u'Yes, we all get a t-shirt!') organisation = forms.CharField(required=True, label=u'Organisation', help_text=u'The primary organisation that you are a member of.', max_length=255, widget=forms.TextInput(attrs={'size':'50'})) - occupation = forms.CharField(required=True, label=u'Occupation', - help_text=u'Title of your occupation', - max_length=255, - widget=forms.TextInput(attrs={'size':'50'})) - city = forms.CharField(required=True, label=u'City', - help_text=u'City of residence', + occupation = forms.ChoiceField(choices=OCCUPATION_CHOICES, + required=True, label=u'Occupation', + help_text=u'Title of your occupation') + city = forms.CharField(required=False, label=u'City', + help_text=u'Your city of residence', max_length=255, widget=forms.TextInput(attrs={'size':'50'})) postcode = forms.CharField(required=False, label=u'Postcode', - help_text=u'This field is optional', + help_text=u'PIN Code of your area', max_length=10, widget=forms.TextInput(attrs={'size':'10'})) + phone_num = forms.CharField(required=False, label=u'Phone Number', + help_text=u'Phone number. Although optional, please provide it for ' + 'faster correspondence', max_length=14, + widget=forms.TextInput(attrs={'size':'20'})) allow_contact = forms.BooleanField(required=False, label=u'Contact', help_text=u'May organizers of SciPy.in contact you after the event?') conference = forms.BooleanField(required=False, label=u'Conference', - help_text=u"""Do you intend to attend the SciPy conference? + help_text=u"""Do you intend to attend SciPy.in 2010 conference? Note: Only conference has an registration fee of Rs.200 which you will pay on the spot.""") tutorial = forms.BooleanField(required=False, label=u'Tutorial', @@ -45,14 +41,17 @@ class RegistrationSubmitForm(forms.Form): sprint = forms.BooleanField(required=False, label=u'Sprint', help_text=u'Do you intend to attend the sprints?') - def demographic_fields(self): + def occupation_fields(self): return (self['organisation'], - self['occupation'], - self['city'], - self['postcode']) + self['occupation']) + + def demographic_fields(self): + return (self['city'], + self['postcode'], + self['phone_num']) def personal_fields(self): - return (self['tshirt'], + return (#self['tshirt'], self['conference'], self['tutorial'], self['sprint'], @@ -61,15 +60,20 @@ class RegistrationSubmitForm(forms.Form): class RegistrationEditForm(RegistrationSubmitForm): id = forms.CharField(widget=forms.HiddenInput) - sponsor = forms.CharField(required=False, widget=forms.HiddenInput) class WifiForm(forms.ModelForm): """PyCon wifi form """ - def save(self, user): - wifi = Wifi(user=user, wifi=self.cleaned_data['wifi']) + def save(self, user, scope): + try: + wifi = Wifi.objects.get(user=user, scope=scope) + except ObjectDoesNotExist: + wifi = Wifi(user=user, scope=scope) + + wifi.wifi = self.cleaned_data['wifi'] wifi.save() + return wifi class Meta: @@ -109,13 +113,7 @@ IC = ( ('T-size', 'tshirt'), ) -SC = ( - ('all', 'all'), - ('S', 'S'), - ('M', 'M'), - ('L', 'L'), - ('XL', 'XL'), - ) + class RegistrationAdminSelectForm(forms.Form): """ Used to make selection for csv download @@ -126,7 +124,7 @@ class RegistrationAdminSelectForm(forms.Form): label=u'By amount') by_party = forms.ChoiceField(choices=HC, required=False, label=u'by party') - by_tshirt = forms.ChoiceField(choices=SC, required=False, + by_tshirt = forms.ChoiceField(choices=SIZE_CHOICES, required=False, label=u'by tshirt size') order_by = forms.ChoiceField(choices=OC, required=False, label=u'order results') diff --git a/project/scipycon/registration/models.py b/project/scipycon/registration/models.py index 8486282..a465bdc 100644 --- a/project/scipycon/registration/models.py +++ b/project/scipycon/registration/models.py @@ -5,8 +5,6 @@ from project.scipycon.base import models as base_models from project.scipycon.registration.labels import WIFI_CHOICES from project.scipycon.registration.labels import WIFI_HELP -from project.scipycon.registration.utils import send_confirmation_payment_email -from project.scipycon.registration.utils import send_banking_fix_email SIZE_CHOICES = ( @@ -14,12 +12,24 @@ SIZE_CHOICES = ( ('M', 'M'), ('L', 'L'), ('XL', 'XL'), + ('XXL', 'XXL'), + ) + +OCCUPATION_CHOICES = ( + ('Education: Student', 'Education: Student'), + ('Education: Faculty', 'Education: Faculty'), + ('Education: Research', 'Education: Research'), + ('Education: Other', 'Education: Other'), + ('Corporate: Research', 'Corporate: Research'), + ('Corporate: Other', 'Corporate: Other'), + ('Other', 'Other') ) class Wifi(base_models.ScopedBase): """Defines wifi options at SciPy.in """ + user = models.ForeignKey(User) wifi = models.CharField(max_length=50, choices=WIFI_CHOICES, @@ -35,7 +45,8 @@ class Registration(base_models.ScopedBase): organisation = models.CharField(max_length=255, blank=True) - occupation = models.CharField(max_length=255, blank=True) + occupation = models.CharField(max_length=255, + choices=OCCUPATION_CHOICES, blank=True) city = models.CharField(max_length=255, blank=True) @@ -43,7 +54,7 @@ class Registration(base_models.ScopedBase): phone_num = models.CharField(max_length=14, blank=True) - tshirt = models.CharField(max_length=2, choices=SIZE_CHOICES) + tshirt = models.CharField(max_length=3, choices=SIZE_CHOICES) conference = models.BooleanField(default=False) diff --git a/project/scipycon/registration/views.py b/project/scipycon/registration/views.py index 7ac1ca0..b9d6419 100644 --- a/project/scipycon/registration/views.py +++ b/project/scipycon/registration/views.py @@ -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.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.registration.models import Registration -from project.scipycon.registration.forms import RegistrationSubmitForm +from project.scipycon.base.models import Event from project.scipycon.registration.forms import RegistrationEditForm -from project.scipycon.registration.forms import RegistrationAdminSelectForm +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.utils import set_message_cookie -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 @@ def edit_registration(request, scope, id, """ 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 @@ def edit_registration(request, scope, id, + ' 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 @@ def submit_registration(request, scope, 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 @@ def submit_registration(request, scope, 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 @@ def submit_registration(request, scope, 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 @@ def submit_registration(request, scope, else: newuser = user - if registration_form.is_valid() and newuser: - allow_contact = registration_form.data.get('allow_contact') and \ - True or False - conference = registration_form.data.get('conference') 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 - 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 @@ def submit_registration(request, scope, # 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) |