project/scipycon/registration/views.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Thu, 18 Nov 2010 16:10:38 +0530
branchsouth-migration
changeset 275 679a9cab4bf1
parent 273 5129e1427557
parent 238 0149f28a4f74
child 276 325ec5a41269
permissions -rw-r--r--
Merge the south migration branch with an additional field for Laptop registration number with default branch.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
     1
from django.contrib.auth import authenticate
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
     2
from django.contrib.auth import login
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
from django.contrib.auth.decorators import login_required
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
from django.contrib.auth.forms import AuthenticationForm
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
from django.contrib.auth.models import User
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
from django.core.exceptions import ObjectDoesNotExist
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
     7
from django.core.urlresolvers import reverse
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
     8
from django.shortcuts import render_to_response
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
     9
from django.template import RequestContext
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    11
from project.scipycon.base.models import Event
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    12
from project.scipycon.registration.forms import RegistrationEditForm
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    13
from project.scipycon.registration.forms import RegistrationSubmitForm
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    14
from project.scipycon.registration.forms import AccommodationForm
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    15
from project.scipycon.registration.forms import WifiForm
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    16
from project.scipycon.registration.models import Accommodation
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    17
from project.scipycon.registration.models import Registration
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    18
from project.scipycon.registration.models import Wifi
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    19
from project.scipycon.registration.utils import send_confirmation
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    20
from project.scipycon.user.forms import RegistrantForm
96
178b89a3ca4f Removed unwanted files and made more changes to make SciPyCon a clean app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 94
diff changeset
    21
from project.scipycon.user.models import UserProfile
178b89a3ca4f Removed unwanted files and made more changes to make SciPyCon a clean app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 94
diff changeset
    22
from project.scipycon.user.utils import scipycon_createregistrant
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    23
from project.scipycon.utils import set_message_cookie
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
REG_TOTAL = 1000
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    28
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    29
@login_required
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    30
def registrations(request, scope, 
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    31
                  template_name='registration/registrations.html'):
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    32
    """Simple page to count registrations"""
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
    registrations = Registration.objects.all().count()
142
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    35
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    36
    user = request.user
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    37
    if user.is_authenticated():
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    38
        registration = Registration.objects.get(registrant=user)
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    39
    else:
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    40
        registration = None
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    41
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    42
    event = Event.objects.get(scope=scope)
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    43
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    44
    return render_to_response(template_name, RequestContext(request, {
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    45
        'params': {'scope': scope},
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
        'over_reg' : registrations >= REG_TOTAL and True or False,
142
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    47
        'registrations' : registrations,
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    48
        'registration': registration,
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    49
        'event': event}))
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
@login_required
111
0e2c94c6a9e8 Adjusted views to send the scope in params.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 106
diff changeset
    52
