Exemple #1
0
def create_education_group(request,
                           category,
                           education_group_type_pk,
                           root_id=None,
                           parent_id=None):
    parent = get_object_or_none(EducationGroupYear, pk=parent_id)
    education_group_type = get_object_or_404(EducationGroupType,
                                             pk=education_group_type_pk)

    request_cache = RequestCache(request.user, reverse('education_groups'))
    cached_data = request_cache.cached_data or {}

    academic_year = cached_data.get('academic_year')
    if not academic_year:
        cached_data['academic_year'] = starting_academic_year()

    initial_academic_year = parent.academic_year_id if parent else cached_data.get(
        'academic_year')
    form_education_group_year = FORMS_BY_CATEGORY[category](
        request.POST or None,
        parent=parent,
        user=request.user,
        education_group_type=education_group_type,
        initial={
            'academic_year': initial_academic_year
        })

    if form_education_group_year.is_valid():
        return _common_success_redirect(request, form_education_group_year,
                                        root_id)

    data = {
        "form_education_group_year":
        form_education_group_year.forms[forms.ModelForm],
        "form_education_group":
        form_education_group_year.forms[EducationGroupModelForm],
        "parent":
        parent,
        'root_pk':
        root_id,
    }

    if category == education_group_categories.TRAINING:
        data.update({
            "form_hops": form_education_group_year.hops_form,
        })

    return render(request, TEMPLATES_BY_CATEGORY.get(category), data)
Exemple #2
0
def clear_filter(request):
    path = request.POST['current_url']
    RequestCache(request.user, path).clear()
    return redirect(path)
Exemple #3
0
 def setUpTestData(cls):
     cls.user = UserFactory()
     cls.path = 'dummy_url'
     cls.request_cache = RequestCache(cls.user, cls.path)
     cls.request_data = {"name": "Axandre", "city": "City25"}
Exemple #4
0
 def test_search_education_group_cache_filter(self):
     response = self.client.get(self.url, data=FILTER_DATA)
     cached_data = RequestCache(self.user, self.url).cached_data
     self.assertEqual(cached_data, FILTER_DATA)