def addResultMain(request): """ To add results of students / link results and students """ emp = models.Teacher.objects.get(user=request.user) if not emp.result_permit: raise Http404 context_dict = { "result_type": context_helper.result_type_helper(), "all_subjects": context_helper.subject_helper(), "all_exam_name": context_helper.exam_name_helper(), } if request.method == 'POST': roll = request.POST.get('rno') result_type = request.POST.get('result_type_picker') exam = request.POST.get('exam_name_picker') subject = request.POST.get('subject_picker') marks = request.POST.get('marks') student = models.Student.objects.filter( roll_no=roll ).first() result_data_check = models.Result.objects.filter( result_type=result_type, batch=student.batch, exam_name=exam, subject=subject ).first() if not result_data_check: context_dict["message"] = "Result Data does not exist, first create data for result" return render(request, 'addResultMain.html', context_dict) duplicate_check = models.ResultMain.objects.filter( student=models.Student.objects.filter(roll_no=student).first(), result=result_data_check, ).first() if duplicate_check: context_dict["message"]= 'Result already exist.' duplicate_check.soft_delete=False duplicate_check.save() return render(request, "addResultMain.html", context_dict) try: result = models.ResultMain( student=student, result=result_data_check, marks_obtained=marks, ) result.save() history = models.History( user=emp, activity='Added result ' + str(result) + '-' + str(marks) +'.\n', activity_type="add result " ) history.save() context_dict["message"] = 'Successfully added new result.' context_dict["success"] = True except Exception as e: context_dict["message"] = str(e) context_dict["success"] = False print(e) return render(request, 'addResultMain.html', context_dict)
def addResultData(request): """ For adding Result Meta Data """ emp = models.Teacher.objects.get(user=request.user) if not emp.result_permit: raise Http404 context_dict = { "result_type": context_helper.result_type_helper(), "all_subjects": context_helper.subject_helper(), "all_courses": context_helper.course_helper(), "all_exam_name": context_helper.exam_name_helper(), } if request.method == "POST": course = request.POST.get('course_picker') result_type = request.POST.get('result_type_picker') exam_name = request.POST.get('exam_name_picker') subject = request.POST.get('subject_picker') batch = request.POST.get('batch') duplicate_check = models.Result.objects.filter( course=course, result_type=result_type, exam_name=exam_name, subject=subject, batch=batch ).first() if duplicate_check: context_dict["message"] = 'Result Data already exist.' duplicate_check.soft_delete=False duplicate_check.save() return render(request, "addResultData.html", context_dict) try: result_data = models.Result( course=models.Course.objects.get(pk=course), result_type=result_type, exam_name=models.ExamName.objects.get(pk=course), subject=models.Subject.objects.get(pk=course), batch=batch ) result_data.save() history = models.History( user=emp, activity='Added result data' + str(course)+ str(result_type)+ str(exam_name)+ str(subject)+ str(batch) +'.\n', activity_type="add result data" ) history.save() context_dict["message"] = 'Successfully added new Result Data.' context_dict["success"] = True except Exception as e: context_dict["message"] = str(e) context_dict["success"] = False print(e) return render(request, "addResultData.html", context_dict)
def add_attendance(request): """ Add result of attendance to the particular subject. Can also use this by taking subject ID not giving drop down for subjects. """ emp = models.Teacher.objects.get(user=request.user) if not emp.student_permit: raise Http404 context_dict = { "all_subjects": context_helper.subject_helper(), } if request.method == "POST": roll = request.POST.get('roll') subject = request.POST.get('subject_picker') attendance = request.POST.get('attendance') total = request.POST.get('total') student = models.Student.objects.filter( roll_no=roll ).first() duplicate_check = models.Attendance.objects.filter( student=student, subject=subject, ).first() if duplicate_check: context_dict["message"] = 'Attendance already exist.' duplicate_check.soft_delete=False duplicate_check.save() return render(request, "addAttendance.html", context_dict) try: attendance_data = models.Attendance( student=student, subject=models.Subject.objects.get(pk=subject), total_attendance=total, obtained_attendance=attendance ) attendance_data.save() history = models.History( user=emp, activity='Added attendance of ' + str(student) + str(subject) +'.\n', activity_type="add attendance" ) history.save() context_dict["message"] = 'Successfully added Attendance.' context_dict["success"] = True except Exception as e: context_dict["message"] = str(e) context_dict["success"] = False print(e) return render(request, "addAttendance.html", context_dict)
def edit_result_data(request, rdata_id): """ Edit Result Data. """ emp = models.Teacher.objects.get(user=request.user) if not emp.result_permit: raise Http404 result_data = models.Result.objects.filter( pk=rdata_id, soft_delete=False ).first() if not result_data: raise Http404 context_dict = { "result_types": context_helper.result_type_helper(), "all_subjects": context_helper.subject_helper(), "all_courses": context_helper.course_helper(), "all_exam_name": context_helper.exam_name_helper(), 'rdata_id': rdata_id, } if request.method == 'POST': update_fields = [] activity = '' course = request.POST.get('course_picker') result_type = request.POST.get('result_type_picker') exam_name = request.POST.get('exam_name_picker') subject = request.POST.get('subject_picker') batch = request.POST.get('batch') try: if result_data.result_type != result_type: result_data.result_type = result_type update_fields.append('result_type') activity += 'Changed result type to ' + str(result_type) + '.\n' if str(result_data.course.pk) != str(course): result_data.course = models.Course.objects.get(pk=course) update_fields.append('course') activity += 'Changed course to ' + str(course) + '.\n' if str(result_data.exam_name.pk) != str(exam_name): result_data.exam_name = models.ExamName.objects.get(pk=exam_name) update_fields.append('exam_name') activity += 'Changed Exam name to ' + str(exam_name) + '.\n' if str(result_data.subject.pk) != str(subject): result_data.subject = models.Subject.objects.get(pk=subject) update_fields.append('subject') activity += 'Changed subject to ' + str(subject) + '.\n' if result_data.batch != batch: result_data.batch = batch update_fields.append('batch') activity += 'Changed batch to' + str(batch) + '.\n' result_data.save(update_fields=update_fields) history = models.History( user=emp, activity=activity, activity_type="edit result data" ) history.save() context_dict["message"] = 'Successfully updated Result Data.' context_dict["success"] = True except Exception as e: context_dict["message"] = str(e) context_dict["success"] = False print(e) context_dict.update(context_helper.get_result_info(result_data)) for i in context_dict['courses']: #use this for dynamic try: del context_dict['all_courses'][i] except: pass for i in context_dict['result_type']: #use this for static try: context_dict['result_types'].remove(i) except: pass for i in context_dict['exams']: try: del context_dict['all_exam_name'][i] except: pass for i in context_dict['subjects']: try: del context_dict['all_subjects'][i] except: pass if context_dict.get('success', False): return HttpResponseRedirect('/view-results') return render( request, "editResultData.html", context_dict )
def edit_attendance(request, attendance_id): """ Edit attendance of students subject wise. """ emp = models.Teacher.objects.get(user=request.user) if not emp.student_permit: raise Http404 attendance = models.Attendance.objects.filter( pk=attendance_id, soft_delete=False ).first() print("1") context_dict = { "all_subjects": context_helper.subject_helper(), 'attendance_id': attendance_id, } if request.method == 'POST': update_fields = [] activity = '' roll = request.POST.get('roll') subject = request.POST.get('subject_picker') obtained = request.POST.get('attendance') total = request.POST.get('total') student = models.Student.objects.filter( roll_no=roll ).first() if not student: context_dict["message"] = 'Student at does not exist / Roll number has not been alloted.' return render(request, "editAttendance.html", context_dict) try: if attendance.student != student: attendance.student = student update_fields.append('student') activity += 'Changed student to ' + str(student) + '.\n' if attendance.total_attendance != total: attendance.total_attendance = total update_fields.append('total_attendance') activity += 'Changed total attendance to ' + str(total) + '.\n' if attendance.obtained_attendance != obtained: attendance.obtained_attendance = obtained update_fields.append('obtained_attendance') activity += 'Changed obtained attendance to' + str(obtained) + '.\n' if str(attendance.subject.pk) != str(subject): attendance.subject = models.Subject.objects.get(pk=subject) update_fields.append('subject') activity += 'Changed subject to ' + str(subject) + '.\n' attendance.save(update_fields=update_fields) history = models.History( user=emp, activity=activity, activity_type="edit attendance" ) history.save() context_dict["message"] = 'Successfully updated Attendance.' context_dict["success"] = True except Exception as e: context_dict["message"] = str(e) context_dict["success"] = False print(e) context_dict.update(context_helper.get_attendance_info(attendance)) for i in context_dict['subjects']: # use for dynamic try: del context_dict['all_subjects'][i] except: pass if context_dict.get('success', False): return HttpResponseRedirect('/view-attendance') return render( request, "editAttendance.html", context_dict )
def editResultMain(request, resultMain_id): """ Edit Mains Result. """ emp = models.Teacher.objects.get(user=request.user) if not emp.result_permit: raise Http404 result_main = models.ResultMain.objects.filter( pk=resultMain_id, soft_delete=False ).first() print(result_main.result) print("1") if not result_main: raise Http404 context_dict = { "result_types": context_helper.result_type_helper(), "all_subjects": context_helper.subject_helper(), "all_exam_name": context_helper.exam_name_helper(), 'resultMain_id': resultMain_id, } if request.method == 'POST': update_fields = [] activity = '' roll = request.POST.get('rno') result_type = request.POST.get('result_type_picker') exam = request.POST.get('exam_name_picker') subject = request.POST.get('subject_picker') marks = request.POST.get('marks') student = models.Student.objects.filter( roll_no=roll ).first() result_data_check = models.Result.objects.filter( result_type=result_type, batch=student.batch, exam_name=exam, subject=subject ).first() print(result_data_check) print("2") if not result_data_check: context_dict["message"] = "Result Data does not exist, first create data for result" return render(request, 'addResultMain.html', context_dict) try: if result_main.student != student: result_main.student = student update_fields.append('student') activity += 'Changed student to ' + str(student) + '.\n' # result_main.student = student # update_fields.append('student') if result_main.result != result_data_check: result_main.result = result_data_check update_fields.append('result') activity += 'Changed student to ' + str(result) + '.\n' # result_main.result = result_data_check # update_fields.append('result') if result_main.marks_obtained != marks: result_main.marks_obtained = marks update_fields.append('marks_obtained') activity += 'Changed marks to ' + str(marks) + '.\n' # result_main.marks_obtained = marks # update_fields.append('marks_obtained') activity += 'Edited Result Main of student' + str(student) + '.\n' result_main.save(update_fields=update_fields) history = models.History( user=emp, activity=activity, activity_type='Edit Result Main' ) history.save() context_dict["message"] = 'Successfully updated Result Main.' context_dict["success"] = True except Exception as e: context_dict["message"] = str(e) context_dict["success"] = False print(e) context_dict.update(context_helper.get_resultMain_info(result_main)) for i in context_dict['exams']: #use this for dynamic try: del context_dict['all_exam_name'][i] except: pass for i in context_dict['subjects']: #use this for dynamic try: del context_dict['all_subjects'][i] except: pass for i in context_dict['result_type']: #use this for static try: context_dict['result_types'].remove(i) except: pass if context_dict.get('success', False): return HttpResponseRedirect('/view-result-main') return render( request, "editResultMain.html", context_dict )