add: 出具培训证书
This commit is contained in:
parent
df843b2817
commit
61f9085f34
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.2.12 on 2024-05-30 05:29
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('exam', '0001_initial'),
|
||||
('edu', '0005_certificate_培训结束日期'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='certificate',
|
||||
name='examrecord',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='exam.examrecord'),
|
||||
),
|
||||
]
|
|
@ -1,5 +1,6 @@
|
|||
from django.db import models
|
||||
from apps.system.models import CommonADModel, CommonAModel
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
|
@ -28,3 +29,4 @@ class Certificate(CommonADModel):
|
|||
培训结束日期 = models.DateField(null=True, blank=True)
|
||||
发证日期 = models.DateField(null=True, blank=True)
|
||||
证书地址 = models.CharField(max_length=100, null=True, blank=True)
|
||||
examrecord = models.ForeignKey('exam.ExamRecord', on_delete=models.CASCADE, null=True, blank=True)
|
||||
|
|
|
@ -7,7 +7,7 @@ from apps.exam.serializers import (QuestionSerializer, QuestioncatSerializer, Pa
|
|||
ExamCreateUpdateSerializer, ExamListSerializer, ExamRecordSubmitSerializer, PaperDetailSerializer, PaperCreateUpdateSerializer, AnswerDetailOutSerializer, ExamRecordListSerializer)
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||||
from rest_framework.exceptions import ParseError
|
||||
from openpyxl import Workbook, load_workbook
|
||||
from django.conf import settings
|
||||
|
@ -545,7 +545,10 @@ class ExamRecordViewSet(ListModelMixin, DestroyModelMixin, RetrieveModelMixin, G
|
|||
|
||||
提交答卷
|
||||
'''
|
||||
er = self.get_object()
|
||||
try:
|
||||
er = ExamRecord.objects.get(id=pk)
|
||||
except Exception as e:
|
||||
raise ParseError(e)
|
||||
now = timezone.now()
|
||||
if er.create_by != request.user:
|
||||
raise ParseError('提交人有误')
|
||||
|
@ -566,10 +569,12 @@ class ExamRecordViewSet(ListModelMixin, DestroyModelMixin, RetrieveModelMixin, G
|
|||
for index, ad in enumerate(ads):
|
||||
ad.user_answer = questions_[index]['user_answer']
|
||||
if ad.question.type == '多选':
|
||||
print('多选', ad.question.right, ad.user_answer)
|
||||
if set(ad.question.right) == set(ad.user_answer):
|
||||
ad.is_right = True
|
||||
ad.score = ad.total_score
|
||||
else:
|
||||
print('其他', ad.question.right, ad.user_answer)
|
||||
if ad.question.right == ad.user_answer:
|
||||
ad.is_right = True
|
||||
ad.score = ad.total_score
|
||||
|
@ -579,6 +584,7 @@ class ExamRecordViewSet(ListModelMixin, DestroyModelMixin, RetrieveModelMixin, G
|
|||
raise ParseError('判卷失败, 请检查试卷:' + str(e))
|
||||
er.score = total_score
|
||||
# if er.score > 0.6*er.total_score:
|
||||
print('score:', er.score, 'paper_socre',paper.pass_score)
|
||||
if er.score >= paper.pass_score:
|
||||
er.is_pass = True
|
||||
# 如果是自动发证
|
||||
|
@ -594,6 +600,7 @@ class ExamRecordViewSet(ListModelMixin, DestroyModelMixin, RetrieveModelMixin, G
|
|||
'所属单位': '国检测试控股集团'+request.user.dept.name,
|
||||
'发证日期': current_date,
|
||||
'课程列表': courese_ids,
|
||||
'examrecord': er.id,
|
||||
}
|
||||
serializer = CertificateSerializer(data=data_dict)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
|
Loading…
Reference in New Issue