Permalink
Browse files

可以运行了则个!

todo next:
1.用户登录验证,注册处理等
2.界面调整
3.其他问题,如支持单选题目和多选题目

2011年 11月 27日 星期日 16:29:58 CST
  • Loading branch information...
1 parent 70629ee commit 0eb73854efe389804d572d098a98e6508090309a guohh committed Nov 27, 2011
View
@@ -27,7 +27,8 @@ def __unicode__(self):
def get_answer_choice(self):
return self.answer_set.all()
-
+ def get_right_answer(self):
+ return self.answer_set.filter(isRight=True)
class Answer(models.Model):
@@ -47,5 +48,7 @@ class Record(models.Model):
def __unicode__(self):
return "result:%d @ %s " % (self.result , self.pub_date)
+ def get_time(self):
+ return "%s:%s:%s" % (self.pub_date.hour,self.pub_date.minute,self.pub_date.second)
@@ -43,18 +43,22 @@ a:hover
}
/**** seting & size --***/
.mainBox {
- margin-left: auto;
+ background:url(../images/top_bg.gif) repeat scroll 0 0 transparent;
+ margin-left: auto;
margin-right: auto;
width: 930px;
display:block;
}
.header {
- background: none repeat scroll 0 0 #EEEEEE;
+ /*background: none repeat scroll 0 0 #EEEEEE;*/
display:block;
width: 100%;
- height: 80px;
+ height: 85px;
}
+.header h1 {
+ color:white;
+ }
.content {
width: 590px;
float:left;
@@ -104,3 +108,67 @@ body {
padding:10px;
text-align:center;
}
+/**** Main Menu ***/
+
+
+#menu {
+ display: block;
+ float:right;
+ margin-top:15px;
+}
+
+#menu ul {
+ margin: 0;
+ list-style: none;
+}
+
+#menu li {
+ display: block;
+ float: left;
+ white-space: nowrap;
+}
+
+#menu li a {
+ display: inline;
+ padding: 55px 20px 12px 20px;
+ text-decoration: none;
+ color: #fff;
+ font-weight: bold;
+}
+
+* html #menu a {width:1%;}
+
+#menu li a:hover {
+ background: url(../images/bg_menu.gif);
+ color:#0089ff;
+
+}
+
+#menu li a.current {
+ letter-spacing: 1px;
+ color: gray;
+ background: url(../images/bg_menu.gif);
+}
+
+#menu li a.normal {
+ letter-spacing:1px;
+}
+
+#menu li a.current:hover {
+ color: #fff;
+}
+
+/*** for quiz-result ***/
+.w-question-box
+{
+ color:red;
+}
+.r-answer {
+ color:#93b333;
+ display:block;
+ background:#3e3e3e;
+}
+.w-list {
+ display:block;
+ background:#3e3e3e;
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,8 +1,9 @@
+#coding=utf-8
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from question.models import *
-
+from datetime import datetime
def show_question_by_id(request,q_id):
obj = ''
try:
@@ -15,21 +16,78 @@ def show_question_by_id(request,q_id):
def show_all_questions(request):
obj_list = []
try:
- obj_list = Question.objects.all()
+ obj_list = Question.objects.all().order_by('-id')
except:
pass
variables = RequestContext(request,{'obj_list':obj_list})
return render_to_response("q_all.html",variables)
def quiz_create(requset):
+ obj_list = []
+ isCreated = False;
+ quiz_info=""
if requset.method == "POST":
level = requset.POST['level']
class_type = requset.POST['class_type']
q_num = requset.POST['q_num']
- if( level && class_type && q_num ):
+ if( level and class_type and q_num ):
## create a quiz with q_num questions.
- obj_list = []
- variables = RequestContext(requset,{'obj_list':obj_list})
- return render_to_response("quiz.html",variables)
- return HttpResponseRedirect("/create_quiz/")
+ isCreated = True
+ _class=""
+
+ if(class_type=="e"):
+ _class=u'容易'
+ elif ( class_type=="m"):
+ _class=u'中等'
+ elif (class_type=="h"):
+ _class=u'困难'
+
+ quiz_info = u'考试等级:%s, 难度:%s, 题目数目:%s' % (level,_class,q_num)
+ ## obj_list - generate here.
+ ## just for test
+ obj_list = Question.objects.all().filter(level=level,class_type=class_type);
+ variables = RequestContext(requset,{'obj_list':obj_list,'isCreated':isCreated,'quiz_info':quiz_info})
+ return render_to_response("quiz-create.html",variables)
+def quiz(request):
+ result = 0
+ r_count = 0
+ w_count = 0
+ w_obj_list = []
+ user = request.user
+ if request.method == "POST":
+ info = request.POST
+ for q in info:
+ tmp = []
+ try:
+ tmp = Question.objects.get(id=q)
+ ### 目前仅支持单选类别,未来需要加上判断题目类型,如果
+ ### 是多选则进行for循环依次判断答案是否正确
+ if ( info[q] == str(tmp.get_right_answer()[0].id) ):
+ r_count += 1
+ else:
+ w_count += 1
+ w_obj_list.append(tmp)
+ except:
+ pass
+
+ if(r_count+w_count):
+ result = 100*r_count/(r_count + w_count)
+ record = Record(user=user,pub_date=datetime.now(),result=result,notes="",)
+ record.save()
+ for w_q in w_obj_list:
+ record.wrong_question.add(w_q)
+ record.save()
+
+ variables = RequestContext(request,{
+ 'result':result,
+ 'r_count':r_count,
+ 'w_count':w_count,
+ 'w_obj_list':w_obj_list,})
+ return render_to_response("quiz.html",variables)
+
+def show_record(request):
+ user = request.user
+ obj_list = Record.objects.all().order_by('-id')
+ variables = RequestContext(request,{'obj_list':obj_list})
+ return render_to_response("record.html",variables)
View
@@ -13,6 +13,15 @@
<div id="main-box" class="mainBox">
<div id="header" class="header">
<h1 id="branding" ><a href="/">iQuiz </a> | {% block _title %} {% endblock %}</h1>
+ <div id="menu" >
+ <ul>
+ <li> <a href="/">首页</a> </li>
+ <li> <a href="/qall/">问题</a> </li>
+ <li> <a href="/quiz/create/">测试</a> </li>
+ <li> <a href="/record/">记录</a> </li>
+ <li> <a href="/help/">帮助</a> </li>
+ </ul>
+ </div>
</div>
<div id="content" class="content">
{% block content %}
@@ -39,8 +48,16 @@ <h2>Navigation</h2>
<a href="/qall/">问题</a>
</li>
<li id="main-nav-quiz">
- <a href="/create_quiz/">进入测试</a>
+ <a href="/quiz/create/">进入测试</a>
</li>
+ <li id="main-nav-record">
+ <a href="/record/">记录</a>
+ </li>
+ <li id="main-nav-help">
+ <a href="/help/">帮助</a>
+ </li>
+
+
</ul>
<h2>留言/评论</h2>
View
@@ -0,0 +1,24 @@
+{% extends "base.html" %}
+{% block title %} 帮助{% endblock %}
+
+{% block _title %} 使用帮助 {% endblock %}
+
+
+{% block content %}
+<h2>使用帮助</h2>
+
+欢迎使用本考试系统iQuiz!
+<p>
+1.如何开始测试?</p>
+<p>
+点击导航链接中的 <a href="/quiz/create/">测试</a> , 选择测试的等级、难度、以及考试题目数目,就可以开始考试了。
+</p>
+<p>
+2.如何查看测试的记录?</p>
+<p>
+如上打开链接 <a href="/record/">记录</a> ,就可以查看自己曾经的测试成绩,还可以查看每次测试中的错误题目。
+</p>
+
+{% endblock %}
+
+
@@ -1,15 +1,4 @@
-{% extends "base.html" %}
-{% block title %} Question {{ obj.id }} {{ obj }} {% endblock %}
-{% block _title %} Question {{ obj.id }} <br/> {{ obj }} {% endblock %}
-
-{% block content %}
-<h2 > 请选择答案</h2>
-
-<form action="" method="post"> {% csrf_token %}
+{{ obj }} <br/>
{% for answer in obj.answer_set.all %}
- <input type="radio" name="a_id" value="{{ answer.id }}"> {{ answer }} <br/>
+<input type="radio" name="{{ obj.id }}" value="{{ answer.id }}">{{ answer }} <br/>
{% endfor %}
-<input type="submit" value="提交答案" />
-</form>
-
-{% endblock %}
@@ -4,22 +4,35 @@
{% block _title %} 制作考卷 {% endblock %}
{% block content %}
+{% if isCreated %}
+<h2>{{ quiz_info }}</h2>
+<div class="quiz-test">
+ <form action="/quiz/" method="post"> {% csrf_token %}
+ <ol>
+ {% for obj in obj_list %}
+ <li>{% include "question.html" %}</li>
+ {% endfor %}
+ </ol>
+ <input type="submit" value="答完了,交卷!">
+ </form>
+</div>
+{% else %}
<div class="quiz-create" >
-<form action="" method="post"> {% csrf_token %}
+<form action="." method="post"> {% csrf_token %}
<fieldset>
<legend>制作何种试卷?</legend>
<label for="level"> 等级&nbsp;&nbsp; </label>
<select name="level" >
- <option>等级1</option>
- <option>等级2</option>
- <option>等级3</option>
+ <option value="1">等级1</option>
+ <option value="2">等级2</option>
+ <option value="3">等级3</option>
</select>
<br/><br/>
<label for="class_type"> 难易 &nbsp;&nbsp; </label>
<select name="class_type">
- <option>容易</option>
- <option>中等</option>
- <option>困难</option>
+ <option value="e">容易</option>
+ <option value="m">中等</option>
+ <option value="h">困难</option>
</select>
<br/><br/>
<label for="q_num"> 数量 &nbsp;&nbsp; </label>
@@ -34,4 +47,5 @@
</fieldset>
</form>
</div>
+{% endif %}
{% endblock %}
View
@@ -1,4 +1,27 @@
{% extends "base.html" %}
+{% block title %}考试成绩{% endblock %}
+{% block _title %}考试成绩{% endblock %}
+
+{% block content %}
+<h2>Hi <a href="/p/{{ user }}">{{ user.username }}</a> ,这是您的考试成绩: {{ result }}</h2>
+正确:{{ r_count }}个<br/>
+错误:{{ w_count }}个<br/>
+<a href="/record/">查看考试记录</a>
+{% if w_count %}
+<hr/>
+ 错误题目:
+ <div class="w-question-box">
+ <ol>
+ {% for obj in w_obj_list %}
+ <li>{{ obj }}</li>
+ <div class="r-answer"> 正确答案 : {% for r in obj.get_right_answer %} {{ r.title }}&nbsp;&nbsp; {% endfor %} <br/>
+ {{ obj.description }}<br/>
+ </div>
+ {% endfor%}
+ </ol>
+ </div>
+{% endif %}
+{% endblock %}
View
@@ -0,0 +1,23 @@
+{% extends "base.html" %}
+{% block title %} 考试记录 {% endblock %}
+{% block _title %} 考试记录 {% endblock %}
+
+{% block content %}
+ <ul>
+ {% for obj in obj_list %}
+ <li> {{ obj.pub_date|date:"Y-m-d"}} {{ obj.get_time }}<br/>
+ 得分:{{ obj.result }} <br/>
+ 笔记:{{ obj.notes }} </li>
+ 错误问题:
+ <div class="w-list">
+
+ <ol>
+ {% for w in obj.wrong_question.all %}
+ <li><a href="/q/{{ w.id }}">{{ w }}</a></li>
+ {% endfor %}
+ </ol>
+ </div>
+ <hr/>
+ {% endfor %}
+ </ul>
+{% endblock %}
Oops, something went wrong.

0 comments on commit 0eb7385

Please sign in to comment.