From 904ce9b2e7a9d3f4ed6594b5bd14ce53cc296367 Mon Sep 17 00:00:00 2001 From: Primal Pappachan Date: Wed, 21 Mar 2012 13:32:27 +0530 Subject: Changed from radio buttons to drop down lists, added new field for insitute information and a preliminary version of the complete page --- allotter/forms.py | 12 ++++-- allotter/models.py | 8 ++++ allotter/urls.py | 2 +- allotter/views.py | 24 ++++++++---- template/allotter/apply.html | 81 ++++++++++++++++++++++++++++------------- template/allotter/complete.html | 14 ++++++- 6 files changed, 103 insertions(+), 38 deletions(-) diff --git a/allotter/forms.py b/allotter/forms.py index 8d4d021..980d3f7 100644 --- a/allotter/forms.py +++ b/allotter/forms.py @@ -23,11 +23,16 @@ class UserLoginForm(forms.Form): password = forms.CharField(label = "Application Number", max_length=10, help_text="As on your Examination ID Card") - dob = forms.DateField(label="Date of Birth", widget=SelectDateWidget(years=BIRTH_YEAR_CHOICES)) + dob = forms.DateField(label="Date of Birth", + widget=SelectDateWidget(years=BIRTH_YEAR_CHOICES), + initial=datetime.date.today) def clean_username(self): u_name = self.cleaned_data["username"] + if not u_name: + raise forms.ValidationError("Enter an username.") + ##Verifies whether username contains only digits and is not ##longer than 7, i.e Username == Registration Number. if str(u_name).strip(digits) or len(str(u_name)) != 7: @@ -43,6 +48,7 @@ class UserLoginForm(forms.Form): raise forms.ValidationError("Entered Registration Number haven't appeared for JAM Exam.") def clean_password(self): + pwd = self.cleaned_data['password'] ##Verifying the length of application number and whether it contains @@ -64,13 +70,13 @@ class UserLoginForm(forms.Form): if profile.dob != dob: raise forms.ValidationError("Date of Birth doesn't match.") except User.DoesNotExist: - raise forms.ValidationError("Verify the details entered.") + raise forms.ValidationError("Correct the following errors and try logging in again.") ##Authentication part user = authenticate(username = u_name, password = pwd) if not user: - raise forms.ValidationError("Invalid username/password") + raise forms.ValidationError("Application Number or Registration Number doesn't match.") return user diff --git a/allotter/models.py b/allotter/models.py index 0004505..77f0849 100644 --- a/allotter/models.py +++ b/allotter/models.py @@ -1,6 +1,10 @@ from django.db import models from django.contrib.auth.models import User +#email in profile +#course - place +#phone no(2) + ##EXAMINATION_SUBJECTS = ( ## ("Physics", "Physics"), ## ("Mathematics", "Mathematics"), @@ -64,6 +68,10 @@ class Option(models.Model): opt_code = models.IntegerField(max_length=3, verbose_name=u"Programme Code") + + opt_location = models.CharField(max_length=30, + verbose_name=u"Programme Location", + help_text=u"Offered by which IIT") exam = models.ManyToManyField(Exam) diff --git a/allotter/urls.py b/allotter/urls.py index aa0d62d..611fb88 100644 --- a/allotter/urls.py +++ b/allotter/urls.py @@ -5,7 +5,7 @@ urlpatterns = patterns('allotter.views', url(r'^logout/$', 'user_logout'), url(r'^apply/$', 'apply'), url(r'^(?P\w+)/submit/$', 'submit'), #change into numbers - url(r'^(?P\d+)/complete/$', 'complete'), #change into numbers + url(r'^(?P\w+)/complete/$', 'complete'), #change into numbers url(r'^$', 'apply'), #url(r'^quit/$', 'quit'), ) diff --git a/allotter/views.py b/allotter/views.py index 743c373..c9a5990 100644 --- a/allotter/views.py +++ b/allotter/views.py @@ -72,12 +72,14 @@ def get_details(user, error_message = ""): 'options_available_first' : options_available_first, 'second_paper': second_paper, 'options_available_second' : options_available_second, - 'np' : np,'oafl': oafl, 'oasl': oasl, + 'np' : np, 'oafl_range': range(1, oafl + 1, 1), + 'oasl_range': range(oafl, oafl + oasl, 1), 'error_message': error_message} else: #If written only one exam context = {'user': user, 'first_paper': first_paper, 'options_available_first' : options_available_first, - 'oafl': oafl, 'np' : np, 'error_message' : error_message} + 'oafl_range': range(1, oafl + 1, 1), + 'np' : np, 'error_message' : error_message} return context @login_required @@ -110,7 +112,7 @@ def submit(request, reg_no): for option in options_available_first: #TODO: Dealing with none option, Dealing with all nones - selected_option = Option.objects.get(pk=request.POST[option.opt_name]) + option_pref = request.POST[option.opt_name] #except (KeyError, Option.DoesNotExist): # Redisplay the application form with error message. # error_message = "You didn't select a choice." @@ -119,8 +121,8 @@ def submit(request, reg_no): # context_instance=RequestContext(request)) #else: - options_list += selected_option.opt_name - + options_list += option_pref + "-" + str(option.opt_code) + "," + user_application.options_selected += options_list user_application.save() return HttpResponseRedirect(reverse('allotter.views.complete', args=(reg_no,))) @@ -129,10 +131,16 @@ def submit(request, reg_no): #User Application def complete(request, reg_no): - - context = {'user': reg_no} + user = get_object_or_404(User, username=reg_no) + email = user.email + user_profile = user.get_profile() + user_application = user_profile.application + first_paper = user_application.first_paper #First Paper Name + options_available_first = Option.objects.filter(exam__exam_name=first_paper).distinct() #Options for First paper + context = {'user': reg_no, 'email': email, 'first_paper': first_paper, + 'options_available_first': options_available_first} ci = RequestContext(request) - return render_to_response('allotter/complete.html', context) + return render_to_response('allotter/complete.html', context, context_instance=ci) """def quit(request): pass diff --git a/template/allotter/apply.html b/template/allotter/apply.html index e1c728d..a336306 100644 --- a/template/allotter/apply.html +++ b/template/allotter/apply.html @@ -2,18 +2,18 @@ {% load range_filter %} -{% block title %}Application form {% endblock %} +{% block title %} Application form {% endblock %} {% block content %} -

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

