Beispiel #1
0
    def test_clear_cached_filter(self):
        key = _get_filter_key(self.user, self.url_cached)
        filter_to_cached = {'filter_a': 'ABCD', 'filter_b': 'CDEF'}
        cache.set(key, filter_to_cached)
        # Check that cache is set
        self.assertDictEqual(cache.get(key), filter_to_cached)

        # Clear fitler cache
        clear_cached_filter(self.request)
        self.assertIsNone(cache.get(key))
Beispiel #2
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        tab_lang = cache.get(get_tab_lang_keys(
            self.request.user)) or settings.LANGUAGE_CODE_FR

        acronym = self.object.acronym.lower()
        is_common = acronym.startswith('common-')
        is_specific = not is_common
        is_bachelor = self.object.is_bachelor

        is_master = acronym.endswith(('2m', '2m1'))
        is_aggregation = acronym.endswith('2a')
        is_mc = acronym.endswith('2mc')
        common_conditions = get_appropriate_common_admission_condition(
            self.object)

        class AdmissionConditionForm(forms.Form):
            text_field = forms.CharField(widget=CKEditorWidget(
                config_name='minimal'))

        admission_condition_form = AdmissionConditionForm()
        admission_condition, created = AdmissionCondition.objects.get_or_create(
            education_group_year=self.object)
        record = {}
        for section in SECTIONS_WITH_TEXT:
            record[section] = AdmissionConditionLine.objects.filter(
                admission_condition=admission_condition,
                section=section).annotate_text(tab_lang)
        context.update({
            'admission_condition_form':
            admission_condition_form,
            'can_edit_information':
            perms.is_eligible_to_edit_admission_condition(
                context['person'], context['object']),
            'info': {
                'is_specific': is_specific,
                'is_common': is_common,
                'is_bachelor': is_bachelor,
                'is_master': is_master,
                'show_components_for_agreg': is_aggregation,
                'show_components_for_agreg_and_mc': is_aggregation or is_mc,
                'show_free_text': self._show_free_text()
            },
            'admission_condition':
            admission_condition,
            'common_conditions':
            common_conditions,
            'record':
            record,
            'language': {
                'list': ["fr-be", "en"],
                'tab_lang': tab_lang
            }
        })

        return context
Beispiel #3
0
    def wrapper(user, *args, **kwargs):
        cache_key = make_notifications_cache_key(user)

        pickled_qs = cache.get(cache_key)
        if pickled_qs:
            return pickle.loads(pickled_qs)

        qs = function(user, *args, **kwargs)
        cache.set(cache_key, pickle.dumps(qs), CACHE_NOTIFICATIONS_TIMEOUT)
        return qs
Beispiel #4
0
    def test_select_ajax_case_learning_unit_year(self):
        response = self.client.post(
            self.url_select_learning_unit,
            HTTP_X_REQUESTED_WITH='XMLHttpRequest',
        )
        data_cached = cache.get(management.SELECT_CACHE_KEY)

        self.assertEquals(response.status_code, HTTPStatus.OK)
        self.assertIsInstance(data_cached, dict)
        self.assertEqual(int(data_cached['id']), self.learning_unit_year.id)
        self.assertEqual(data_cached['modelname'],
                         management.LEARNING_UNIT_YEAR)
Beispiel #5
0
    def test_select_case_education_group(self):
        response = self.client.post(
            self.url_management,
            data=self.select_data,
            HTTP_X_REQUESTED_WITH='XMLHttpRequest',
        )
        data_cached = cache.get(management.SELECT_CACHE_KEY)

        self.assertEquals(response.status_code, HTTPStatus.OK)
        self.assertIsInstance(data_cached, dict)
        self.assertEqual(int(data_cached['id']),
                         self.child_education_group_year.id)
        self.assertEqual(data_cached['modelname'],
                         management.EDUCATION_GROUP_YEAR)
Beispiel #6
0
def attach_from_cache(parent):
    selected_data = cache.get(SELECT_CACHE_KEY)
    if selected_data:
        kwargs = {'parent': parent}
        if selected_data['modelname'] == LEARNING_UNIT_YEAR:
            luy = LearningUnitYear.objects.get(pk=selected_data['id'])
            kwargs['child_leaf'] = luy
        elif selected_data['modelname'] == EDUCATION_GROUP_YEAR:
            egy = EducationGroupYear.objects.get(pk=selected_data['id'])
            kwargs['child_branch'] = egy
        new_gey = group_element_year.get_or_create_group_element_year(**kwargs)
        _clear_cache()
        return new_gey
    raise ObjectDoesNotExist
Beispiel #7
0
    def test_select_case_learning_unit_year(self):
        """In this test, we ensure that redirect is made if the request is not in AJAX """
        response = self.client.post(self.url_select_learning_unit)

        # Verify cache
        data_cached = cache.get(management.SELECT_CACHE_KEY)
        self.assertIsInstance(data_cached, dict)
        self.assertEqual(int(data_cached['id']), self.learning_unit_year.id)
        self.assertEqual(data_cached['modelname'],
                         management.LEARNING_UNIT_YEAR)

        # Verify redirection
        redirected_url = reverse('learning_unit',
                                 args=[self.learning_unit_year.id])
        self.assertRedirects(response,
                             redirected_url,
                             fetch_redirect_response=False)
Beispiel #8
0
def attach_from_cache(parent):
    selected_data = cache.get(SELECT_CACHE_KEY)
    if selected_data:
        kwargs = {'parent': parent}
        if selected_data['modelname'] == LEARNING_UNIT_YEAR:
            luy = LearningUnitYear.objects.get(pk=selected_data['id'])
            kwargs['child_leaf'] = luy
        elif selected_data['modelname'] == EDUCATION_GROUP_YEAR:
            egy = EducationGroupYear.objects.get(pk=selected_data['id'])
            if not _types_are_compatible(parent, egy):
                raise IncompatiblesTypesException(
                    errors=
                    _("You cannot attach \"%(child)s\" (type \"%(child_type)s\") "
                      "to \"%(parent)s\" (type \"%(parent_type)s\")") % {
                          'child': egy,
                          'child_type': egy.education_group_type,
                          'parent': parent,
                          'parent_type': parent.education_group_type,
                      })
            kwargs['child_branch'] = egy
        new_gey = group_element_year.get_or_create_group_element_year(**kwargs)
        _clear_cache()
        return new_gey
    raise ObjectDoesNotExist
Beispiel #9
0
def get_notifications_last_time_read_for_user(user):
    cache_key = make_notifications_timestamp_cache_key(user)
    timestamp_last_read = cache.get(cache_key)
    return datetime.datetime.fromtimestamp(
        float(timestamp_last_read)) if timestamp_last_read else None
Beispiel #10
0
 def wrapper(user, *args, **kwargs):
     cache_key = make_notifications_cache_key(user)
     if cache.get(cache_key) is not None:
         return None
     return function(user, *args, **kwargs)