コード例 #1
0
def extract_child_from_cache(parent, user):
    selected_data = ElementCache(user).cached_data
    if not selected_data:
        raise ObjectDoesNotExist

    kwargs = {'parent': parent}
    if selected_data['modelname'] == LEARNING_UNIT_YEAR:
        kwargs['child_leaf'] = LearningUnitYear.objects.get(
            pk=selected_data['id'])

    elif selected_data['modelname'] == EDUCATION_GROUP_YEAR:
        kwargs['child_branch'] = EducationGroupYear.objects.get(
            pk=selected_data['id'])

    if selected_data.get('source_link_id'):
        kwargs['source_link'] = GroupElementYear.objects.select_related('parent') \
            .get(pk=selected_data['source_link_id'])

    return kwargs
コード例 #2
0
    def get_redirect_url(self, *args, **kwargs):
        self.pattern_name = 'group_element_year_create'

        try:
            perms.can_change_education_group(self.request.user,
                                             self.education_group_year)
        except PermissionDenied as e:
            display_warning_messages(self.request, str(e))

        cached_data = ElementCache(self.request.user).cached_data

        if cached_data:

            action_from_cache = cached_data.get('action')

            if action_from_cache == ElementCache.ElementCacheAction.CUT.value:
                kwargs['group_element_year_id'] = fetch_source_link(
                    self.request.GET, self.request.user).id
                self.pattern_name = 'group_element_year_move'

        return super().get_redirect_url(*args, **kwargs)