def test_generate_xls_data_with_no_data(self, mock_generate_xls): qs_empty = EducationGroupYear.objects.none() create_xls_administrative_data(self.user, qs_empty, None, { ORDER_COL: None, ORDER_DIRECTION: None }) expected_argument = _generate_xls_administrative_data_build_parameter( [], self.user) mock_generate_xls.assert_called_with(expected_argument, None)
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 _create_xls_administrative_data(view_obj, context, **response_kwargs): user = view_obj.request.user egys = context["filter"].qs filters = _get_filter(context["form"]) # FIXME: use ordering args in filter_form! Remove xls_order_col/xls_order property order = { ORDER_COL: view_obj.request.GET.get('xls_order_col'), ORDER_DIRECTION: view_obj.request.GET.get('xls_order') } return create_xls_administrative_data(user, egys, filters, order)
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)