Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Tue, 20 Jul 2010 19:27:16 +0530
changeset 126 f185cb8316cf
parent 125 2456984cecfc
child 127 328b5244aa1c
Added scope to all URLs, all reverse functions and all view methods and removed unnecessary functions.
project/scipycon/registration/views.py
--- a/project/scipycon/registration/views.py	Tue Jul 20 19:26:21 2010 +0530
+++ b/project/scipycon/registration/views.py	Tue Jul 20 19:27:16 2010 +0530
@@ -1,7 +1,6 @@
 import cStringIO as StringIO
 import csv
 
-from django.conf import settings
 from django.shortcuts import render_to_response
 from django.template.loader import render_to_string
 from django.shortcuts import get_object_or_404
@@ -15,149 +14,47 @@
 from django.core.exceptions import ObjectDoesNotExist
 
 from project.scipycon.utils import set_message_cookie
-from project.scipycon.utils import slugify
 from project.scipycon.user.models import UserProfile
 from project.scipycon.user.utils import scipycon_createregistrant
 from project.scipycon.user.forms import RegistrantForm
 from project.scipycon.talk.models import Talk
 
-from .models import Registration
-from .models import Wifi
-from .forms import RegistrationSubmitForm
-from .forms import RegistrationEditForm
-from .forms import RegistrationAdminSelectForm
-from .forms import WifiForm
-from .utils import send_confirmation
+from project.scipycon.registration.models import Registration
+from project.scipycon.registration.forms import RegistrationSubmitForm
+from project.scipycon.registration.forms import RegistrationEditForm
+from project.scipycon.registration.forms import RegistrationAdminSelectForm
+from project.scipycon.registration.forms import WifiForm
+from project.scipycon.registration.utils import send_confirmation
 
 from .forms import IC
 
 REG_TOTAL = 1000
 
-@login_required
-def download_csv(request, scope,
-        template_name = 'registration/download-csv.html'):
-    """
-    """
-    if not request.user.is_staff:
-        redirect_to = reverse('scipycon_login')
-    if request.method == "POST":
-        form = RegistrationAdminSelectForm(request.POST)
-        if form.is_valid():
-            conference = form.cleaned_data['by_conference']
-            tutorial = form.cleaned_data['by_tutorial']
-            sprint = form.cleaned_data['by_sprint']
-            amount = form.cleaned_data['by_amount']
-            tshirt = form.cleaned_data['by_tshirt']
-            order_by = form.cleaned_data['order_by']
-            include = form.cleaned_data['include']
-            q = Registration.objects.all()
-            if conference == 'conference':
-                q = q.filter(conference=True)
-            elif conference == 'no conference':
-                q = q.filter(conference=False)
-            elif tutorial == 'tutorial':
-                q = q.filter(tutorial=True)
-            elif tutorial == 'no tutorial':
-                q = q.filter(tutorial=False)
-            if sprint == 'sprint':
-                q = q.filter(sprint=True)
-            if sprint == 'no sprint':
-                q = q.filter(sprint=False)
-            elif tshirt != 'all':
-                q = q.filter(tshirt=tshirt)
-            q = q.order_by('registrant__email')
-            query = q.query
-            results = list(q)
-            if include == []:
-                # default to include all fields
-                include = [i[0] for i in IC]
-            if results:
-                response = HttpResponse(mimetype='text/csv')
-                response['Content-Disposition'] = 'attachment; filename=registrations.csv'
-                output = csv.writer(response)
-                output.writerow([h for h in include])
-                for row in results:
-                    conference = row.conference == True and 'yes' or 'no'
-                    tutorial = row.tutorial == True and 'yes' or 'no'
-                    sprint = row.sprint == True and 'yes' or 'no'
-                    wrow = []
-                    if 'Name' in include:
-                        wrow.append(
-                            row.registrant.get_full_name().encode('utf-8'))
-                    if 'Email' in include:
-                        wrow.append(row.registrant.email.encode('utf-8'))
-                    if 'Organisation' in include:
-                        wrow.append(row.organisation.encode('utf-8'))
-                    if 'Conference' in include:
-                        wrow.append(conference)
-                    if 'Tutorial' in include:
-                        wrow.append(tutorial)
-                    if 'Sprint' in include:
-                        wrow.append(sprint)
-                    if 'T-size' in include:
-                        wrow.append(row.tshirt)
-                    output.writerow(wrow)
-                return response
-            else:
-                no_results = u'No results found for the query'
+
+def registrations(request, scope, 
+                  template_name='registration/registrations.html'):
+    """Simple page to count registrations"""
 
