Added custom view for looking at registrants yAy.
authorShantanu <shantanu@fossee.in>
Mon, 25 Jan 2010 01:20:43 +0530
changeset 12 10d86ada90c2
parent 11 ae643a9734f3
child 13 2ef7b964dda3
Added custom view for looking at registrants yAy.
upload/admin.py
upload/views.py
upload/workshops.py
urls.py
--- a/upload/admin.py	Sun Jan 24 14:58:51 2010 +0530
+++ b/upload/admin.py	Mon Jan 25 01:20:43 2010 +0530
@@ -8,3 +8,4 @@
 
 admin.site.register(Participant, ParticipantAdmin)
 
+
--- a/upload/views.py	Sun Jan 24 14:58:51 2010 +0530
+++ b/upload/views.py	Mon Jan 25 01:20:43 2010 +0530
@@ -2,11 +2,12 @@
 from django.http import HttpResponse
 from django.template import Context, Template
 from django.shortcuts import render_to_response
+from django.contrib.auth.decorators import login_required
 
 from forms import ParticipantForm
 from models import Participant
 
-def upload_file(request, template_name='index.html'):
+def register_user(request, template_name='index.html'):
     if request.method == 'POST':
         form = ParticipantForm(request.POST, request.FILES)		
         if form.is_valid():            
@@ -16,3 +17,26 @@
             return render_to_response(template_name, {'form': form, 'value': True,})
     return render_to_response(template_name,
 			  {'form': ParticipantForm(), 'value': True})
+
+#@login_required
+def view_registrants(request, template_name='registrants.html'):
+    """
+    View to return list of registered participants
+    """
+    ##wow what a one liner
+    poc = dict([line.strip().split('|') for line in open('upload/poc')])        
+    if not request.user.is_authenticated():
+        return HttpResponse("You can't view these details.")
+    context_registrants = []
+
+    registrations = Participant.objects.all()
+    for registrant in registrations:
+        if poc[request.user.username] == registrant.workshop:
+            context_registrants.append({
+                'registrant':registrant,
+                })
+    context = {
+        'registrants':context_registrants,
+        }
+    return render_to_response(template_name, context)
+    
--- a/upload/workshops.py	Sun Jan 24 14:58:51 2010 +0530
+++ b/upload/workshops.py	Mon Jan 25 01:20:43 2010 +0530
@@ -18,7 +18,7 @@
     for event in parsedCal.components():
         eventDate = event.dtstart.value.date()
 	daysLeft = eventDate - date.today()
-	if daysLeft.days > 3 and daysLeft.days < 31:
+	if daysLeft.days > -1 and daysLeft.days < 31:
             eventList += (tuple((event.summary.value,event.summary.value)),)    
     return tuple(eventList)
 
--- a/urls.py	Sun Jan 24 14:58:51 2010 +0530
+++ b/urls.py	Mon Jan 25 01:20:43 2010 +0530
@@ -19,8 +19,8 @@
 
     # Uncomment the next line to enable the admin:
         (r'^admin/(.*)', admin.site.root),
-	(r'^$','ws_reg.upload.views.upload_file'),
+	(r'^$','ws_reg.upload.views.register_user'),
+        (r'^list/$','upload.views.view_registrants'),
         (r'^captcha/', include('captcha.urls')), 	
-        (r'^databrowse/(.*)',databrowse.site.root),        
-	(r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT }),
+        (r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT }),
 )