def form_valid(self, form): """Save to the database. If data exists, update else create new record""" self.object = form.save(commit=False) self.object.save() school_profile_obj = SchoolProfile( academic_year=academic_year(), sp_school=self.object, sp_school_name=self.object.school_name, sp_cd=self.object.school_block.block_name) school_profile_obj.save() messages.success(self.request, 'School Registered successfully') return super().form_valid(form)
class ExamCoScholastic(models.Model): exam_cs_subject = models.ForeignKey(Subject, on_delete=models.CASCADE) exam_cs_student = models.ForeignKey(Student, on_delete=models.CASCADE) exam_cs_grade_1 = models.CharField(max_length=5, default='NA', choices=exam_cs_grade_choices) exam_cs_grade_2 = models.CharField(max_length=5, default='NA', choices=exam_cs_grade_choices) exam_cs_year = models.CharField(max_length=50, default=academic_year(), choices=year_choices()) exam_cs_class = models.CharField(max_length=5, choices=class_choices, blank=True) exam_cs_section = models.CharField(max_length=5, choices=section_choices, default = 'NA', blank=True) exam_cs_stream = models.CharField(max_length=25, choices=stream_choices, default = 'NA', blank=True) exam_cs_rollno = models.CharField(max_length=10, null=True, blank=True) def __str__(self): return self.exam_cs_student.user.first_name + " ("+ self.exam_cs_class + "-" + self.exam_cs_section + "-" + self.exam_cs_rollno + ") " + self.exam_cs_subject.subject_name
def get(self, request, *args, **kwargs): """ Get inputs from form """ if self.request.GET.get('academic_year_field'): self.academic_year_field = self.request.GET.get( 'academic_year_field') else: self.academic_year_field = academic_year() if self.request.GET.get('districts_field'): self.districts_field = int(self.request.GET.get('districts_field')) if self.request.GET.get('blocks_field'): self.blocks_field = int(self.request.GET.get('blocks_field')) if self.request.GET.get('categories_field'): self.categories_field = self.request.GET.get('categories_field') return super(SchoolsByMgmt, self).get(request, *args, **kwargs)
def studentReportViewByID(request, stud_id): template_name = 'exams/report-by-id.html' year = academic_year() school = School.objects.filter(id=request.GET.get('school', 0)).first() context = { 'academic_year': year, 'year': year_choices, 'school_name': request.user.school.school_name if request.user.is_school_admin else school } if request.method == "POST": if request.POST['year']: year = request.POST['year'] try: current_student = Student.objects.get(id=stud_id) scholastic_subjects = current_student.exam_set.filter( exam_year=year) co_scholastic_subjects = current_student.examcoscholastic_set.filter( exam_cs_year=year) if not (scholastic_subjects or co_scholastic_subjects): context.update({'no_record': True}) else: context.update({ 'subjects': scholastic_subjects, 'co_subjects': co_scholastic_subjects, 'student': current_student, 'selected_year': request.POST['year'], 'display_class_section': scholastic_subjects and (scholastic_subjects[0].exam_class + ' - ' + scholastic_subjects[0].exam_section) or co_scholastic_subjects and (co_scholastic_subjects[0].exam_cs_class + ' - ' + co_scholastic_subjects[0].exam_cs_section), 'display_rollno': (scholastic_subjects and scholastic_subjects[0].exam_rollno) or (co_scholastic_subjects and co_scholastic_subjects[0].exam_cs_rollno) }) except Exception as e: context.update({'no_record': True}) return render(request, template_name, context) return render(request, template_name, context)
def myReportView(request): template_name = 'exams/my-report.html' year = academic_year() context = { 'academic_year': year, 'year': year_choices, 'school_name': request.user.student.stud_school.school_name } if request.method == "POST": if not request.POST['year']: context.update({'error_msg': "Please Select Academic Year"}) return [template_name, context] try: current_student = request.user.student scholastic_subjects = current_student.exam_set.filter( exam_year=request.POST['year']) co_scholastic_subjects = current_student.examcoscholastic_set.filter( exam_cs_year=request.POST['year']) if not (scholastic_subjects or co_scholastic_subjects): context.update({'no_record': True}) else: context.update({ 'subjects': scholastic_subjects, 'co_subjects': co_scholastic_subjects, 'student': current_student, 'selected_year': request.POST['year'], 'display_class_section': scholastic_subjects and (scholastic_subjects[0].exam_class + ' - ' + scholastic_subjects[0].exam_section) or co_scholastic_subjects and (co_scholastic_subjects[0].exam_cs_class + ' - ' + co_scholastic_subjects[0].exam_cs_section), 'display_rollno': (scholastic_subjects and scholastic_subjects[0].exam_rollno) or (co_scholastic_subjects and co_scholastic_subjects[0].exam_cs_rollno) }) except Exception as e: print(e) context.update({'no_record': True}) return [template_name, context] return [template_name, context]
class Exam(models.Model): subject = models.ForeignKey(Subject, on_delete=models.CASCADE) student = models.ForeignKey(Student, on_delete=models.CASCADE) per_test_1 = IntegerRangeField(min_value=0, max_value=10, blank=True, null=True) notebook_1 = IntegerRangeField(min_value=0, max_value=5, blank=True, null=True) sea_1 = IntegerRangeField(min_value=0, max_value=5, blank=True, null=True) main_1 = IntegerRangeField(min_value=0, max_value=80, blank=True, null=True) grade_1 = models.CharField(max_length=10, default='NA', choices=grade_choices, editable=False) per_test_2 = IntegerRangeField(min_value=0, max_value=10, blank=True, null=True) notebook_2 = IntegerRangeField(min_value=0, max_value=5, blank=True, null=True) sea_2 = IntegerRangeField(min_value=0, max_value=5, blank=True, null=True) main_2 = IntegerRangeField(min_value=0, max_value=80, blank=True, null=True) grade_2 = models.CharField(max_length=10, default='NA', choices=grade_choices, editable=False) exam_year = models.CharField(max_length=50, default=academic_year(), choices=year_choices()) exam_class = models.CharField(max_length=5, choices=class_choices, blank=True) exam_section = models.CharField(max_length=5, choices=section_choices, default = 'NA', blank=True) exam_stream = models.CharField(max_length=25, choices=stream_choices, default = 'NA', blank=True) exam_rollno = models.CharField(max_length=10, null=True, blank=True) @property def total_1(self): # returns Term-1 total marks obtained from 100 try: return self.per_test_1 + self.notebook_1 + self.sea_1 + self.main_1 except: return '' @property def total_2(self): # returns Term-2 total marks obtained from 100 try: return self.per_test_2 + self.notebook_2 + self.sea_2 + self.main_2 except: return '' def save(self, *args, **kwargs): try: self.grade_1 = find_grade(self.total_1) self.grade_2 = find_grade(self.total_2) except: pass super().save(*args, **kwargs) def __str__(self): return self.student.user.first_name + " ("+ self.exam_class + "-" + self.exam_section + "-" + self.exam_rollno + ") " + self.subject.subject_name
def studentReportView(request): if request.user.is_student: template_name, context = myReportView(request) return render(request, template_name, context) else: template_name = 'exams/student-report.html' school = School.objects.get(id=request.GET.get('school')) sections = [ item for item in section_choices if item[0] ] context = { 'academic_year': academic_year(), 'class': class_choices, 'section': sections, 'year': year_choices, 'stream': list(stream_choices)[2:], 'school_name': school.school_name } if request.method=="POST": if not request.POST['class']: context.update({ 'error_msg': "Please Select a Class" }) return render(request, template_name, context) else: context.update({ 'selected_class': request.POST['class'] }) if not request.POST['section']: context.update({ 'error_msg': "Please Select a Section" }) return render(request, template_name, context) else: context.update({ 'selected_section': request.POST['section'] }) if not request.POST['year']: context.update({ 'error_msg': "Please Select academic year" }) return render(request, template_name, context) else: context.update({ 'selected_year': request.POST['year'] }) if not request.POST['roll_no']: context.update({ 'error_msg': "Please Enter a Roll No." }) return render(request, template_name, context) else: context.update({ 'input_rollno': request.POST['roll_no'] }) 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: context.update({ 'selected_stream': request.POST['stream'] }) try: if stream: exam = Exam.objects.filter(student__stud_school=school, exam_class=request.POST['class'], exam_section=request.POST['section'], exam_stream=request.POST['stream'], exam_rollno=request.POST['roll_no'], exam_year=request.POST['year']) exam_cs = ExamCoScholastic.objects.filter(exam_cs_student__stud_school=school, exam_cs_class=request.POST['class'], exam_cs_section=request.POST['section'], exam_cs_stream=request.POST['stream'], exam_cs_year=request.POST['year'], exam_cs_rollno=request.POST['roll_no']) else: exam = Exam.objects.filter(student__stud_school=school, exam_class=request.POST['class'], exam_section=request.POST['section'], exam_rollno=request.POST['roll_no'], exam_year=request.POST['year'], exam_school=school) exam_cs = ExamCoScholastic.objects.filter(exam_cs_student__stud_school=school, exam_cs_class=request.POST['class'], exam_cs_section=request.POST['section'], exam_cs_year=request.POST['year'], exam_cs_rollno=request.POST['roll_no'], exam_cs_school=school) current_student = (exam and exam[0].student) or (exam_cs and exam_cs[0].exam_cs_student) scholastic_subjects = exam co_scholastic_subjects = exam_cs if not (scholastic_subjects or co_scholastic_subjects): context.update({ 'no_record': True }) else: context.update({ 'subjects': scholastic_subjects, 'co_subjects': co_scholastic_subjects, 'student': current_student, 'display_class_section': request.POST['class'] + " - " + request.POST['section'], 'display_rollno': request.POST['roll_no'] }) except Exception as e: context.update({ 'no_record': True }) return render(request, template_name, context) return render(request, template_name, context)
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']).extra(select={'stud_rollno_int': 'CAST(stud_rollno AS INTEGER)'}).order_by('stud_rollno_int') 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').order_by('stud_rollno').extra(select={'stud_rollno_int': 'CAST(stud_rollno AS INTEGER)'}).order_by('stud_rollno_int') 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 academic_year() == request.POST['year']: exams = [] for stud in students: e, cr = Exam.objects.get_or_create(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) exams.append(e) 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']) 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 academic_year() == request.POST['year']: exams = [] for stud in students: e, cr = ExamCoScholastic.objects.get_or_create(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) exams.append(e) 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: context.update({'no_record': True}) context.update({ 'exams': exams }) return render(request, template_name, context)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) if 'year' in self.request.GET: if self.request.GET['year'] != "": year = Q(academic_year=self.request.GET['year']) context['year'] = self.request.GET['year'] else: year = Q(academic_year=academic_year()) context['year'] = academic_year() else: year = Q(academic_year=academic_year()) context['year'] = academic_year() if 'district' in self.request.GET: if self.request.GET['district'] != "": district = Q(pf_school__school_district=int( self.request.GET['district'])) context['district_id'] = self.request.GET['district'] else: district = Q() else: district = Q() if 'block' in self.request.GET: if self.request.GET['block'] != "": block = Q( pf_school__school_block=int(self.request.GET['block'])) context['block_id'] = self.request.GET['block'] else: block = Q() else: block = Q() context['years'] = (('', 'Choose Academic Year'), ) + year_choices() context['blocks'] = (('', 'Choose Block'), ) + get_blocks() context['districts'] = (('', 'Choose District'), ) + get_districts() context['no_of_school'] = PhysicalFacilities.objects.filter( year).filter(district).filter(block).count() context[ 'no_of_government_schools'] = PhysicalFacilities.objects.filter( pf_status='Government').filter(year).filter(district).filter( block).count() context[ 'no_of_school_with_drinking_water'] = PhysicalFacilities.objects.filter( pf_drinking_water_available='Yes').filter(year).filter( district).filter(block).count() context[ 'no_of_school_have_playground_facility'] = PhysicalFacilities.objects.filter( pf_playground_facility='Yes').filter(year).filter( district).filter(block).count() context[ 'no_of_school_with_electricity'] = PhysicalFacilities.objects.filter( pf_electricity_connection='Yes').filter(year).filter( district).filter(block).count() context[ 'no_of_school_with_library'] = PhysicalFacilities.objects.filter( pf_librarian='Yes').filter(year).filter(district).filter( block).count() context[ 'no_of_school_with_seperate_girl_common_room'] = PhysicalFacilities.objects.filter( pf_sep_girls_sec='Yes').filter(year).filter(district).filter( block).count() context['no_of_school_with_ramp'] = PhysicalFacilities.objects.filter( pf_ramp_disabled='Yes').filter(year).filter(district).filter( block).count() context[ 'no_of_school_with_toilet'] = PhysicalFacilities.objects.filter( pf_schools_toilet='Yes').filter(year).filter(district).filter( block).count() context['no_of_government_schools'] = get_percentage( context['no_of_government_schools'], context['no_of_school']) context['no_of_school_with_drinking_water'] = get_percentage( context['no_of_school_with_drinking_water'], context['no_of_school']) context['no_of_school_have_playground_facility'] = get_percentage( context['no_of_school_have_playground_facility'], context['no_of_school']) context['no_of_school_with_electricity'] = get_percentage( context['no_of_school_with_electricity'], context['no_of_school']) context['no_of_school_with_library'] = get_percentage( context['no_of_school_with_library'], context['no_of_school']) context[ 'no_of_school_with_seperate_girl_common_room'] = get_percentage( context['no_of_school_with_seperate_girl_common_room'], context['no_of_school']) context['no_of_school_with_ramp'] = get_percentage( context['no_of_school_with_ramp'], context['no_of_school']) context['no_of_school_with_toilet'] = get_percentage( context['no_of_school_with_toilet'], context['no_of_school']) return context