feat: exam/view.py
This commit is contained in:
parent
fef6715c94
commit
789479ddea
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.2.12 on 2024-06-24 02:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('exam', '0002_auto_20240619_1412'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='paper',
|
||||
name='category',
|
||||
field=models.ManyToManyField(blank=True, null=True, to='exam.Questioncat', verbose_name='题库分类'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='paper',
|
||||
name='paper_types',
|
||||
field=models.CharField(choices=[(10, '押题'), (20, '抽考')], default='押题', max_length=50, verbose_name='试卷类型'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.12 on 2024-06-24 02:21
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('exam', '0003_auto_20240624_1020'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='paper',
|
||||
name='paper_types',
|
||||
field=models.CharField(choices=[(10, '押题'), (20, '抽考')], default=10, max_length=50, verbose_name='试卷类型'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.12 on 2024-06-24 03:14
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('exam', '0004_alter_paper_paper_types'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='paper',
|
||||
name='questions',
|
||||
field=models.ManyToManyField(blank=True, null=True, through='exam.PaperQuestion', to='exam.Question'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.12 on 2024-06-24 03:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('exam', '0005_alter_paper_questions'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='paper',
|
||||
name='paper_types',
|
||||
field=models.IntegerField(choices=[(10, '押题'), (20, '抽考')], default=10, verbose_name='试卷类型'),
|
||||
),
|
||||
]
|
|
@ -51,8 +51,14 @@ class Question(CommonADModel):
|
|||
|
||||
|
||||
class Paper(CommonAModel):
|
||||
cate_types = (
|
||||
('押题', '押题'),
|
||||
('抽考', '抽考'),
|
||||
)
|
||||
|
||||
paper_types = models.CharField(default='押题', max_length=50,choices=cate_types, verbose_name='试卷类型')
|
||||
name = models.CharField(max_length=200, verbose_name='名称', unique=True)
|
||||
questions = models.ManyToManyField(Question, through='PaperQuestion')
|
||||
questions = models.ManyToManyField(Question, through='PaperQuestion', null=True, blank=True)
|
||||
limit = models.IntegerField(default=0, verbose_name='限时(分钟)')
|
||||
total_score = models.FloatField(default=0, verbose_name='满分')
|
||||
pass_score = models.FloatField(default=0, verbose_name='通过分数')
|
||||
|
@ -62,6 +68,7 @@ class Paper(CommonAModel):
|
|||
duoxuan_score = models.FloatField(default=4, verbose_name='多选分数')
|
||||
panduan_count = models.IntegerField(default=0, verbose_name='判断数量')
|
||||
panduan_score = models.FloatField(default=2, verbose_name='判断分数')
|
||||
category = models.ManyToManyField(Questioncat,verbose_name='题库分类',related_name='paper_category',null=True, blank=True)
|
||||
class Meta:
|
||||
verbose_name = '押题卷'
|
||||
verbose_name_plural = verbose_name
|
||||
|
|
|
@ -275,7 +275,10 @@ class PaperViewSet(ModelViewSet):
|
|||
vdata = sr.validated_data
|
||||
vdata['create_by'] = request.user
|
||||
questions_ = vdata.pop('questions_')
|
||||
category = vdata.pop('category')
|
||||
paper = Paper.objects.create(**vdata)
|
||||
for c in category:
|
||||
paper.category.add(c.id)
|
||||
q_list = []
|
||||
for i in questions_:
|
||||
q_list.append(PaperQuestion(question=i['question'], total_score=i['total_score'], paper=paper))
|
||||
|
@ -540,7 +543,17 @@ class ExamViewSet(CreateUpdateCustomMixin, ModelViewSet):
|
|||
er.save()
|
||||
ret = {}
|
||||
ret['examrecord'] = er.id
|
||||
pqs = PaperQuestion.objects.filter(paper=exam.paper).order_by('id')
|
||||
if exam.paper.paper_types == 10:
|
||||
pqs = PaperQuestion.objects.filter(paper=exam.paper).order_by('id')
|
||||
else:
|
||||
# 查询此试卷有哪些分类
|
||||
cqs = exam.paper.category
|
||||
print(cqs)
|
||||
# 查询随机组卷的单选、多选、判断各多少题和不同分类
|
||||
single_qs = Question.objects.filter(Q(type="单选") & Q(category__in=cqs)).order_by('?')[:exam.paper.danxuan_count]
|
||||
multiple_qs = Question.objects.filter(Q(type="多选") & Q(category__in=cqs)).order_by('?')[:exam.paper.duoxuan_count]
|
||||
judge_qs = Question.objects.filter(Q(type="判断") & Q(category__in=cqs)).order_by('?')[:exam.paper.panduan_count]
|
||||
pqs = list(single_qs) + list(multiple_qs) + list(judge_qs)
|
||||
details = []
|
||||
for i in pqs:
|
||||
details.append(AnswerDetail(examrecord=er, question=i.question, total_score=i.total_score))
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.2.12 on 2024-06-24 02:20
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('information', '0052_alter_qualification_change_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='qualification',
|
||||
name='change_date',
|
||||
field=models.DateField(blank=True, default=datetime.datetime(2024, 6, 24, 2, 20, 37, 283650, tzinfo=utc), null=True, verbose_name='变更日期'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.2.12 on 2024-06-24 02:21
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('information', '0053_alter_qualification_change_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='qualification',
|
||||
name='change_date',
|
||||
field=models.DateField(blank=True, default=datetime.datetime(2024, 6, 24, 2, 21, 22, 979097, tzinfo=utc), null=True, verbose_name='变更日期'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.2.12 on 2024-06-24 03:21
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('information', '0054_alter_qualification_change_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='qualification',
|
||||
name='change_date',
|
||||
field=models.DateField(blank=True, default=datetime.datetime(2024, 6, 24, 3, 21, 44, 611827, tzinfo=utc), null=True, verbose_name='变更日期'),
|
||||
),
|
||||
]
|
Loading…
Reference in New Issue