added list statiscs page
authornishanth
Sat, 29 May 2010 19:35:49 +0530
changeset 25 30baf3c635c5
parent 24 f79be1dd4a22
child 26 212fcba4459e
child 28 1c2906cad944
added list statiscs page
sdi/forms.py
sdi/views.py
templates/list_stats.html
--- a/sdi/forms.py	Sat May 29 18:41:04 2010 +0530
+++ b/sdi/forms.py	Sat May 29 19:35:49 2010 +0530
@@ -61,14 +61,13 @@
 
         range_str = self.cleaned_data['knowledge_of_python'].strip()
         if not range_str:
-            return (1,5)
+            return ("","")
 
         start_stop = range_str.split("-")
 
         if len(start_stop) == 1:
             if start_stop[0].isdigit():
-                print "only one"
-                return (start_stop[0], 5)
+                return (start_stop[0], "")
             else:
                 raise forms.ValidationError("Invalid range for knowledge of Python")
 
@@ -88,14 +87,13 @@
 
         range_str = self.cleaned_data['knowledge_of_sage'].strip()
         if not range_str:
-            return (1,5)
+            return ("","")
 
         start_stop = range_str.split("-")
 
         if len(start_stop) == 1:
             if start_stop[0].isdigit():
-                print "only one"
-                return (start_stop[0], 5)
+                return (start_stop[0], "")
             else:
                 raise forms.ValidationError("Invalid range for knowledge of Sage")
 
@@ -115,14 +113,13 @@
 
         range_str = self.cleaned_data['likeliness_of_attending'].strip()
         if not range_str:
-            return (1,5)
+            return ("","")
 
         start_stop = range_str.split("-")
 
         if len(start_stop) == 1:
             if start_stop[0].isdigit():
-                print "only one"
-                return (start_stop[0], 5)
+                return (start_stop[0], "")
             else:
                 raise forms.ValidationError("Invalid range for Likeliness of attending the workshop")
 
--- a/sdi/views.py	Sat May 29 18:41:04 2010 +0530
+++ b/sdi/views.py	Sat May 29 19:35:49 2010 +0530
@@ -31,7 +31,40 @@
     if request.method == "POST":
         form = SearchForm(request.POST)
         if form.is_valid():
-            pass
+            data = form.cleaned_data
+            need_workshop = data['need_for_python_workshop']
+            db_query = "Registrant.objects.filter(need_for_python_workshop=%s)"%need_workshop
+
+            topics_include, topics_exclude = data['topics_interested']
+            for number in topics_include:
+                db_query += '.filter(topics_interested__contains="%s")'%number
+
+            for number in topics_exclude:
+                db_query += '.exclude(topics_interested__contains="%s")'%number
+
+            start_python, stop_python = data['knowledge_of_python']
+            if start_python and stop_python:
+                db_query += '.filter(knowledge_of_python__gte="%s")'%start_python
+                db_query += '.filter(knowledge_of_python__lte="%s")'%stop_python
+            elif start_python:
+                db_query += '.filter(knowledge_of_python__exact="%s")'%start_python
+
+            start_sage, stop_sage = data['knowledge_of_sage']
+            if start_sage and stop_sage:
+                db_query += '.filter(knowledge_of_sage__gte="%s")'%start_sage
+                db_query += '.filter(knowledge_of_sage__lte="%s")'%stop_sage
+            elif start_sage:
+                db_query += '.filter(knowledge_of_sage__exact="%s")'%start_sage
+
+            start_likeliness, stop_likeliness = data['likeliness_of_attending']
+            if start_likeliness and stop_likeliness:
+                db_query += '.filter(likeliness_of_attending__gte="%s")'%start_likeliness
+                db_query += '.filter(likeliness_of_attending__lte="%s")'%stop_likeliness
+            elif start_likeliness:
+                db_query += '.filter(likeliness_of_attending__exact="%s")'%start_likeliness
+
+            matches = eval(db_query)
+            return render_to_response("list_stats.html", {"form":form, 'matches':matches})
         else:
             return render_to_response("list_stats.html", {"form":form})
     else:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/list_stats.html	Sat May 29 19:35:49 2010 +0530
@@ -0,0 +1,42 @@
+<html>
+<body>
+<form action="" method="post">
+<!--
+Topics: <input name="topics" value=""{{topics}}> <br />
+Knowledge of Python: <input name="python_knowledge" value="{{python_knowledge}}"> <br />
+Knowledge of Sage: <input name="sage_knowledge" value="{{sage_knowledge}}"> <br />
+Likeliness of atttending: <input name="likeliness_of_attending" value="{{likeliness_of_attending}}"> <br />
+-->
+{{form.as_p}}
+<input type="submit" value="Search">
+</form>
+No.of candidates found: {{matches.count}}<br />
+<br />
+<table cellpadding=5 border=1>
+
+<tr>
+<td>Name</td>
+<td>E Mail</td>
+<td>Gender</td>
+<td>Profession</td>
+<td>Institution/Company</td>
+<td>Knowledge of other tools</td>
+<td>Phone Number</td>
+<td>Address</td>
+</tr>
+{% for user in matches %}
+	<tr>
+		<td>{{user.first_name.title}} {{user.last_name.title}}</td>
+		<td>{{user.email}}</td>
+		<td>{{user.gender}}</td>
+		<td>{{user.profession}}</td>
+		<td>{{user.affiliated_to}}</td>
+		<td>{{user.tools_used}}</td>
+		<td>{{user.phone_num}}</td>
+		<td>{{user.address|linebreaksbr}}</td>
+	</tr>
+{% endfor %}
+</table>
+
+</body>
+</html>