def get_context_data(self, **kwargs): force_default_language(self.request) """Insert the form into the context dict.""" if 'form' not in kwargs: kwargs['form'] = self.get_form() school = self.request.user.school notifications = Notification.objects.filter(type='general', schools=school) if school.is_2nd_shift and not school.is_alp: notifications = notifications.filter(school_type='2ndshift') if school.is_alp and not school.is_2nd_shift: notifications = notifications.filter(school_type='ALP') kwargs['notifications'] = notifications[:50] kwargs['unread_notifications'] = notifications.filter( status=False).count() tickets = Notification.objects.filter(type='helpdesk', school_id=school.id) kwargs['tickets'] = tickets[:50] kwargs['unread_tickets'] = tickets.filter(status=False).count() return super(ProfileView, self).get_context_data(**kwargs)
def get_context_data(self, **kwargs): force_default_language(self.request) return {'documents': self.queryset}
def get_queryset(self): force_default_language(self.request) alp_round = ALPRound.objects.get(current_pre_test=True) return Outreach.objects.filter(alp_round=alp_round, owner=self.request.user)
def get_context_data(self, **kwargs): force_default_language(self.request) """Insert the form into the context dict.""" if 'form' not in kwargs: kwargs['form'] = self.get_form() return super(PartnerView, self).get_context_data(**kwargs)
def get_queryset(self): force_default_language(self.request) alp_round = ALPRound.objects.get(current_post_test=True) return Outreach.objects.filter(alp_round=alp_round, registered_in_level__isnull=False)
def get_queryset(self): force_default_language(self.request) alp_round = ALPRound.objects.get(current_round=True) return Outreach.objects.filter(alp_round=alp_round, school=self.request.user.school_id)
def get_context_data(self, **kwargs): force_default_language(self.request) return { }
def get_queryset(self): force_default_language(self.request) education_year = EducationYear.objects.get(current_year=True) return Enrollment.objects.exclude(moved=True).filter( education_year=education_year, school=self.request.user.school_id)
def get_context_data(self, **kwargs): force_default_language(self.request) level = 0 section = 0 school = 0 levels_by_sections = [] attendance_students = [] attendance_status = {} students = [] date_format = '%Y-%m-%d' date_format_display = '%A %d/%m/%Y' alp_round = ALPRound.objects.get(current_round=True) if self.request.user.school: school = self.request.user.school if not school.academic_year_start: messages.warning(self.request, _('Please go to the school profile and enter the academic start date in order to take attendance.')) self.template_name = 'error.html' return { } current_date = datetime.datetime.now().strftime(date_format) selected_date = self.request.GET.get('date', current_date) selected_date_view = datetime.datetime.strptime(selected_date, date_format).strftime(date_format_display) try: attendance = Attendance.objects.get( school_id=school.id, attendance_date=selected_date, school_type='ALP', alp_round__current_round=True ) except Attendance.DoesNotExist: attendance = '' if self.request.GET.get('level', 0): level = EducationLevel.objects.get(id=int(self.request.GET.get('level', 0))) self.template_name = 'attendances/level_section.html' if self.request.GET.get('section', 0): section = Section.objects.get(id=int(self.request.GET.get('section', 0))) queryset = Outreach.objects.filter(school_id=school, alp_round__current_round=True) registrations = queryset.filter( registered_in_level__isnull=False, section__isnull=False ).distinct().values( 'registered_in_level__name', 'registered_in_level_id', 'section__name', 'section_id' ).order_by('registered_in_level_id') current_level_section = '' disable_attendance = False for registry in registrations: exam_day = False not_attending = False school_closed = attendance.close_reason if attendance else False validation_date = attendance.validation_date if attendance else '' total_attended = 0 total_absences = 0 attendance_taken = False level_section = '{}-{}'.format(registry['registered_in_level_id'], registry['section_id']) attendances = attendance.students[level_section] if attendance \ and attendance.students \ and level_section in attendance.students else '' total = queryset.filter(registered_in_level_id=registry['registered_in_level_id'], section_id=registry['section_id']).count() if attendances: attendance_taken = True total = attendances['total_enrolled'] total_attended = attendances['total_attended'] total_absences = attendances['total_absences'] exam_day = attendances['exam_day'] if 'exam_day' in attendances else False not_attending = attendances['not_attending'] if 'not_attending' in attendances else False for value in attendances['students']: attendance_status[value['student_id']] = value level_by_section = { 'level_name': registry['registered_in_level__name'], 'level': registry['registered_in_level_id'], 'section_name': registry['section__name'], 'section': registry['section_id'], 'total': total, 'total_attended': total_attended, 'total_absences': total_absences, 'exam_day': exam_day, 'not_attending': not_attending, 'validation_date': validation_date, 'disable_attendance': disable_attendance, 'attendance_taken': attendance_taken, 'school_closed': school_closed } if level and section and level.id == registry['registered_in_level_id'] and section.id == registry['section_id']: current_level_section = level_by_section if exam_day or not_attending or (attendance and attendance.validation_date) or school_closed: disable_attendance = True levels_by_sections.append(level_by_section) if attendance and (attendance.validation_date or attendance.close_reason): disable_attendance = True if level and section: students = queryset.filter(registered_in_level_id=level.id, section_id=section.id, ).order_by('student__first_name', 'student__father_name', 'student__last_name') for line in students: student = line.student if str(student.id) in attendance_status: student_status = attendance_status[str(student.id)] line.attendance_status = student_status['status'] if 'status' in student_status else True line.absence_reason = student_status['absence_reason'] if 'absence_reason' in student_status else '' attendance_students.append(line) base = datetime.datetime.now() dates = [] allowed_dates = [] if alp_round.round_start_date: start_date = alp_round.round_start_date end_date = datetime.date(base.year, base.month, base.day) delta = end_date - start_date day_range = delta.days + 1 else: day_range = school.attendance_range if school.attendance_range else Attendance.DEFAULT_ATTENDANCE_RANGE for x in range(0, day_range): d = base - datetime.timedelta(days=x) allowed_dates.append(d.strftime(date_format)) dates.append({ 'value': d.strftime(date_format), 'label': d.strftime(date_format_display) }) if selected_date not in allowed_dates: messages.warning(self.request, _('This dates is blocked you are not allowed to take attendance for this date.')) self.template_name = 'error.html' return { } return { 'school_type': 'ALP', 'attendance': attendance, 'disable_attendance': disable_attendance, 'current_level_section': current_level_section, 'total': queryset.count(), 'total_students': students.count() if students else 0, 'students': students, 'school': school, 'level': level, 'section': section, 'dates': dates, 'classrooms': EducationLevel.objects.all(), 'sections': Section.objects.all(), 'levels_by_sections': levels_by_sections, 'selected_date': selected_date, 'selected_date_view': selected_date_view, }