From 2c97aecefd592649e88f5ace6ed39ef98f93089d Mon Sep 17 00:00:00 2001 From: Primal Pappachan Date: Fri, 16 Mar 2012 19:06:37 +0530 Subject: added the options listing page --- allotter/urls.py | 1 + allotter/views.py | 70 +++++++++++++++++++++++++++++--------------- template/allotter/apply.html | 59 ++++++++++++++++++++++++++++++++----- 3 files changed, 98 insertions(+), 32 deletions(-) diff --git a/allotter/urls.py b/allotter/urls.py index e0c7c7b..6238e3c 100644 --- a/allotter/urls.py +++ b/allotter/urls.py @@ -2,6 +2,7 @@ from django.conf.urls.defaults import patterns, url urlpatterns = patterns('allotter.views', url(r'^login/$', 'user_login'), + url(r'^apply/$', 'apply'), #url(r'^apply/$', 'apply'), #url(r'^submit/$', 'submit'), #url(r'^quit/$', 'quit'), diff --git a/allotter/views.py b/allotter/views.py index a63873f..abfec2e 100644 --- a/allotter/views.py +++ b/allotter/views.py @@ -31,6 +31,52 @@ def user_login(request): context = {"form": form} return render_to_response('allotter/login.html', context, context_instance=RequestContext(request)) + + +@login_required +def apply(request): + user = request.user + if not(user.is_authenticated()): + return redirect('/allotter/login/') + user_profile = user.get_profile() + user_application = user_profile.application + np = user_application.np #Number of Papers + first_paper = user_application.first_paper + options_available_first = Option.objects.filter(exam__exam_name=first_paper).distinct() + oafl = len(options_available_first) + if np == 2: + second_paper = user_application.second_paper + options_available_second = Option.objects.filter(exam__exam_name=second_paper).distinct() + oasl = len(options_available_second) + context = {'user': user, 'first_paper': first_paper, + 'options_available_first' : options_available_first,'np' : np, + 'oafl': oafl, 'oasl': oasl, 'second_paper': second_paper, + 'options_available_second' : options_available_second} + ci = RequestContext(request) + return render_to_response('allotter/apply.html', context, + context_instance=ci) + + #form = ApplicationForm(logged_user=user) + context = {'user': user, 'first_paper': first_paper, + 'options_available_first' : options_available_first, + 'oafl': oafl, 'np' : np} + ci = RequestContext(request) + return render_to_response('allotter/apply.html', context, + context_instance=ci) + + +""" +def submit(request): + pass + +def quit(request): + pass + +def user_logout(request): + logout(request) + return redirect ('/allotter/') + +""" """def user_register(request): Register a new user. @@ -62,27 +108,3 @@ def user_login(request): """ -"""@login_required -def apply(request): - user = request.user - if not(user.is_authenticated()): - return redirect('/allotter/login/') - user_profile = user.get_profile() - subject = user_profile.exam_code - options_available = Option.objects.filter(exam__exam_name=subject).distinct() - #form = ApplicationForm(logged_user=user) - context = {'user': user, 'subject': subject, - 'options' : options_available} - ci = RequestContext(request) - return render_to_response('allotter/apply.html', context, - context_instance=ci) - -def submit(request): - pass - -def quit(request): - pass - -def user_logout(request): - logout(request) - return redirect ('/allotter/')""" diff --git a/template/allotter/apply.html b/template/allotter/apply.html index 72c96c3..ca03726 100644 --- a/template/allotter/apply.html +++ b/template/allotter/apply.html @@ -1,34 +1,77 @@ {% extends "base.html" %} +{% load range_filter %} + {% block title %}Application form {% endblock %} {% block content %} -

Hello, there

+

Thank you for providing the details. You have been authenticated.

Welcome {{user.first_name.title}} {{user.last_name.title}}, to JAM 2012 allotment!

Choose the options as per your preference -

{{user.first_name}} {{user.last_name}} {{user.user_name}}

+

You are in the merit list for {{first_paper}} + +{% comment %} +Checking if there is second paper and displaying its name. +{% endcomment %} + +{% if np == 2 %} + +and {{second_paper}} + +{% endif %} + +

+ +

For the paper(s) in which you are in the merit list, the following +options are available to you. Please rank your choices.

-

{{subject}}

+

Options will be given preference in the ascending order. Make sure it's +None for all options after your last option so that it is not considered.

+ +

Number of Options {{ oafl }} Number of subjects {{np}}

+ +{% comment %} +Listing the options for first test paper. +{% endcomment %}
{% csrf_token %} -{% for option in options %} -{{option.opt_name}}
+{% for option in options_available_first %} +

{{ option.opt_name }}

+ {% for i in oafl|get_range %} + {{i}}
+ {% endfor %} + None
{% endfor %} +{% comment %} +Listing the options for second test paper if it exists. +{% endcomment %} + +{% if np == 2 %} + +{% for option in options_available_second %} +

{{ option.opt_name }}

+ {% for i in oafl|get_range %} + {{i}}
+ {% endfor %} + None
+{% endfor %} + +{% endif %} +
-
+ {% csrf_token %} - +
-Logout {% endblock content %} -- cgit