def edit_registration(request, scope, id,
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    53
                      template_name='registration/edit-registration.html'):
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    54
    """Allows users that submitted a registration to edit it.
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    55
    """
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    56
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    57
    scope_entity = Event.objects.get(scope=scope)
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    58
233
394576ff8a2f Fix major bug: Change hard coded registration form redirect to based on User and do int conversions for ids.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 231
diff changeset
    59
    reg = Registration.objects.get(pk=int(id))
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    60
    wifi = Wifi.objects.get(user=reg.registrant)
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    62
    # TODO: This is an ugly hack to add accommodation form
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    63
    # details at later stage for SciPy.in 2010. This must be
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    64
    # removed for SciPy.in 2011
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    65
    acco, created = Accommodation.objects.get_or_create(user=reg.registrant,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    66
                                                        scope=scope_entity)
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    67
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
    if reg.registrant != request.user:
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    69
        redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    70
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    71
        return set_message_cookie(
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    72
            redirect_to,
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    73
            msg = u'Redirected because the registration you selected' \
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
                      + ' is not your own.')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
    if request.method == 'POST':
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    77
        registration_form = RegistrationEditForm(data=request.POST)
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    78
        wifi_form = WifiForm(data=request.POST)
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    79
        acco_form = AccommodationForm(data=request.POST)
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    80
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    81
        if (registration_form.is_valid() and wifi_form.is_valid() and
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    82
            acco_form.is_valid()):
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    83
            reg.organisation = registration_form.data.get('organisation')
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    84
            reg.occupation = registration_form.data.get('occupation')
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    85
            reg.city = registration_form.data.get('city')
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    86
            reg.phone_num = registration_form.data.get('phone_num')
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    87
            reg.postcode = registration_form.data.get('postcode')
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    88
            #reg.tshirt = registration_form.data.get('tshirt')
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    89
            reg.allow_contact = registration_form.data.get(
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    90
                'allow_contact') and True or False
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    91
            reg.conference = registration_form.data.get(
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    92
                'conference') and True or False
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    93
            reg.tutorial = registration_form.data.get(
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    94
                'tutorial') and True or False
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    95
            reg.sprint = registration_form.data.get(
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    96
                'sprint') and True or False
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
            reg.save()
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
    98
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    99
            wifi = wifi_form.save(reg.registrant, reg.scope)
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   100
            acco = acco_form.save(reg.registrant, reg.scope)
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   101
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
            # Saved.. redirect
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   103
            redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   104
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
            return set_message_cookie(redirect_to,
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   106
                msg = u'Your changes have been saved.')
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
    else:
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   108
        registration_form = RegistrationEditForm(initial={
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   109
            'id' : id,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   110
            'organisation' : reg.organisation,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   111
            'occupation' : reg.occupation,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   112
            'city' : reg.city,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   113
            'phone_num': reg.phone_num,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   114
            #'tshirt' : reg.tshirt,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   115
            'conference': reg.conference,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   116
            'tutorial': reg.tutorial,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   117
            'postcode' : reg.postcode,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   118
            'sprint' : reg.sprint,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   119
            'allow_contact' : reg.allow_contact,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   120
            })
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   121
        wifi_form = WifiForm(initial={
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   122
            'user': wifi.user,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   123
            'scope': wifi.scope,
273
5129e1427557 Add registration_id field to initial form in the field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 233
diff changeset
   124
            'wifi': wifi.wifi,
5129e1427557 Add registration_id field to initial form in the field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 233
diff changeset
   125
            'registration_id': wifi.registration_id
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
            })
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   127
        acco_form = AccommodationForm(initial={
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   128
            'user': acco.user,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   129
            'scope': acco.scope,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   130
            'sex': acco.sex,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   131
            'accommodation_required': acco.accommodation_required,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   132
            'accommodation_days': acco.accommodation_days,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   133
            })
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
111
0e2c94c6a9e8 Adjusted views to send the scope in params.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 106
diff changeset
   135
    return render_to_response(
0e2c94c6a9e8 Adjusted views to send the scope in params.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 106
diff changeset
   136
        template_name, RequestContext(request, {
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   137
        'params': {'scope': scope},
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   138
        'registration': {'id': id},
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   139
        'registration_form': registration_form,
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   140
        'wifi_form': wifi_form,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   141
        'acco_form': acco_form}))
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   142
106
3a31881564ba Add a scope pattern to the URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   143
def submit_registration(request, scope,
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
        template_name='registration/submit-registration.html'):
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   145
    """Allows user to edit registration
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   146
    """
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   147
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
    user = request.user
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   149
    reg_count = Registration.objects.all().count()
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   150
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   151
    scope_entity = Event.objects.get(scope=scope)
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   152
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
    if user.is_authenticated():
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   154
        try:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
            profile = user.get_profile()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   156
        except:
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   157
            profile, new = UserProfile.objects.get_or_create(
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   158
                user=user, scope=scope_entity)
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   159
            if new:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   160
                profile.save()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   161
        try:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   162
            registration = Registration.objects.get(registrant=user)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   163
            if registration:
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   164
                redirect_to = reverse('scipycon_account',
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   165
                                      kwargs={'scope': scope})
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   166
                return set_message_cookie(
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   167
                    redirect_to, msg = u'You have already been registered.')
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   169
        except ObjectDoesNotExist:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
            pass
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
    message = None
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   174
    if request.method == 'POST':
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   175
        registration_form = RegistrationSubmitForm(data=request.POST)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   176
        registrant_form = RegistrantForm(data=request.POST)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   177
        wifi_form = WifiForm(data=request.POST)
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   178
        acco_form = AccommodationForm(data=request.POST)
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   179
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   180
        if request.POST.get('action', None) == 'login':
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
            login_form = AuthenticationForm(data=request.POST)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
            if login_form.is_valid():
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
                login(request, login_form.get_user())
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   186
                redirect_to = reverse('scipycon_submit_registration',
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   187
                                      kwargs={'scope': scope})
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
                return set_message_cookie(redirect_to,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
                        msg = u'You have been logged in please continue' + \
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
                               'with registration.')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   191
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
        newuser = None
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
        passwd = None
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
        if not user.is_authenticated():
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
            if registrant_form.is_valid():
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   196
                newuser = scipycon_createregistrant(
142
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
   197
                    request, registrant_form.data, scope)
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   198
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
                # Log in user
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
                passwd = User.objects.make_random_password()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   201
                newuser.set_password(passwd)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
                newuser.save()
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   203
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   204
                user = authenticate(username=newuser.username, password=passwd)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   205
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   206
                login(request, user)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   207
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   208
                newuser = user
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   209
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   210
        else:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   211
            newuser = user
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   213
        if (registration_form.is_valid() and newuser and wifi_form.is_valid()
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   214
            and acco_form.is_valid()):
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   215
            allow_contact = registration_form.cleaned_data.get(
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   216
                'allow_contact') and True or False
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   217
            conference = registration_form.cleaned_data.get(
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   218
                'conference') and True or False
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   219
            tutorial = registration_form.cleaned_data.get('tutorial') and \
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   220
                True or False
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   221
            sprint = registration_form.cleaned_data.get('sprint') and \
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   222
                True or False
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
            registrant = User.objects.get(pk=newuser.id)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
            reg = Registration(
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   227
                scope=scope_entity,
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   228
                registrant = registrant,
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   229
                organisation = registration_form.cleaned_data.get(
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   230
                    'organisation'),
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   231
                occupation = registration_form.cleaned_data.get('occupation'),
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   232
                city = registration_form.cleaned_data.get('city'),
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   233
                #tshirt = registration_form.data.get('tshirt'),
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   234
                postcode = registration_form.cleaned_data.get('postcode'),
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   235
                phone_num = registration_form.cleaned_data.get('phone_num'),
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   236
                allow_contact = allow_contact,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   237
                conference = conference,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   238
                tutorial = tutorial,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   239
                sprint = sprint)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   240
            reg.save() 
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   241
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   242
            # get id and use as slug and invoice number
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   243
            id = reg.id
