def get_redirect_url(self): # if has_group(self.request.user, 'ENROL_EDIT'): # return reverse('enrollments:enrollment_edit', kwargs={}) # if has_group(self.request.user, 'SCHOOL'): # return reverse('enrollments:enrollment_patch', kwargs={}) # if has_group(self.request.user, 'ALP_SCHOOL'): # return reverse('alp:alp_data_collecting', kwargs={}) + '?1' if has_group(self.request.user, 'PARTNER'): return reverse('alp:alp_outreach', kwargs={}) + '?' if has_group(self.request.user, 'HELPDESK'): return reverse('helpdesk_dashboard', kwargs={}) return reverse('home')
def get_queryset(self, request): qs = super(AbsenteeAdmin, self).get_queryset(request) qs = qs.filter(attended_days__gt=0) if has_group(request.user, 'COORDINATOR'): return qs.filter(school_id__in=request.user.schools.all()) return qs
def delete(self, request, *args, **kwargs): instance = self.model.objects.get(id=kwargs['pk'], school=self.request.user.school) if not has_group(request.user, 'ENROL_DELETE') or not is_owner( request.user, instance): return JsonResponse({'status': 500}) instance.delete() return JsonResponse({'status': status.HTTP_200_OK})
def lookups(self, request, model_admin): """ Returns a list of tuples. The first element in each tuple is the coded value for the option that will appear in the URL query. The second element is the human-readable name for the option that will appear in the right sidebar. """ if has_group(request.user, 'COORDINATOR'): return ((l.id, l.__unicode__()) for l in School.objects.filter( id__in=request.user.schools.all())) return ((l.id, l.__unicode__()) for l in School.objects.all())
def lookups(self, request, model_admin): """ Returns a list of tuples. The first element in each tuple is the coded value for the option that will appear in the URL query. The second element is the human-readable name for the option that will appear in the right sidebar. """ schools = School.objects.all() if has_group(request.user, 'COORDINATOR'): schools = schools.filter(id__in=request.user.schools.all()) return set((l.location_id, l.location.name if l.location else '') for l in schools)
def get(self, request, *args, **kwargs): school = int(request.GET.get('school', 0)) current_type = request.GET.get('current_type', 'current') response = HttpResponse( '', content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ) if has_group(self.request.user, 'PARTNER'): response = export_alp({'pre_test': 'true'}) if has_group(self.request.user, 'ALP_SCHOOL') and self.request.user.school_id: school = self.request.user.school_id if school: response = export_alp({ current_type: 'true', 'school': school }, return_data=True) return response
def update(self, request, *args, **kwargs): if has_group(self.request.user, 'CERD') and request.method != "PATCH": self.serializer_class = OutreachSmallSerializer return super(OutreachViewSet, self).update(request)
def create(self, request, *args, **kwargs): if has_group(self.request.user, 'CERD'): self.serializer_class = OutreachSmallSerializer return super(OutreachViewSet, self).create(request)
def perform_update(self, serializer): if has_group(self.request.user, 'CERD') and self.request.method != "PATCH": self.serializer_class = OutreachSmallSerializer instance = serializer.save() instance.save()
def has_dropout_permission(self, request): if has_group(request.user, 'COORDINATOR') or has_group( request.user, 'PMU'): return False return True
def has_validate_absentees_permission(self, request): if has_group(request.user, 'COORDINATOR') or has_group( request.user, 'PMU'): return False return True
def has_delete_permission(self, request, obj=None): if has_group(request.user, 'COORDINATOR') or has_group( request.user, 'PMU'): return False return True
def get_queryset(self, request): qs = super(BySchoolByDayAdmin, self).get_queryset(request) if has_group(request.user, 'COORDINATOR'): return qs.filter(school_id__in=request.user.schools.all()) return qs
def get(self, request, *args, **kwargs): queryset = self.model.objects.all() school = int(request.GET.get('school', 0)) location = int(request.GET.get('location', 0)) alp_round = ALPRound.objects.get(current_round=True) if has_group(self.request.user, 'PARTNER'): alp_round = ALPRound.objects.get(current_pre_test=True) queryset = queryset.filter(owner=self.request.user, alp_round=alp_round) if has_group(self.request.user, 'ALP_SCHOOL') and self.request.user.school_id: school = self.request.user.school_id if school: queryset = queryset.filter(school_id=school, alp_round=alp_round).order_by('id') if location: queryset = queryset.filter(school__location_id=location, alp_round=alp_round).order_by('id') data = tablib.Dataset() data.headers = [ _('ALP result'), _('ALP round'), _('ALP level'), _('Is the child participated in an ALP program'), _('Education year'), _('Last education level'), _('Phone prefix'), _('Phone number'), _('Student living address'), _('Student ID Number'), _('Student ID Type'), _('Registered in UNHCR'), _('Mother nationality'), _('Mother fullname'), _('Current Section'), _('Current Level'), _('Post-test result'), _('Assigned to level'), _('Pre-test result'), _('Student nationality'), _('Student age'), _('Student birthday'), _('Sex'), _('Student fullname'), _('School'), _('School number'), _('District'), _('Governorate'), ] content = [] for line in queryset: if not line.student or not line.school: continue content = [ line.last_informal_edu_final_result.name if line.last_informal_edu_final_result else '', line.last_informal_edu_round.name if line.last_informal_edu_round else '', line.last_informal_edu_level.name if line.last_informal_edu_level else '', _(line.participated_in_alp) if line.participated_in_alp else '', line.last_education_year, line.last_education_level.name if line.last_education_level else '', line.student.phone_prefix, line.student.phone, line.student.address, line.student.id_number, line.student.id_type.name if line.student.id_type else '', _(line.registered_in_unhcr) if line.registered_in_unhcr else '', line.student.mother_nationality.name if line.student.mother_nationality else '', line.student.mother_fullname, line.section.name if line.section else '', line.registered_in_level.name if line.registered_in_level else '', line.post_exam_total, line.assigned_to_level.name if line.assigned_to_level else '', line.exam_total, line.student.nationality_name(), line.student.calc_age, line.student.birthday, _(line.student.sex), line.student.__unicode__(), line.school.name, line.school.number, line.school.location.name, line.school.location.parent.name, ] data.append(content) file_format = base_formats.XLS() response = HttpResponse( file_format.export_data(data), content_type='application/application/ms-excel', ) response['Content-Disposition'] = 'attachment; filename=outreach_list.xls' return response
def partial_update(self, request, *args, **kwargs): if has_group(self.request.user, 'CERD'): self.serializer_class = GradingSerializer return super(OutreachViewSet, self).partial_update(request)