コード例 #1
0
def learning_unit_comparison(request, learning_unit_year_id):
    learning_unit_yr = get_object_or_404(
        mdl.learning_unit_year.LearningUnitYear.objects.all().select_related(
            'learning_unit', 'learning_container_year'),
        pk=learning_unit_year_id)
    context = get_learning_unit_comparison_context(learning_unit_yr)

    previous_academic_yr = mdl.academic_year.find_academic_year_by_year(
        learning_unit_yr.academic_year.year - 1)
    previous_lu = _get_learning_unit_year(previous_academic_yr,
                                          learning_unit_yr)
    previous_values = compare_learning_unit_years(learning_unit_yr,
                                                  previous_lu)
    previous_lcy_values = compare_learning_container_years(
        learning_unit_yr.learning_container_year,
        previous_lu.learning_container_year)

    next_academic_yr = mdl.academic_year.find_academic_year_by_year(
        learning_unit_yr.academic_year.year + 1)
    next_lu = _get_learning_unit_year(next_academic_yr, learning_unit_yr)
    next_values = compare_learning_unit_years(learning_unit_yr, next_lu)
    next_lcy_values = compare_learning_container_years(
        learning_unit_yr.learning_container_year,
        next_lu.learning_container_year)
    previous_context = get_learning_unit_comparison_context(previous_lu)
    next_context = get_learning_unit_comparison_context(next_lu)

    if _has_changed(context, next_context, previous_context,
                    'learning_container_year_partims'):
        context.update({
            'partims': {
                'prev':
                get_partims_as_str(
                    previous_context.get('learning_container_year_partims')),
                'current':
                get_partims_as_str(
                    context.get('learning_container_year_partims')),
                'next':
                get_partims_as_str(
                    next_context.get('learning_container_year_partims'))
            }
        })

    context.update({
        'previous_values':
        previous_values,
        'previous_academic_yr':
        previous_academic_yr,
        'next_academic_yr':
        next_academic_yr,
        'next_values':
        next_values,
        'fields':
        get_keys(list(previous_values.keys()), list(next_values.keys())),
        'entity_changes':
        _get_changed_organization(context, previous_context, next_context),
        'fields_lcy':
        get_keys(list(previous_lcy_values.keys()),
                 list(next_lcy_values.keys())),
        'previous_lcy_values':
        previous_lcy_values,
        'next_lcy_values':
        next_lcy_values,
        'components_comparison':
        get_components_changes(previous_context['components'],
                               context['components'],
                               next_context['components'])
    })
    return layout.render(request, "learning_unit/comparison.html", context)
コード例 #2
0
ファイル: test_comparison.py プロジェクト: kelvinninja1/osis
 def test_get_keys(self):
     self.assertCountEqual(get_keys(['a1', 'c3'], ['a1', 'b2', 'c1']),
                           ['a1', 'b2', 'c1', 'c3'])
コード例 #3
0
ファイル: learning_unit.py プロジェクト: kelvinninja1/osis
def learning_unit_comparison(request, learning_unit_year_id):
    learning_unit_yr = get_object_or_404(
        mdl.learning_unit_year.LearningUnitYear.objects.all().select_related(
            'learning_unit', 'learning_container_year'),
        pk=learning_unit_year_id)
    context = get_learning_unit_comparison_context(learning_unit_yr)

    previous_academic_yr = mdl.academic_year.find_academic_year_by_year(
        learning_unit_yr.academic_year.year - 1)
    previous_lu = _get_learning_unit_year(previous_academic_yr,
                                          learning_unit_yr)
    if previous_lu:
        previous_values = compare_learning_unit_years(learning_unit_yr,
                                                      previous_lu)
        previous_lcy_values = compare_learning_container_years(
            learning_unit_yr.learning_container_year,
            previous_lu.learning_container_year)
        previous_context = get_learning_unit_comparison_context(previous_lu)
    else:
        previous_values, previous_lcy_values, previous_context = {}, {}, {}

    next_academic_yr = mdl.academic_year.find_academic_year_by_year(
        learning_unit_yr.academic_year.year + 1)
    next_lu = _get_learning_unit_year(next_academic_yr, learning_unit_yr)
    if next_lu:
        next_values = compare_learning_unit_years(learning_unit_yr, next_lu)
        next_lcy_values = compare_learning_container_years(
            learning_unit_yr.learning_container_year,
            next_lu.learning_container_year)
        next_context = get_learning_unit_comparison_context(next_lu)
    else:
        next_values, next_lcy_values, next_context = {}, {}, {}

    if (previous_lu or next_lu) and \
            _has_changed(context, next_context, previous_context, 'learning_container_year_partims'):
        context.update({
            'partims': {
                'prev':
                get_partims_as_str(
                    previous_context.get('learning_container_year_partims',
                                         {})),
                'current':
                get_partims_as_str(
                    context.get('learning_container_year_partims')),
                'next':
                get_partims_as_str(
                    next_context.get('learning_container_year_partims', {})),
            }
        })

        context.update({
            'previous_values':
            previous_values,
            'previous_academic_yr':
            previous_academic_yr,
            'next_academic_yr':
            next_academic_yr,
            'next_values':
            next_values,
            'fields':
            get_keys(list(previous_values.keys()), list(next_values.keys())),
            'entity_changes':
            _get_changed_organization(context, previous_context, next_context),
            'fields_lcy':
            get_keys(list(previous_lcy_values.keys()),
                     list(next_lcy_values.keys())),
            'previous_lcy_values':
            previous_lcy_values,
            'next_lcy_values':
            next_lcy_values,
            'components_comparison':
            get_components_changes(previous_context.get('components', {}),
                                   context.get('components', {}),
                                   next_context.get('components', {})),
            'previous_lu':
            previous_lu,
            'next_lu':
            next_lu,
        })
        _add_warnings_for_inexisting_luy(request, next_academic_yr, next_lu)
        _add_warnings_for_inexisting_luy(request, previous_academic_yr,
                                         previous_lu)
        return render(request, "learning_unit/comparison.html", context)
    else:
        display_error_messages(
            request,
            _('Comparison impossible! No learning unit to compare to'))
        return HttpResponseRedirect(
            reverse('learning_unit', args=[learning_unit_year_id]))