def start_exam(request): """ Creates new exam based on subjects and length parameters """ length = int(request.GET.get('length')) subjects = request.GET.getlist('subjects') exam = Exam.create(request.user, subjects, length) return redirect('exams:exam-detail', id=exam.id)
def createexams(request): Exam.objects.all().delete() exams = ExamType.objects.all() subtests = ["A", "B", "C", "D"] for et in exams: for st in subtests: qnums = "" for x in range(0, 10): qnum = random.randint(1, 160) qnums = qnums + str(qnum) + "," qnums = qnums[:-1] ne = Exam() ne.exam_type = et ne.sub_test = st ne.exam_ques = qnums ne.save() return redirect("/admin/exams/exam/")
def createexams(request): Exam.objects.all().delete() exams=ExamType.objects.all() subtests = ["A","B","C","D"] for et in exams: for st in subtests: qnums = "" for x in range(0,10): qnum = random.randint(1,160) qnums = qnums + str(qnum) + "," qnums = qnums[:-1] ne = Exam() ne.exam_type = et ne.sub_test = st ne.exam_ques = qnums ne.save() return redirect("/admin/exams/exam/")
def save(self): exam = self.exam if not exam: exam = Exam() data = self.cleaned_data exam.publishable = False exam.paper_only = False fields = ['has_solutions', 'version', 'number', 'exam_type', 'semester'] if self.request.user.is_superuser: fields += ["publishable", "complete"] for field in fields: setattr(exam, field, data[field]) if exam.semester == INITIAL_SEMESTER_VALUE: exam.semester = None exam.comment = exam.comment or '' if exam.comment.find('FILENAME:') == -1: exam.comment += "\nFILENAME: '%s'\n" % data['exam_file'].name if not exam.submitter and not self.request.user.is_anonymous(): exam.submitter = self.request.user if data.has_key('course'): exam.course = data['course'] if data.has_key("exam_file_extension"): exam.file.save(exam.get_exam_filename() + data["exam_file_extension"], ContentFile(data['exam_file'].read())) else: exam.save() #instructors = [instr for instr in [data.get(field, None) for field in ("instructor1", "instructor2")] if instr is not None] #instrs = [data.get(field, None) for field in ("instructor1", "instructor2")] #instructors = filter(lamdba x: x is not None, instrs) instructors = [] if 'instructor1' in data: instructors.append(data['instructor1']) if 'instructor2' in data: instructors.append(data['instructor2']) if instructors: exam.instructors = instructors return exam
def reportView(request): # template_name = 'exams/report.html' template_name = 'exams/report-2.html' none_edit_view = False context = { 'class': class_choices, 'selected_class': None, 'selected_subject': None, 'year': year_choices, 'section': list(section_choices)[1:], 'stream': list(stream_choices)[1:] } if request.user.is_block_admin or request.user.is_district_admin or request.user.is_state_admin: none_edit_view = True schools_list = [] if request.user.is_block_admin: schools_list = request.user.block.school_set.values( 'id', 'school_name').distinct() if request.user.is_district_admin: blocks_list = request.user.district.block_set.values( 'id', 'block_name').distinct() context.update({ 'show_block': True, 'blocks': blocks_list, 'selected_block': None }) if request.user.is_state_admin: districts_list = District.objects.values( 'id', 'district_name').distinct() context.update({ 'show_block': True, 'show_district': True, 'districts': districts_list, 'selected_district': None }) context.update({ 'school': schools_list, 'selected_school': None, 'no_editing': True }) if request.method == "POST": context.update({ 'selected_block': int(request.POST.get('block', None) or 0), 'selected_district': int(request.POST.get('district', None) or 0), 'selected_school': int(request.POST.get('school', None) or 0), 'selected_class': request.POST.get('class', None), 'selected_section': request.POST.get('section', None), 'selected_year': request.POST.get('year', None), 'selected_subject': request.POST.get('subject', None), 'selected_stream': request.POST.get('stream', None) }) if not request.POST['year']: context.update({'error_msg': "Please Select academic year"}) return render(request, template_name, context) if (request.user.is_district_admin or request.user.is_state_admin): if not request.POST.get('block', False): context.update({'error_msg': "Please Select a Block"}) return render(request, template_name, context) if request.user.is_state_admin: if not request.POST.get('district', False): context.update({'error_msg': "Please Select a District"}) return render(request, template_name, context) if none_edit_view: if request.POST['block']: context.update({ 'school': School.objects.filter(school_block=request.POST['block']) }) if request.POST['district'] and request.POST['block']: context.update({ 'blocks': Block.objects.filter( block_district=request.POST['district']), 'school': School.objects.filter( school_block=request.POST['block'], school_district=request.POST['district']) }) if not request.POST['school']: context.update({'error_msg': "Please Select a School"}) return render(request, template_name, context) if not request.POST['class']: context.update({'error_msg': "Please Select a Class"}) return render(request, template_name, context) if not request.POST['subject']: context.update({'error_msg': "Please Select a Subject"}) return render(request, template_name, context) if request.POST['class'] == '11' or request.POST['class'] == '12': stream = True if not request.POST['stream']: context.update({'error_msg': "Please Select a stream"}) return render(request, template_name, context) else: stream = False if not request.POST['section']: context.update({'error_msg': "Please Select a Section"}) return render(request, template_name, context) # New Strategy if none_edit_view: subject = Subject.objects.get( subject_name=request.POST['subject'], subject_class=request.POST['class'], subject_board=School.objects.get( id=request.POST['school']).school_board) students = Student.objects.filter( stud_class=request.POST['class'], stud_section=request.POST['section'], stud_stream=request.POST['stream'] if stream else 'NA', stud_school=request.POST['school']) else: subject = Subject.objects.get( subject_name=request.POST['subject'], subject_class=request.POST['class'], subject_board=request.user.school.school_board) students = request.user.school.student_set.filter( stud_class=request.POST['class'], stud_section=request.POST['section'], stud_stream=request.POST['stream'] if stream else 'NA') if subject.subject_type != "Co -Scholastic": if none_edit_view: exams = Exam.objects.filter( student__stud_school=request.POST['school'], exam_class=request.POST['class'], subject=subject, exam_section=request.POST['section'], exam_stream=request.POST['stream'] if stream else 'NA', exam_year=request.POST['year']) else: exams = Exam.objects.filter( student__stud_school=request.user.school, exam_class=request.POST['class'], subject=subject, exam_section=request.POST['section'], exam_stream=request.POST['stream'] if stream else 'NA', exam_year=request.POST['year']) if (not exams) and academic_year() == request.POST['year']: exams = [] for stud in students: e = Exam(exam_class=stud.stud_class, student=stud, subject=subject, exam_section=stud.stud_section, exam_stream=stud.stud_stream, exam_year=request.POST['year'], exam_rollno=stud.stud_rollno) e.save() exams.append(e) else: context.update({'has_co_scholastic_subject': True}) if none_edit_view: exams = ExamCoScholastic.objects.filter( exam_cs_student__stud_school__school_name=request. POST['school'], exam_cs_class=request.POST['class'], exam_cs_subject=subject, exam_cs_section=request.POST['section'], exam_cs_stream=request.POST['stream'] if stream else 'NA', exam_cs_year=request.POST['year']) else: exams = ExamCoScholastic.objects.filter( exam_cs_student__stud_school=request.user.school, exam_cs_class=request.POST['class'], exam_cs_subject=subject, exam_cs_section=request.POST['section'], exam_cs_stream=request.POST['stream'] if stream else 'NA', exam_cs_year=request.POST['year']) if (not exams) and academic_year() == request.POST['year']: exams = [] for stud in students: e = ExamCoScholastic(exam_cs_student=stud, exam_cs_class=stud.stud_class, exam_cs_subject=subject, exam_cs_section=stud.stud_section, exam_cs_stream=stud.stud_stream, exam_cs_year=request.POST['year'], exam_cs_rollno=stud.stud_rollno) e.save() exams.append(e) if not exams: context.update({'no_record': True}) context.update({'exams': exams}) return render(request, template_name, context)