from django.shortcuts import render,HttpResponse
import docx
from django.db import transaction
from CollectTestpaper import models
# Create your views here.
def test(request):
if request.method == 'GET':
x = request.POST.get('lala');
return render(request, 'test.html')
else:
global files;
x_get = request.FILES.get('上传的文件')
try:
files = docx.Document(x_get)
except Exception as e:
return HttpResponse("插入失败:上传试卷类型有误!清仔细检查!")
# testChoice()#获取选择题
# testJudge()#获取判断题
# testInput()#获取填空题
# getTitle()#获取试卷名
'''首先,获取试卷中的各项内容
接下来,将各项内容录入数据库
首先应该是试卷名的录入'''
titleString = getTitle()
choiceList = testChoice()
judgeList = testJudge()
inputList = testInput()
Hard = request.POST.get("Hard")#读取试卷难度
Apply_time = request.POST.get("Apply_time")#读取出卷时间
Intro = request.POST.get("Intro")
try:
save_id_testpaper = transaction.savepoint()
'''插入试卷'''
if x_get == None:
raise Exception("请先上传文件!")
if models.Testpaper.objects.filter(name=titleString).exists():
raise Exception("试卷已存在!")
models.Testpaper.objects.create(name=titleString, hard=Hard, apply_time=Apply_time, intro=Intro)#Successful for test!
'''接下来插入判断题'''
for i in judgeList:
for j in i.items():
models.Question.objects.create(stems=j[1][0], level=2)#Successful for test!
models.TrueOrFalse.objects.create(
question_id=models.Question.objects.filter(stems=j[1][0]).first(),
standard_answer=j[1][1],
)
models.TestpaperQuestion.objects.create(#插入试题_试卷对应表
testpaper_id=models.Testpaper.objects.filter(name=titleString).first(),
question_id=models.Question.objects.filter(stems=j[1][0]).first()
)
'''接下来插入填空题'''
for i in inputList:
for j in i.items():
models.Question.objects.create(stems=j[1][0], level=3)#Successful for test!
models.Gapfill.objects.create(
question_id=models.Question.objects.filter(stems=j[1][0]).first(),
standard_answer=j[1][1],
)
models.TestpaperQuestion.objects.create(#插入试题_试卷对应表
testpaper_id=models.Testpaper.objects.filter(name=titleString).first(),
question_id=models.Question.objects.filter(stems=j[1][0]).first()
)
'''接下来插入选择题'''
for i in choiceList:
for j in i.items():
models.Question.objects.create(stems=j[1][0], level=1)#插入试题表
models.Choice.objects.create(#选项插入
question_id=models.Question.objects.filter(stems=j[1][0]).first(),
choice1=j[1][2],
choice2=j[1][3],
choice3=j[1][4],
choice4=j[1][5],
standard_answer=j[1][1],
)
models.TestpaperQuestion.objects.create(#插入试题_试卷对应表
testpaper_id=models.Testpaper.objects.filter(name=titleString).first(),
question_id=models.Question.objects.filter(stems=j[1][0]).first()
)
transaction.savepoint_commit(save_id_testpaper)
except Exception as e:
transaction.savepoint_rollback(save_id_testpaper)
return HttpResponse("插入失败:" + str(e))
return render(request, 'testSuccessful.html')
def testChoice():
choiceList = []#选择题总容器
k = 0
line = 0
op = 0
for i in files.paragraphs:
if i.style.name == "Heading 2":
if i.text == "选择题":
A = 0
B = 0
C = 0
D = 0
op = 0
k = 1
continue
elif i.style.name == "Heading 2":
break
if op == 0:
choiceDict = dict() # 单个选择题容器字典
question_answer = [] # 存储题干和标准答案
if k == 1:
t = i.text
try:
t.index("题干:")
# print(line)
# print(t[3:])#此为题干
try:
rt = t.index("【")
except Exception as e:
print("未识别到答案")
else:
question_answer.append(t[3:rt]) # 将题干存储入结构
question_answer.append(t[rt+1:-1])#将答案存储入结构
op = 1
line += 1
# question_answer.append(t[3:]) # 将题干存储入结构
# op = 1
# line += 1
except Exception as e:#选择题中,识别不到题干二字的段落必然是选项,故异常处理需要将本次内容记录,并将下一次读入合并,再进行识别选项
# print(t)
if A == 0:
try:
a_index = t.index("A.")
except Exception as e:
A = 0
continue
else:
A = 1
try:
b_index = t.index("B.")
except Exception as e:
B = 0
str_A = t[a_index+2:]
else:
B = 1
str_A = t[a_index+2:b_index]
try:
c_index = t.index("C.")
except Exception as e:
C = 0
str_B = t[b_index+2:]
else:
C = 1
str_B = t[b_index+2:c_index]
try:
d_index = t.index("D.")
except Exception as e:
D = 0
str_C = t[c_index+2:]
else:
D = 1
str_C = t[c_index+2:d_index]
str_D = t[d_index+2:]
# print(str_A + '\n') # 此为选项A
# print(str_B + '\n') # 此为选项B
# print(str_C + '\n') # 此为选项C
# print(str_D + '\n') # 此为选项D
question_answer.append(str_A)
question_answer.append(str_B)
question_answer.append(str_C)
question_answer.append(str_D)
choiceDict[line] = question_answer # 存储入单个题目容器
choiceList.append(choiceDict) # 存储入总容器
A = 0
B = 0
C = 0
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
管理系统是一种通过计算机技术实现的用于组织、监控和控制各种活动的软件系统。这些系统通常被设计用来提高效率、减少错误、加强安全性,同时提供数据和信息支持。以下是一些常见类型的管理系统: 学校管理系统: 用于学校或教育机构的学生信息、教职员工信息、课程管理、成绩记录、考勤管理等。学校管理系统帮助提高学校的组织效率和信息管理水平。 人力资源管理系统(HRM): 用于处理组织内的人事信息,包括员工招聘、培训记录、薪资管理、绩效评估等。HRM系统有助于企业更有效地管理人力资源,提高员工的工作效率和满意度。 库存管理系统: 用于追踪和管理商品或原材料的库存。这种系统可以帮助企业避免库存过剩或不足的问题,提高供应链的效率。 客户关系管理系统(CRM): 用于管理与客户之间的关系,包括客户信息、沟通记录、销售机会跟踪等。CRM系统有助于企业更好地理解客户需求,提高客户满意度和保留率。 医院管理系统: 用于管理医院或医疗机构的患者信息、医生排班、药品库存等。这种系统可以提高医疗服务的质量和效率。 财务管理系统: 用于记录和管理组织的财务信息,包括会计凭证、财务报表、预算管理等。财务管理系统
资源推荐
资源详情
资源评论
收起资源包目录
试题管理系统.zip (98个子文件)
SJT-code
QuestionBaseSystem
__init__.py 0B
wsgi.py 413B
urls.py 1KB
settings.py 3KB
asgi.py 413B
index
__init__.py 0B
tests.py 60B
admin.py 63B
migrations
__init__.py 0B
apps.py 142B
models.py 57B
templates
educater_supermarket.html 4KB
subjectDesc.html 3KB
PersonalCenter.html 2KB
PersonalCenter2.html 3KB
index.html 5KB
text.html 3KB
urls.py 491B
static
CSS
bootstrap.min.css 118KB
PersonalCenter.css 2KB
index.css 4KB
subjectDesc.css 2KB
img
newpk01.png 45KB
background_img.jpg 351KB
newpk02.png 136KB
img.png 18KB
views.py 5KB
exam
__init__.py 0B
tests.py 60B
admin.py 63B
migrations
__init__.py 0B
apps.py 140B
models.py 57B
templates
ExamPage.html 7KB
urls.py 93B
views.py 10KB
CollectTestpaper
__init__.py 1B
tests.py 60B
admin.py 1KB
migrations
__init__.py 0B
0001_initial.py 4KB
0003_alter_testpaper_hard.py 556B
0002_choice_score_gapfill_score_testpaper_apply_time_and_more.py 1KB
apps.py 192B
models.py 4KB
templates
test.html 2KB
testSuccessful.html 656B
urls.py 92B
static
CSS
collect.css 1KB
views.py 15KB
.idea
dataSources
991f8898-97e9-4e64-b266-e807581af4a2.xml 1.23MB
991f8898-97e9-4e64-b266-e807581af4a2
storage_v2
_src_
schema
sakila.oXLGyQ.meta 9B
sys.zb4BAA.meta 6B
information_schema.FNRwLQ.meta 21B
information_schema.FNRwLQ.zip 144KB
sys.zb4BAA.zip 488KB
sakila.oXLGyQ.zip 24KB
dataSources.local.xml 984B
shelf
Uncommitted_changes_before_Checkout_at_2022_11_16_1_26_[Changes]
shelved.patch 6KB
Uncommitted_changes_before_Checkout_at_2022_11_16_1_26_[Changes]1
shelved.patch 0B
Uncommitted_changes_before_Update_at_2022_11_16_0_53__Changes_.xml 387B
Uncommitted_changes_before_Checkout_at_2022_11_16_1_26__Changes_.xml 395B
Uncommitted_changes_before_Update_at_2022_11_16_0_53_[Changes]
shelved.patch 3KB
vcs.xml 180B
workspace.xml 10KB
misc.xml 207B
dataSources.xml 519B
QuestionBaseSystem.iml 1KB
inspectionProfiles
profiles_settings.xml 174B
modules.xml 288B
manage.py 674B
initData.sql 129KB
Consumer
__init__.py 0B
tests.py 60B
admin.py 900B
migrations
__init__.py 0B
0002_consumer_testpaper_first.py 991B
0001_initial.py 1KB
0004_alter_consumer_options_alter_consumer_birthday_and_more.py 3KB
0003_consumer_answer_status.py 1KB
apps.py 176B
models.py 3KB
templates
register.html 3KB
modify.html 3KB
modify_false.html 496B
resetPasswordSuccessful.html 422B
registerFalse.html 498B
login.html 1KB
forgotPwd_verifySecurity.html 951B
registerSuccessful.html 413B
forgotPwd_resetPassword.html 1KB
forgotPwd_inputAccount.html 891B
modify_successful.html 420B
urls.py 384B
static
CSS
forgotPwd.css 2KB
register.css 1KB
login.css 2KB
views.py 6KB
共 98 条
- 1
资源评论
JJJ69
- 粉丝: 6262
- 资源: 5775
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功