Skip to content

Commit

Permalink
hist exam
Browse files Browse the repository at this point in the history
  • Loading branch information
snakeqing23 committed Jul 14, 2012
1 parent e16c68b commit 5db4842
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/etraining/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class EmployeeTrainingRecord(models.Model):
attend_date = models.DateField(blank=True, null=True)
score = models.IntegerField(blank=True, null=True)
admin = models.ForeignKey(User, blank=True, null=True)
exam_result = models.CharField(max_length=500, blank=True, null=True)

def __unicode__(self):
return self.training+'|'+self.employee
Expand Down Expand Up @@ -210,6 +211,7 @@ class NonemployeeTrainingRecord(models.Model):
attend_date = models.DateField(blank=True, null=True)
score = models.IntegerField(blank=True, null=True)
admin = models.ForeignKey(User, blank=True, null=True)
exam_result = models.CharField(max_length=500, blank=True, null=True)

objects = models.Manager()
entrance_trainings = EntranceTrainingManager()
Expand Down
1 change: 1 addition & 0 deletions src/etraining/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
url(r'^self_search/$', 'self_search', name='self_search'),
url(r'^self_training/(?P<training_id>\d+)/$', 'self_training', name='self_training'),
url(r'^self_examination/(?P<is_employee>\d+)/(?P<record_id>\d+)/$', 'self_examination', name='self_examination'),
url(r'^hist_exam/(?P<is_employee>\d+)/(?P<record_id>\d+)/$', 'hist_exam', name='hist_exam'),
)
29 changes: 28 additions & 1 deletion src/etraining/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from etraining.models import Choice, Question, QuestionType, Document, Training, IsConfirmAvailable
from etraining.models import Employee, EmployeeTrainingRecord, NonemployeeRegistration, NonemployeeTrainingRecord, Group
from etraining.admin_forms import NonemployeeRegistrationForm, EmployeeRegistrationForm
import datetime, sys, random
import datetime, sys, random, json

def index(request):
return HttpResponseRedirect(reverse("self_search"))
Expand Down Expand Up @@ -110,6 +110,30 @@ def self_training(request, training_id):
"audio_clip": training.document.audio_clip,
}, context_instance=RequestContext(request))

def hist_exam(request, is_employee, record_id):
if int(is_employee):
record = EmployeeTrainingRecord.objects.get(pk=record_id)
else:
record = NonemployeeTrainingRecord.objects.get(pk=record_id)

score = record.score
isPass = (score >= record.training.pass_criteria)
exam_result = json.loads(record.exam_result)
qids = []
for qid in exam_result:
qids.append(int(qid))

questions = Question.objects.filter(id__in=qids)
for question in questions:
question.user_answer = exam_result[str(question.id)]
return render_to_response("etraining/hist_exam.html", {
'score' : score,
'pass' : isPass,
'exam_result' : exam_result,
'questions' : questions,
}, context_instance=RequestContext(request))


def self_examination(request, is_employee, record_id):
if int(is_employee):
record = EmployeeTrainingRecord.objects.get(pk=record_id)
Expand All @@ -126,9 +150,11 @@ def self_examination(request, is_employee, record_id):
session['answers'][session['cur_qid']]=answer
if action == 'finish':
wrongCount = 0
qamap = {}
for qid in session['answers']:
question = session['questions'][qid]
answer = session['answers'][qid]
qamap[question.id] = answer
try:
choice = question.choice_set.get(id=answer)
except Choice.DoesNotExist:
Expand All @@ -140,6 +166,7 @@ def self_examination(request, is_employee, record_id):
wrongCount += 1
score = len(session['questions'])-wrongCount
record.score = score
record.exam_result = json.dumps(qamap)
record.save()

isPass = (score >= record.training.pass_criteria)
Expand Down
23 changes: 23 additions & 0 deletions src/templates/etraining/hist_exam.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "etraining/base_etraining.html" %}
{% load i18n %}

{% block content %}
<div class="content clearfix">
<div class="content_title">{% trans "Employment Training Exam" %}</div>
<div class="test_result_summary">该次考试分数为:{{ score }}, 结果: {% if pass %}通过{% else %}未通过{% endif %}</div>
<div class="questions">
{% for question in questions %}
<div class="question">
<div class="question_body">{{question.id}}. {{question.content}}</div>
<div class="choices">
{% for choice in question.choice_set.all %}
<div class="choice {% if question.user_answer == choice.id %}{% if choice.is_answer %}green{% else %}red{% endif %}{% endif %}">
<input type="radio" disabled name="{{choice.id}}" {% if question.user_answer == choice.id %}checked{% endif %} value="{{choice.id}}" />{{choice.text}}
</div>
{% endfor %}
</div>
</div>
<br>
{% endfor %}
</div>
{% endblock %}

0 comments on commit 5db4842

Please sign in to comment.