예제 #1
0
 def create_exam(self, name, start, end):
     examid = IDGenerator.generate(Entity.Exam)
     new_exam = Exam(id=examid,
                     name=name,
                     organizer=self.organizer,
                     start_time=start,
                     end_time=end)
     new_exam.save()
     return new_exam
예제 #2
0
파일: tests.py 프로젝트: psycho-ir/azma-py
 def test_to_find_an_exam_with_all_its_questions(self):
     e = Exam()
     e.name = "Simple Exam"
     e.start_date = datetime.now()
     e.save()
     q = e.question_set.create()
     choice1 = MultipleChoice()
     choice1.valid = True
     choice1.text = "RED"
     q.choice_set.add(choice1)
     print(choice1.id)
     self.assertIsNotNone(choice1.id)
예제 #3
0
    def update(self, pk):
        try:
            exam = Exam.objects.get(id=pk)
        except Teacher.DoesNotExist:
            exam = Exam()

        exam.time = self.data['time'] if 'time' in self.data else exam.time
        exam.desc = self.data['desc'] if 'desc' in self.data else exam.desc
        exam.total = self.data['total'] if 'total' in self.data else exam.total
        exam.lock = self.data['lock'] if 'lock' in self.data else exam.lock
        exam.save()
        return exam
예제 #4
0
    def post(self, request, *args, **kwargs):
        if request.is_ajax(): # If the request is ajax
            payload = loads(request.body) #Get the body of the request
            exam = Exam.objects.filter(key=payload['key']).first() #Grab the exam that has that key
            exam.archived = True #Set the exam as archived and respond.
            exam.save()
            return JsonResponse({"Archived": True}, status=200)

        form = self.form(request.POST) #Get the form from the page
        if form.is_valid():
            full_name = form.cleaned_data['full_name'].split(" ")
            key = generate_key(full_name[0], full_name[1]) #Generate the key
            exam = Exam( #Create the exam
                first_name=full_name[0],
                last_name=full_name[1],
                key=key,
                exam_template=form.cleaned_data['exam_template']
                )
            exam.save()
            
        return redirect('exam-active')
예제 #5
0
    def create(self, validated_data):
        request = self.context.get("request")
        name = validated_data.get("name")
        subject = request.data['subject']
        subject_instance = Subject.objects.get(pk=subject['id'])
        exercises = request.data['exercises']
        print('data================', exercises)

        # throughModel = exams.subject

        exam = Exam(name=name, subject=subject_instance)
        exam.save()

        for exercise in exercises:
            ex_name = exercise['name']
            ex_description = exercise['description']
            exercise_instance = Exercise(name=ex_name,
                                         description=ex_description,
                                         exam=exam,
                                         subject=subject_instance)
            exercise_instance.save()

        return exam
예제 #6
0
def addExam(request):
    img, id = fun(request)
    g = request.user.groups.all()
    g_id = Group.objects.get(name=g[0]).id
    id = request.user.username
    if g_id == 1:
        return render(request, 'examDashboard.html')
    else:
        teacher = Teacher.objects.filter(username=id)
        uploadedBy = teacher[0].firstname + ' ' + teacher[0].lastname
        courses = Courses.objects.all()
        departments = Department.objects.all()
    params = {'uploadedBy': uploadedBy,
              'courses': courses, 'departments': departments, 'img': img}
    if request.method == "POST" and request.FILES['exam_file']:
        qpaperfile = request.FILES['exam_file']
        fileurl = qpaperfile
        examName = request.POST.get('examName', '')
        doe = request.POST.get('doe', '')
        est = request.POST.get('est', '')
        eet = request.POST.get('eet', '')
        examtype = request.POST.get('examType', '')
        cname = request.POST.get('course', '')
        course = Courses.objects.get(course_name=cname)
        dept = request.POST.get('dept', '')
        uploadedBy = request.POST.get('uploadedBy', '')
        upby = Teacher.objects.get(username=id)
        detail = request.POST.get('detail', '')
        emarks_outof = request.POST.get('emarks_outof')
        if g_id == 1:
            return render(request, 'examDashboard.html')
        else:
            exam = Exam(exam_fileUpload=fileurl, exam_name=examName, exam_type=examtype, exam_date=doe,
                        exam_start_time=est, exam_end_time=eet, exam_detail=detail, course=course, dept=dept, uploaded_by=upby, exam_marksOutOf=emarks_outof)
            exam.save()
            return HttpResponse("<script>setTimeout(function(){window.location.href='/exam/addExam/'},0000);</script>")
    return render(request, 'addExam.html', params)
예제 #7
0
 def post(self, request):
     serializer = ExamCreate(data=request.data)
     if serializer.is_valid():
         name = serializer.data.get("name")
         teacher = serializer.data.get("teacher")
         exam = Exam()
         exam.name = name
         exam.Teacher = teacher
         exam.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
예제 #8
0
def new_exam(request):
    form = NewExam()
    context = {
        "form": form,
    }
    if request.method == 'POST':
        form = NewExam(request.POST)
        if form.is_valid():
            subject = request.POST['subject']
            question_amount = request.POST['question_amount']
            answer_at_end = request.POST['feedback']
            e = Exam(subject=subject,
                     user=request.user,
                     question_amount=question_amount,
                     answer_at_end=answer_at_end)
            e.save()
            e.set_questions()
            return HttpResponseRedirect(
                reverse('question_form', kwargs={'pk': e.id}))

        else:
            return redirect("exam_templates/new_exam.html", context)

    return render(request, "exam_templates/newexam.html", context)
