summaryrefslogtreecommitdiff
path: root/exam
diff options
context:
space:
mode:
authorPrabhu Ramachandran2011-11-21 15:46:54 +0530
committerPrabhu Ramachandran2011-11-21 15:46:54 +0530
commit4df6fb51be0661aaf0f852e4f2bedc2bb72e1eef (patch)
treefe5219e4f7a589c67b2fe2a595bef5aa94fcbb7a /exam
parent75c5904f27dc82d9445804aa5a9543dae40fcdf2 (diff)
downloadonline_test-4df6fb51be0661aaf0f852e4f2bedc2bb72e1eef.tar.gz
online_test-4df6fb51be0661aaf0f852e4f2bedc2bb72e1eef.tar.bz2
online_test-4df6fb51be0661aaf0f852e4f2bedc2bb72e1eef.zip
ENH: Adding dept/insti/pos fields in profile.
Adding institute/department/position fields, prettifying form with some help text. Also prettified monitor and user data. Updated commands to show/dump new fields.
Diffstat (limited to 'exam')
-rw-r--r--exam/forms.py24
-rw-r--r--exam/management/commands/dump_user_data.py3
-rw-r--r--exam/management/commands/results2csv.py5
-rw-r--r--exam/models.py4
-rw-r--r--exam/views.py5
5 files changed, 34 insertions, 7 deletions
diff --git a/exam/forms.py b/exam/forms.py
index cb2d37d..a5ca26f 100644
--- a/exam/forms.py
+++ b/exam/forms.py
@@ -11,13 +11,23 @@ PWD_CHARS = letters + punctuation + digits
class UserRegisterForm(forms.Form):
- username = forms.CharField(max_length=30)
+ username = forms.CharField(max_length=30,
+ help_text='Letters, digits, period and underscores only.')
email = forms.EmailField()
- password = forms.CharField(max_length=30, widget=forms.PasswordInput())
- confirm_password = forms.CharField(max_length=30, widget=forms.PasswordInput())
+ password = forms.CharField(max_length=30,
+ widget=forms.PasswordInput())
+ confirm_password = forms.CharField(max_length=30,
+ widget=forms.PasswordInput())
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
- roll_number = forms.CharField(max_length=30)
+ roll_number = forms.CharField(max_length=30,
+ help_text="Use a dummy if you don't have one.")
+ institute = forms.CharField(max_length=128,
+ help_text='Institute/Organization')
+ department = forms.CharField(max_length=64,
+ help_text='Department you work/study at')
+ position = forms.CharField(max_length=64,
+ help_text='Student/Faculty/Researcher/Industry/etc.')
def clean_username(self):
u_name = self.cleaned_data["username"]
@@ -59,8 +69,12 @@ class UserRegisterForm(forms.Form):
new_user.last_name = self.cleaned_data["last_name"]
new_user.save()
+ cleaned_data = self.cleaned_data
new_profile = Profile(user=new_user)
- new_profile.roll_number = self.cleaned_data["roll_number"]
+ new_profile.roll_number = cleaned_data["roll_number"]
+ new_profile.institute = cleaned_data["institute"]
+ new_profile.department = cleaned_data["department"]
+ new_profile.position = cleaned_data["position"]
new_profile.save()
return u_name, pwd
diff --git a/exam/management/commands/dump_user_data.py b/exam/management/commands/dump_user_data.py
index bd8f566..f14e144 100644
--- a/exam/management/commands/dump_user_data.py
+++ b/exam/management/commands/dump_user_data.py
@@ -14,6 +14,9 @@ Name: {{ user_data.name.title }}
Username: {{ user_data.username }}
Roll number: {{ user_data.rollno }}
Email: {{ user_data.email }}
+Position: {{ user_data.position }}
+Department: {{ user_data.department }}
+Institute: {{ user_data.institute }}
Date joined: {{ user_data.date_joined }}
Last login: {{ user_data.last_login }}
{% for paper in user_data.papers %}
diff --git a/exam/management/commands/results2csv.py b/exam/management/commands/results2csv.py
index 1adf442..f1da1a8 100644
--- a/exam/management/commands/results2csv.py
+++ b/exam/management/commands/results2csv.py
@@ -11,11 +11,12 @@ from exam.views import get_quiz_data
from exam.models import Quiz
result_template = Template('''\
-"name","username","rollno","email","answered","total","attempts"
+"name","username","rollno","email","answered","total","attempts","position","department","institute"
{% for paper in paper_list %}\
"{{ paper.name }}","{{ paper.username }}","{{ paper.rollno }}",\
"{{ paper.email }}","{{ paper.answered }}",{{ paper.total }},\
-{{ paper.attempts }}
+{{ paper.attempts }},"{{ paper.position }}",\
+"{{ paper.department }}","{{ paper.institute }}"
{% endfor %}\
''')
diff --git a/exam/models.py b/exam/models.py
index 8be87e4..09529b9 100644
--- a/exam/models.py
+++ b/exam/models.py
@@ -7,6 +7,10 @@ class Profile(models.Model):
"""Profile for a user to store roll number and other details."""
user = models.ForeignKey(User)
roll_number = models.CharField(max_length=20)
+ institute = models.CharField(max_length=128)
+ department = models.CharField(max_length=64)
+ position = models.CharField(max_length=64)
+
################################################################################
class Question(models.Model):
diff --git a/exam/views.py b/exam/views.py
index a998606..729b1e6 100644
--- a/exam/views.py
+++ b/exam/views.py
@@ -269,6 +269,7 @@ def get_quiz_data(quiz_id):
paper['name'] = user.get_full_name()
paper['username'] = user.username
paper['rollno'] = str(profile.roll_number)
+ paper['institute'] = str(profile.institute)
paper['email'] = user.email
qa = q_paper.questions_answered.split('|')
answered = ', '.join(sorted(qa))
@@ -343,6 +344,10 @@ def get_user_data(username):
data['email'] = user.email
data['rollno'] = profile.roll_number if profile else ''
data['name'] = user.get_full_name()
+ data['institute'] = profile.institute if profile else ''
+ data['department'] = profile.department if profile else ''
+ data['position'] = profile.position if profile else ''
+ data['name'] = user.get_full_name()
data['date_joined'] = str(user.date_joined)
data['last_login'] = str(user.last_login)
papers = []