project/scipycon/registration/views.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Tue, 16 Nov 2010 17:37:36 +0530
branchpayments
changeset 263 02593358eddc
parent 257 e2ff0c70014d
child 276 325ec5a41269
permissions -rw-r--r--
Made adjustments in the view to make paid field a dummy form field and not a model field. Also added confirmed field as model field.
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
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
    15
from project.scipycon.registration.forms import PaymentForm
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    16
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
    17
from project.scipycon.registration.models import Accommodation
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
    18
from project.scipycon.registration.models import Payment
137
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.models import Registration
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    20
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
    21
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
    22
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
    23
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
    24
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
    25
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
    26
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
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
    29
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
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    31
@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
    32
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
    33
                  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
    34
    """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
    35
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
    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
    37
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    38
    user = request.user
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    39
    if user.is_authenticated():
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    40
        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
    41
    else:
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    42
        registration = None
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    43
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    44
    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
    45
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
    46
    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
    47
        '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
    48
        '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
    49
        'registrations' : registrations,
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    50
        'registration': registration,
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    51
        '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
    52
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
@login_required
111
0e2c94c6a9e8 Adjusted views to send the scope in params.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 106
diff changeset
    54
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
    55
                      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
    56
    """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
    57
    """
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
    58
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    59
    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
    60
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
    reg = Registration.objects.get(pk=id)
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    62
    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
    63
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
    64
    # TODO: This is an ugly hack to add accommodation and payment forms
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
    65
    # details at later stage for SciPy.in 2010. This must be removed for
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
    66
    # SciPy.in 2011
247
2907855f18c4 Rename created variable name to acco_created for acco object creation in edit registration view function.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 202
diff changeset
    67
    acco, acco_created = Accommodation.objects.get_or_create(
2907855f18c4 Rename created variable name to acco_created for acco object creation in edit registration view function.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 202
diff changeset
    68
        user=reg.registrant, scope=scope_entity)
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
    69
    payment, payment_created = Payment.objects.get_or_create(
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
    70
        user=reg.registrant, scope=scope_entity)
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    71
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
    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
    73
        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
    74
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
    75
        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
    76
            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
    77
            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
    78
                      + ' 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
    79
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
    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
    81
        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
    82
        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
    83
        acco_form = AccommodationForm(data=request.POST)
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
    84
        payment_form = PaymentForm(data=request.POST)
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    85
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
    86
        if (registration_form.is_valid() and wifi_form.is_valid() and
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
    87
            acco_form.is_valid() and payment_form.is_valid()):
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    88
            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
    89
            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
    90
            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
    91
            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
    92
            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
    93
            #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
    94
            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
    95
                '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
    96
            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
    97
                '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
    98
            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
    99
                '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
   100
            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
   101
                '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
   102
            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
   103
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   104
            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
   105
            acco = acco_form.save(reg.registrant, reg.scope)
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   106
            payment = payment_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
   107
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
            # 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
   109
            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
   110
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
            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
   112
                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
   113
    else:
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   114
        registration_form = RegistrationEditForm(initial={
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   115
            'id' : id,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   116
            'organisation' : reg.organisation,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   117
            'occupation' : reg.occupation,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   118
            'city' : reg.city,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   119
            '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
   120
            #'tshirt' : reg.tshirt,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   121
            'conference': reg.conference,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   122
            'tutorial': reg.tutorial,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   123
            'postcode' : reg.postcode,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   124
            'sprint' : reg.sprint,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   125
            '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
   126
            })
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   127
        wifi_form = WifiForm(initial={
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   128
            'user': wifi.user,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   129
            'scope': wifi.scope,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   130
            'wifi': wifi.wifi
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   131
            })
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   132
        acco_form = AccommodationForm(initial={
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   133
            'user': acco.user,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   134
            'scope': acco.scope,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   135
            'sex': acco.sex,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   136
            'accommodation_required': acco.accommodation_required,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   137
            'accommodation_days': acco.accommodation_days,
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   138
            })
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   139
        payment_form = PaymentForm(initial={
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   140
            'user': payment.user,
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   141
            'scope': payment.scope,
263
02593358eddc Made adjustments in the view to make paid field a dummy form field and not a model field. Also added confirmed field as model field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 257
diff changeset
   142
            'paid': payment.type or payment.details,
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   143
            'type': payment.type,
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   144
            'details': payment.details,
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   145
            })
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
111
0e2c94c6a9e8 Adjusted views to send the scope in params.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 106
diff changeset
   147
    return render_to_response(
0e2c94c6a9e8 Adjusted views to send the scope in params.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 106
diff changeset
   148
        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
   149
        'params': {'scope': scope},
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   150
        'registration': {'id': id},
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   151
        'registration_form': registration_form,
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   152
        'wifi_form': wifi_form,
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   153
        'acco_form': acco_form,
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   154
        'payment_form': payment_form}))
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
106
3a31881564ba Add a scope pattern to the URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   156
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
   157
        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
   158
    """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
   159
    """
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
   160
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   161
    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
   162
    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
   163
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   164
    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
   165
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   166
    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
   167
        try:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
            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
   169
        except:
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   170
            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
   171
                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
   172
            if new:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
                profile.save()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   174
        try:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   175
            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
   176
            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
   177
                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
   178
                                      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
   179
                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
   180
                    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
   181
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
        except ObjectDoesNotExist:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
            pass
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
    message = None
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
    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
   188
        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
   189
        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
   190
        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
   191
        acco_form = AccommodationForm(data=request.POST)
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   192
        payment_form = PaymentForm(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
   193
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
        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
   195
            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
   196
            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
   197
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   198
                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
   199
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
   200
                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
   201
                                      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
   202
                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
   203
                        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
   204
                               'with registration.')
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
        newuser = None
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   207
        passwd = None
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   208
        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
   209
            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
   210
                newuser = scipycon_createregistrant(
142
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
   211
                    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
   212
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
                # 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
   214
                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
   215
                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
   216
                newuser.save()
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   217
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   218
                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
   219
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   220
                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
   221
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   222
                newuser = user
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
        else:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
            newuser = user
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   227
        if (registration_form.is_valid() and newuser and wifi_form.is_valid()
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   228
            and acco_form.is_valid() and payment_form.is_valid()):
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   229
            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
   230
                '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
   231
            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
   232
                '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
   233
            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
   234
                True or False
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   235
            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
   236
                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
   237
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   238
            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
   239
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   240
            reg = Registration(
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   241
                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
   242
                registrant = registrant,
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   243
                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
   244
                    'organisation'),
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   245
                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
   246
                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
   247
                #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
   248
                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
   249
                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
   250
                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
   251
                conference = conference,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   252
                tutorial = tutorial,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   253
                sprint = sprint)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
            reg.save() 
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   256
            # 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
   257
            id = reg.id
142
70fcb57d8d15 Added event and registrants to Registration summary page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
   258
            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
   259
            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
   260
            reg.save()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   261
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   262
            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
   263
            acco = acco_form.save(registrant, scope_entity)
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   264
            payment = payment_form.save(registrant, scope_entity)
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
   265
186
8bd09b59f359 Handling the password in mail problem
amit
parents: 146
diff changeset
   266
            send_confirmation(registrant, scope_entity,password=passwd)
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   267
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
   268
            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
   269
                                  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
   270
            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
   271
                    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
   272
                           '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
   273
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   274
    else:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   275
        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
   276
        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
   277
        wifi_form = WifiForm()
202
b4391b3d5fcc Edit views to make room for accommodation forms.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 194
diff changeset
   278
        acco_form = AccommodationForm()
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   279
        payment_form = PaymentForm()
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   280
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   281
    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
   282
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   283
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   284
    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
   285
        '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
   286
        '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
   287
        '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
   288
        '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
   289
        'acco_form': acco_form,
251
b99607287a52 Add payment forms and object details in edit and submit registration views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 247
diff changeset
   290
        'payment_form': payment_form,
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   291
        '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
   292
        'message' : message,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   293
        '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
   294
    }))
193
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   295
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   296
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   297
@login_required
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   298
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
   299
             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
   300
    """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
   301
    """
194
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   302
193
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   303
    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
   304
        redirect_to = reverse('scipycon_login', kwargs={'scope': scope})
255
b20d55891709 Add cookie and return message for regstats view function.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   305
        return set_message_cookie(
b20d55891709 Add cookie and return message for regstats view function.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   306
            redirect_to, msg = u'You must be a staff on this website to '
b20d55891709 Add cookie and return message for regstats view function.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   307
            'access this page.')
193
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   308
194
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   309
    q = Registration.objects.all()
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   310
    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
   311
    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
   312
    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
   313
ed5828a90109 Copy the download csv code that was earlier written but scraped.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 186
diff changeset
   314
    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
   315
        {'params': {'scope': scope},
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   316
         'conf_num': conf_num, 
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   317
         'tut_num': tut_num,
808abc104b55 View to calculate the number of registrants per event.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 193
diff changeset
   318
         'sprint_num': sprint_num,
257
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   319
         }))
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   320
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   321
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   322
@login_required
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   323
def manage_payments(request, scope,
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   324
                    template_name='registration/manage_payments.html'):
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   325
    """View that gives a form to manage payments.
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   326
    """
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   327
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   328
    if not request.user.is_superuser:
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   329
        redirect_to = reverse('scipycon_login', kwargs={'scope': scope})
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   330
        return set_message_cookie(
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   331
            redirect_to, msg = u'You must be an admin on this website to '
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   332
            'access this page.')
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   333
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   334
    message = None
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   335
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   336
    scope_entity = Event.objects.get(scope=scope)
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   337
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   338
    if request.method == 'POST':
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   339
        post_data = request.POST
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   340
        list_user_ids = []
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   341
        for user_id_string in post_data:
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   342
            id_str_list = user_id_string.split('_')
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   343
            if (len(id_str_list) == 3 and id_str_list[0] == 'registrant' and
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   344
              id_str_list[1] == 'id'):
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   345
                id = int(id_str_list[2])
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   346
                reg_user = User.objects.get(pk=id)
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   347
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   348
                payment, created = reg_user.payment_set.get_or_create(
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   349
                  user=reg_user, scope=scope_entity)
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   350
263
02593358eddc Made adjustments in the view to make paid field a dummy form field and not a model field. Also added confirmed field as model field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 257
diff changeset
   351
                payment.confirmed = True
257
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   352
                payment.save()
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   353
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   354
                list_user_ids.append(id)
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   355
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   356
        # This is done to unset for the confirmation for users for whom
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   357
        # mistakenly confirmation was set.
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   358
        # (TODO) This is a very expensive operation, any better solution
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   359
        # will be appreciated.
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   360
        unpaid_users = User.objects.exclude(pk__in=list_user_ids)
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   361
        for user in unpaid_users:
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   362
            payment, created = user.payment_set.get_or_create(
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   363
              user=user, scope=scope_entity)
263
02593358eddc Made adjustments in the view to make paid field a dummy form field and not a model field. Also added confirmed field as model field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 257
diff changeset
   364
            payment.confirmed = False
257
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   365
            payment.save()
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   366
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   367
    registrants = Registration.objects.all()
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   368
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   369
    return render_to_response(template_name, RequestContext(request,
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   370
        {'params': {'scope': scope},
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   371
         'registrants': registrants,
e2ff0c70014d Add a view to manage payments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 255
diff changeset
   372
         }))