+

Welcome to JAM 2012 allotment!

-

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

+

Read the following instructions carefully before continuing.

+
Choose the options as per your preference -

You are in the merit list for {{first_paper}} +

You are eligible for {{first_paper}} {% comment %} Checking if there is second paper and displaying its name. @@ -30,46 +30,77 @@ and {{second_paper}}

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

-

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.

+

Preferences will be assigned to options 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 %} +

Options available for {{first_paper}}

+ {% if error_message %}

{{ error_message }}

{% endif %}
{% csrf_token %} -{% for option in options_available_first %} -

{{ option.opt_name }}

- {% for i in oafl|get_range %} -
+ + + + + + + + +{% for option in options_available_first %} + + + + + + {% endfor %} - -{% comment %} -Listing the options for second test paper if it exists. -{% endcomment %} - +

Programme Code

Programme Name

Insitute

Preference

{{ option.opt_code }}

{{option.opt_name }}

{{option.opt_location }}

None
+ + +
{% if np == 2 %} -{% for option in options_available_second %} -

{{ option.opt_name }}

- {% for i in oafl|get_range %} -
+

Options available for {{second_paper}}

+ + + + + + + + + +{% for option in options_available_second %} + + + + + + +{% endfor %} +

Programme Code

Programme Name

Insitute

Preference

{{option.opt_code }}

{{option.opt_name }}

{{option.opt_location }}

None
-{% endfor %} + + +
{% endif %} -
diff --git a/template/allotter/complete.html b/template/allotter/complete.html index 1759c30..e235772 100644 --- a/template/allotter/complete.html +++ b/template/allotter/complete.html @@ -5,7 +5,19 @@ {% block content %} -

Thank you, your options have been saved to the database

+

Thank you, your following options have been saved to the database

+ +{{first_paper}} + +{% for option in options_available_first %} +

{{ option.opt_name }}

+{% endfor %} + +{% if email %} + +An email with all the options has been to the following email address: {{email}} + +{% endif %} {% endblock content %} -- cgit