-    else:
-        form = RegistrationAdminSelectForm()
-    return render_to_response(template_name, RequestContext(request,
-        locals()))
-
-# NOT REQUIRED FOR SciPy.in
-@login_required
-def invoice(request, scope, template_name='registration/invoice.html'):
-    user = request.user
-    registration = get_object_or_404(Registration, registrant=user)
-    if registration.sponsor:
-        redirect_to = reverse('scipycon_account')
-        return set_message_cookie(redirect_to,
-                msg = u'You are a sponsored guest, no payment required.')
-    return render_to_response(template_name, RequestContext(request,
-        {'registration' : registration, 'user': user}))
-
-@login_required
-def pdf_invoice(request, scope, template_name='registration/invoice.html'):
-    user = request.user
-    registration = get_object_or_404(Registration, registrant=user)
-    if registration.sponsor:
-        redirect_to = reverse('scipycon_account')
-        return set_message_cookie(redirect_to,
-                msg = u'You are a sponsored guest, no payment required.')
-    content = render_to_string(template_name,
-        {'registration' : registration, 'user': user})
-    result = StringIO.StringIO()
-    import ho.pisa
-    pdf = ho.pisa.pisaDocument(StringIO.StringIO(content.encode("UTF-8")),result)
-    if not pdf.err:
-        return HttpResponse(result.getvalue(), mimetype='application/pdf')
-    return HttpResponse("Gremlins ate your invoice, please try html" \
-        " version")
-
-
-def registrations(request, scope,
-        template_name='registration/registrations.html'):
-    """Simple page to count registrations"""
-    #registrations = Registration.objects.filter(payment=True).count()
     registrations = Registration.objects.all().count()
-    return render_to_response(template_name, RequestContext(request,
-        {
+    return render_to_response(template_name, RequestContext(request, {
+        'params': {'scope': scope},
         'over_reg' : registrations >= REG_TOTAL and True or False,
-            'registrations' : registrations}))
+        'registrations' : registrations}))
 
 @login_required
 def edit_registration(request, scope, id,
-        template_name='registration/edit-registration.html'):
-    '''Allows users that submitted a registration to edit it.
-    '''
+                      template_name='registration/edit-registration.html'):
+    """Allows users that submitted a registration to edit it.
+    """
+
     reg = Registration.objects.get(pk=id)
 
     if reg.registrant != request.user:
-        redirect_to = reverse('scipycon_account')
-        return set_message_cookie(redirect_to,
-                msg = u'Redirected because the registration you selected' \
+        redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
+
+        return set_message_cookie(
+            redirect_to,
+            msg = u'Redirected because the registration you selected' \
                       + ' is not your own.')
 
     if request.method == 'POST':
@@ -172,10 +69,12 @@
             reg.tutorial = form.data.get('tutorial') and True or False
             reg.sprint = form.data.get('sprint') and True or False
             reg.save()
+
             # Saved.. redirect
-            redirect_to = reverse('scipycon_account')
+            redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
+
             return set_message_cookie(redirect_to,
-                    msg = u'Your changes have been saved.')
+                msg = u'Your changes have been saved.')
     else:
         form = RegistrationEditForm(initial={
                                     'id' : id,
@@ -196,10 +95,12 @@
 
 def submit_registration(request, scope,
         template_name='registration/submit-registration.html'):
-    '''Allows user to edit registration
-    '''
+    """Allows user to edit registration
+    """
+
     user = request.user
     reg_count = Registration.objects.all().count()
+
     if user.is_authenticated():
         try:
             profile = user.get_profile()
@@ -210,9 +111,10 @@
         try:
             registration = Registration.objects.get(registrant=user)
             if registration:
-                redirect_to = reverse('scipycon_account')
-                return set_message_cookie(redirect_to,
-                        msg = u'You have already been registered.')
+                redirect_to = reverse('scipycon_account',
+                                      kwargs={'scope': scope})
+                return set_message_cookie(
+                    redirect_to, msg = u'You have already been registered.')
 
         except ObjectDoesNotExist:
             pass
@@ -231,7 +133,8 @@
                 from django.contrib.auth import login
                 login(request, login_form.get_user())
 
-                redirect_to = reverse('scipycon_submit_registration')
+                redirect_to = reverse('scipycon_submit_registration',
+                                      kwargs={'scope': scope})
                 return set_message_cookie(redirect_to,
                         msg = u'You have been logged in please continue' + \
                                'with registration.')
@@ -248,7 +151,6 @@
                 from django.contrib.auth import authenticate
                 user = authenticate(username=newuser.username, password=passwd)
 
-                from django.contrib.auth import login
                 login(request, user)
 
                 newuser = user
@@ -258,19 +160,19 @@
 
         if registration_form.is_valid() and newuser:
             allow_contact = registration_form.data.get('allow_contact') and \
-                                        True or False
+                True or False
             conference = registration_form.data.get('conference') and \
-                                        True or False
+                True or False
             tutorial = registration_form.data.get('tutorial') and \
-                                        True or False
+                True or False
             sprint = registration_form.data.get('sprint') and \
-                                        True or False
+                True or False
 
             registrant = User.objects.get(pk=newuser.id)
 
             presenter = None
             talks = Talk.objects.filter(
-                    speaker=registrant).filter(approved=True)
+                speaker=registrant).filter(approved=True)
             if talks:
                 for talk in talks:
                     if talk.duration == '30':
@@ -294,7 +196,7 @@
 
             # get id and use as slug and invoice number
             id = reg.id
-            slug = 'KPC09%03d' % id
+            slug = 'SPYIN10%03d' % id
             reg.slug = slug
             reg.save()
 
@@ -309,7 +211,8 @@
             # 2. send user email with registration id
                 send_confirmation(registrant, slug)
 
-            redirect_to = reverse('scipycon_registrations')
+            redirect_to = reverse('scipycon_registrations',
+                                  kwargs={'scope': scope})
             return set_message_cookie(redirect_to,
                     msg = u'Thank you, your registration has been submitted '\
                            'and an email has been sent with payment details.')