def education_groups(request): person = get_object_or_404(Person, user=request.user) if request.GET: form = EducationGroupFilter(request.GET) else: current_academic_year = mdl.academic_year.current_academic_year() form = EducationGroupFilter(initial={'academic_year': current_academic_year, 'category': education_group_categories.TRAINING}) object_list = _get_object_list(form, request) if form.is_valid() else [] if request.GET.get('xls_status') == "xls": return create_xls(request.user, object_list, _get_filter_keys(form), {ORDER_COL: request.GET.get('xls_order_col'), ORDER_DIRECTION: request.GET.get('xls_order')}) if request.GET.get('xls_status') == "xls_administrative": return create_xls_administrative_data( request.user, object_list, _get_filter_keys(form), {ORDER_COL: request.GET.get('xls_order_col'), ORDER_DIRECTION: request.GET.get('xls_order')} ) context = { 'form': form, 'object_list': paginate_queryset(object_list, request.GET), 'object_list_count': len(object_list), 'experimental_phase': True, 'enums': education_group_categories, 'person': person } return layout.render(request, "education_group/search.html", context)
def test_ordering(self): self.form = EducationGroupFilter() self.assertEqual( list(self.form.fields["education_group_type"].queryset), [self.educ_grp_type_A, self.educ_grp_type_B, self.educ_grp_type_D]) educ_grp_type_C = EducationGroupTypeFactory(name='C label') self.form = EducationGroupFilter() self.assertEqual( list(self.form.fields["education_group_type"].queryset), [ self.educ_grp_type_A, self.educ_grp_type_B, educ_grp_type_C, self.educ_grp_type_D ])
def setUpTestData(cls): today = datetime.date.today() cls.academic_year = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) cls.previous_academic_year = AcademicYearFactory( start_date=today.replace(year=today.year - 1), end_date=today - datetime.timedelta(days=1), year=today.year - 1) cls.type_training = EducationGroupTypeFactory( category=education_group_categories.TRAINING) cls.type_minitraining = EducationGroupTypeFactory( category=education_group_categories.MINI_TRAINING) cls.type_group = EducationGroupTypeFactory( category=education_group_categories.GROUP) oph_entity = EntityFactory() envi_entity = EntityFactory() cls.education_group_edph2 = EducationGroupYearFactory( acronym='EDPH2', academic_year=cls.academic_year, partial_acronym='EDPH2_SCS', education_group_type=cls.type_group, management_entity=envi_entity) cls.education_group_arke2a = EducationGroupYearFactory( acronym='ARKE2A', academic_year=cls.academic_year, education_group_type=cls.type_training, management_entity=oph_entity) cls.education_group_hist2a = EducationGroupYearFactory( acronym='HIST2A', academic_year=cls.academic_year, education_group_type=cls.type_group, management_entity=oph_entity) cls.education_group_arke2a_previous_year = EducationGroupYearFactory( acronym='ARKE2A', academic_year=cls.previous_academic_year, education_group_type=cls.type_training, management_entity=oph_entity) cls.oph_entity_v = EntityVersionFactory(entity=oph_entity, parent=envi_entity, end_date=None) cls.envi_entity_v = EntityVersionFactory(entity=envi_entity, end_date=None) cls.user = PersonFactory().user cls.user.user_permissions.add( Permission.objects.get(codename="can_access_education_group")) cls.form_class = EducationGroupFilter()._meta.form cls.url = reverse("education_groups")
def education_groups(request): person = get_object_or_404(Person, user=request.user) filter_form = EducationGroupFilter(request.GET or None) objects_qs = EducationGroupYear.objects.none() if filter_form.is_valid(): objects_qs = filter_form.qs if not objects_qs.exists(): messages.add_message(request, messages.WARNING, _('No result!')) # FIXME: use ordering args in filter_form! Remove xls_order_col/xls_order property if request.GET.get('xls_status') == "xls": return create_xls( request.user, objects_qs, _get_filter_keys(filter_form.form), { ORDER_COL: request.GET.get('xls_order_col'), ORDER_DIRECTION: request.GET.get('xls_order') }) # FIXME: use ordering args in filter_form! Remove xls_order_col/xls_order property if request.GET.get('xls_status') == "xls_administrative": return create_xls_administrative_data( request.user, objects_qs, _get_filter_keys(filter_form.form), { ORDER_COL: request.GET.get('xls_order_col'), ORDER_DIRECTION: request.GET.get('xls_order') }) object_list_paginated = paginate_queryset(objects_qs, request.GET) if request.is_ajax(): serializer = EducationGroupSerializer(object_list_paginated, context={'request': request}, many=True) return JsonResponse({'object_list': serializer.data}) context = { 'form': filter_form.form, 'object_list': object_list_paginated, 'object_list_count': objects_qs.count(), 'enums': education_group_categories, 'person': person } return render(request, "education_group/search.html", context)
def education_groups(request): if request.GET: form = EducationGroupFilter(request.GET) else: current_academic_year = mdl.academic_year.current_academic_year() form = EducationGroupFilter(initial={'academic_year': current_academic_year, 'category': education_group_categories.TRAINING}) object_list = None if form.is_valid(): object_list = form.get_object_list() if not _check_if_display_message(request, object_list): object_list = None context = { 'form': form, 'object_list': object_list, 'experimental_phase': True } return layout.render(request, "education_groups.html", context)
def test_should_always_order_by_id(self): search_parameters = QueryDict(mutable=True) search_parameters["ordering"] = "title" filter_form = EducationGroupFilter(search_parameters) self.assertIn("id", filter_form.qs.query.order_by)
def setUpTestData(cls): cls.current_academic_year = create_current_academic_year() cls.previous_academic_year = AcademicYearFactory( year=cls.current_academic_year.year - 1) cls.type_training = EducationGroupTypeFactory( category=education_group_categories.TRAINING) cls.type_minitraining = EducationGroupTypeFactory( category=education_group_categories.MINI_TRAINING) cls.type_group = EducationGroupTypeFactory( category=education_group_categories.GROUP) oph_entity = EntityFactory() envi_entity = EntityFactory() cls.education_group_edph2 = EducationGroupYearFactory( acronym='EDPH2', academic_year=cls.current_academic_year, partial_acronym='EDPH2_SCS', education_group__start_year=cls.previous_academic_year, education_group_type=cls.type_group, management_entity=envi_entity, title=TITLE_EDPH2) cls.education_group_edph3 = EducationGroupYearFactory( acronym='EDPH3', academic_year=cls.current_academic_year, partial_acronym='EDPH3_SCS', education_group__start_year=cls.previous_academic_year, education_group_type=cls.type_training, management_entity=envi_entity, title=TITLE_EDPH3) cls.education_group_arke2a = EducationGroupYearFactory( acronym='ARKE2A', academic_year=cls.current_academic_year, education_group__start_year=cls.previous_academic_year, education_group_type=cls.type_training, management_entity=oph_entity) cls.education_group_hist2a = EducationGroupYearFactory( acronym='HIST2A', academic_year=cls.current_academic_year, education_group__start_year=cls.previous_academic_year, education_group_type=cls.type_group, management_entity=oph_entity) cls.education_group_arke2a_previous_year = EducationGroupYearFactory( acronym='ARKE2A', academic_year=cls.previous_academic_year, education_group__start_year=cls.previous_academic_year, education_group_type=cls.type_training, management_entity=oph_entity) cls.oph_entity_v = EntityVersionFactory(entity=oph_entity, parent=envi_entity, end_date=None) cls.envi_entity_v = EntityVersionFactory(entity=envi_entity, end_date=None) cls.user = PersonFactory().user cls.user.user_permissions.add( Permission.objects.get(codename="can_access_education_group")) cls.form_class = EducationGroupFilter()._meta.form cls.url = reverse("education_groups")