142
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
   244
            slug = 'SCIPYIN2010%04d' % id
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   245
            reg.slug = slug
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   246
            reg.save()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   247
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   248
            wifi = wifi_form.save(registrant, scope_entity)
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   249
            acco = acco_form.save(registrant, scope_entity)
231
839dd1745ad2 Fix style issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 202
diff changeset
   250
            send_confirmation(registrant, scope_entity, password=passwd)
126
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   251
            redirect_to = reverse('scipycon_registrations',
f185cb8316cf Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 111
diff changeset
   252
                                  kwargs={'scope': scope})
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   253
            return set_message_cookie(redirect_to,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
                    msg = u'Thank you, your registration has been submitted '\
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
                           'and an email has been sent with payment details.')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   256
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   257
    else:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   258
        registration_form = RegistrationSubmitForm()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   259
        registrant_form = RegistrantForm()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   260
        wifi_form = WifiForm()
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   261
        acco_form = AccommodationForm()
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   262
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   263
    login_form = AuthenticationForm()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   264
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   265
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   266
    return render_to_response(template_name, RequestContext(request, {
111
0e2c94c6a9e8 Adjusted views to send the scope in params.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 106
diff changeset
   267
        'params': {'scope': scope},
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   268
        'registration_form': registration_form,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   269
        'registrant_form' : registrant_form,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   270
        'over_reg' : reg_count >= REG_TOTAL and True or False,
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   271
        'acco_form': acco_form,
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   272
        'wifi_form' : wifi_form,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   273
        'message' : message,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   274
        'login_form' : login_form
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   275
    }))
193
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   276
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   277
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   278
@login_required
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   279
def regstats(request, scope,
194
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   280
             template_name='registration/regstats.html'):
193
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   281
    """View that gives the statistics of registrants.
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   282
    """
194
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   283
193
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   284
    if not request.user.is_staff:
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   285
        redirect_to = reverse('scipycon_login', kwargs={'scope': scope})
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   286
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   287
194
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   288
    q = Registration.objects.all()
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   289
    conf_num = q.filter(conference=True).count()
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   290
    tut_num = q.filter(tutorial=True).count()
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   291
    sprint_num = q.filter(sprint=True).count()
193
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   292
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   293
    return render_to_response(template_name, RequestContext(request,
194
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   294
        {'params': {'scope': scope},
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   295
         'conf_num': conf_num, 
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   296
         'tut_num': tut_num,
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   297
         'sprint_num': sprint_num,
236
29ecd3dd6565 Merging heads
Amit Sethi
parents: 194
diff changeset
   298
         }))