예제 #9
0
    def create_exam_freezing(self):
        from exam.models import Exam

        exam = Exam()
        exam.id = 1
        exam.request_date = timezone.now()
        exam.receipt_date = timezone.now()
        exam.speciment_collection_date = timezone.now()
        exam.received_speciment = 'Speciment'
        exam.examination_time = '00:00:00'
        exam.requesting_physician = 'Request Physician'
        exam.responsible_physician = 'Responsible Physician'
        exam.exam_type_id = 1
        exam.patient = 1
        exam.save()
예제 #10
0
    def create_exam_biopsy(self, patient_id=1):
        from exam.models import Exam

        exam = Exam()
        exam.id = 1
        exam.request_date = timezone.now()
        exam.receipt_date = timezone.now()
        exam.speciment_collection_date = timezone.now()
        exam.received_speciment = 'Speciment'
        exam.requesting_physician = 'Request Physician'
        exam.responsible_physician = 'Responsible Physician'
        exam.exam_type_id = 1
        exam.patient = patient_id
        exam.save()
        self.create_biopsy(exam.id)
예제 #11
0
    def post(self, request):
        ret = dict()
        try:
            user_id = request.session.get('_auth_user_id')
            exam = Exam()
            exam.create_user_id = user_id
            exam.name = request.POST.get("title")
            exam.duration = int(request.POST.get("duration"))

            types = request.POST.getlist("types", [])
            if len(types) == 0:
                raise Exception('考试类型不能为空')

            dep_id_list = []
            if 'to' in request.POST and request.POST['to']:
                dep_id_list = request.POST.getlist('to', [])
            if len(dep_id_list) == 0:
                raise Exception('考试部门不能为空')

            exam.start_time = request.POST.get("start_time")
            exam.end_time = request.POST.get("end_time")

            one_num = request.POST.get('one_num')
            one_score = request.POST.get('one_score')
            if one_num:
                if int(one_num) > 0:
                    if not one_score or float(one_score) <= 0:
                        raise Exception('请正确输入单选题数量与分数')
                    one_data_num = 0  # 判断题目数量是否足够
                    for i in types:
                        one_data = ExamOneChoose.objects.filter(type_id=i)
                        one_data_num += len(one_data)
                    if int(one_num) > one_data_num:
                        raise Exception('单选题数量超出当前题库存储数量')
                    exam.one_num = one_num
                    exam.one_score = float(one_score)
                elif int(one_num) < 0:
                    raise Exception('请正确输入单选题数量与分数')

            muti_num = request.POST.get('muti_num')
            muti_score = request.POST.get('muti_score')
            if muti_num:
                if int(muti_num) > 0:
                    if not muti_score or float(muti_score) <= 0:
                        raise Exception('请正确输入多选题数量与分数')
                    muti_data_num = 0  # 判断题目数量是否足够
                    for i in types:
                        muti_data = ExamMutiChoose.objects.filter(type_id=i)
                        muti_data_num += len(muti_data)
                    if int(muti_num) > muti_data_num:
                        raise Exception('多选题数量超出当前题库存储数量')
                    exam.muti_num = muti_num
                    exam.muti_score = float(muti_score)
                elif int(muti_num) < 0:
                    raise Exception('请正确输入多选题数量与分数')

            TorF_num = request.POST.get('TorF_num')
            TorF_score = request.POST.get('TorF_score')
            if TorF_num:
                if int(TorF_num) > 0:
                    if not TorF_score or float(TorF_score) <= 0:
                        raise Exception('请正确输入判断题数量与分数')
                    TorF_data_num = 0  # 判断题目数量是否足够
                    for i in types:
                        TorF_data = ExamTorF.objects.filter(type_id=i)
                        TorF_data_num += len(TorF_data)
                    if int(TorF_num) > TorF_data_num:
                        raise Exception('判断题数量超出当前题库存储数量')
                    exam.TorF_num = TorF_num
                    exam.TorF_score = float(TorF_score)
                elif int(TorF_num) < 0:
                    raise Exception('请正确输入判断题数量与分数')

            exam.total_score = float(request.POST.get('total_score'))
            if exam.total_score <= 0:
                raise Exception('总分不能小于等于0')
            exam.pass_score = float(request.POST.get('pass_score'))
            if exam.total_score < exam.pass_score:
                raise Exception('总分不能小于及格分数')

            exam.save()
            for t in types:
                exam_type = ExamTypeRel()
                exam_type.exam = exam
                exam_type.type_id = t
                exam_type.save()
            for d in dep_id_list:
                exam_dep = ExamDep()
                exam_dep.exam = exam
                exam_dep.dep_id = d
                exam_dep.save()
            ret['code'] = '0'
        except Exception as e:
            ret['code'] = '-1'
            ret['error'] = str(e)
        return HttpResponse(json.dumps(ret, cls=DjangoJSONEncoder),
                            content_type='application/json')