Ejemplo n.º 1
0
def get_learning_container_year_comparison_context(initial_data,
                                                   learning_unit_year):
    initial_learning_container_year = deepcopy(
        learning_unit_year.learning_container_year)
    _reinitialize_model(initial_learning_container_year,
                        initial_data["learning_container_year"])
    learning_container_year_fields = []
    for field in FIELDS_FOR_LEARNING_CONTAINER_YR_COMPARISON:
        if getattr(initial_learning_container_year, field) != getattr(
                learning_unit_year.learning_container_year, field):
            field_name = learning_unit_year.learning_container_year._meta.get_field(
                field).verbose_name
            if field == 'type_declaration_vacant':
                initial = _get_value_from_enum(
                    DECLARATION_TYPE,
                    getattr(initial_learning_container_year, field))
                new_value = _get_value_from_enum(
                    DECLARATION_TYPE,
                    getattr(learning_unit_year.learning_container_year, field))
            else:
                initial = getattr(initial_learning_container_year, field)
                new_value = getattr(learning_unit_year.learning_container_year,
                                    field)
            learning_container_year_fields.append(
                [field_name, initial, new_value])
    return learning_container_year_fields
Ejemplo n.º 2
0
def get_learning_unit_year_comparison_context(initial_data,
                                              learning_unit_year):
    initial_learning_unit_year = deepcopy(learning_unit_year)
    _reinitialize_model(initial_learning_unit_year,
                        initial_data["learning_unit_year"])
    learning_unit_year_fields = []
    for field in FIELDS_FOR_LEARNING_UNIT_YR_COMPARISON:
        if getattr(initial_learning_unit_year, field) != getattr(
                learning_unit_year, field):
            field_name = learning_unit_year._meta.get_field(field).verbose_name
            if field == 'periodicity':
                initial = _get_value_from_enum(
                    PERIODICITY_TYPES,
                    getattr(initial_learning_unit_year, field))
                new_value = _get_value_from_enum(
                    PERIODICITY_TYPES, getattr(learning_unit_year, field))
            elif field == 'attribution_procedure':
                initial = _get_value_from_enum(
                    ATTRIBUTION_PROCEDURES,
                    getattr(initial_learning_unit_year, field))
                new_value = _get_value_from_enum(
                    ATTRIBUTION_PROCEDURES, getattr(learning_unit_year, field))
            else:
                initial = getattr(initial_learning_unit_year, field)
                new_value = getattr(learning_unit_year, field)
            learning_unit_year_fields.append([field_name, initial, new_value])
    return initial_learning_unit_year, learning_unit_year_fields
Ejemplo n.º 3
0
def get_learning_unit_context(learning_unit_year):
    learning_unit_year_fields = {}
    for field in FIELDS_FOR_LEARNING_UNIT_YR_COMPARISON:
        field_name = learning_unit_year._meta.get_field(field).verbose_name
        if field == 'periodicity':
            value = _get_value_from_enum(PERIODICITY_TYPES, getattr(learning_unit_year, field))
        elif field == 'attribution_procedure':
            value = _get_value_from_enum(ATTRIBUTION_PROCEDURES, getattr(learning_unit_year, field))
        else:
            value = getattr(learning_unit_year, field)
        learning_unit_year_fields[field_name] = value
    return learning_unit_year_fields
Ejemplo n.º 4
0
def learning_unit_proposal_comparison(request, learning_unit_year_id):
    learning_unit_year = get_object_or_404(
        LearningUnitYear.objects.all().select_related(
            'learning_unit', 'learning_container_year', 'campus',
            'campus__organization'),
        pk=learning_unit_year_id)
    initial_data = proposal_learning_unit.find_by_learning_unit_year(
        learning_unit_year).initial_data
    initial_learning_unit_year, learning_unit_year_fields = get_learning_unit_year_comparison_context(
        initial_data, learning_unit_year)
    components = get_components_identification(learning_unit_year)
    components_list = []
    for component in components['components']:
        volumes = get_volumes_comparison_context(component, initial_data)
        components_list.append([
            _get_value_from_enum(LEARNING_COMPONENT_YEAR_TYPES,
                                 component['learning_component_year'].type),
            volumes
        ])
    context = {
        'learning_unit_year': learning_unit_year,
        'learning_container_year_fields': get_learning_container_year_comparison_context(
            initial_data,
            learning_unit_year
        ),
        'campus': [
            learning_unit_year._meta.get_field('campus').verbose_name,
            initial_learning_unit_year.campus.name,
            learning_unit_year.campus.name] \
            if initial_learning_unit_year.campus.name != learning_unit_year.campus.name else [],
        'entities_fields': get_all_entities_comparison_context(initial_data, learning_unit_year),
        'learning_unit_year_fields': learning_unit_year_fields,
        'components': components_list
    }
    return render(request, "learning_unit/proposal_comparison.html", context)
Ejemplo n.º 5
0
def reinitialize_learning_unit_year(components_list, context, initial_data,
                                    learning_unit_year):
    initial_data = proposal_learning_unit.find_by_learning_unit_year(
        learning_unit_year).initial_data
    _reinitialize_model(learning_unit_year, initial_data["learning_unit_year"])
    _reinitialize_model(learning_unit_year.learning_container_year,
                        initial_data["learning_container_year"])
    _reinitialize_components(initial_data["learning_component_years"] or {})
    for component in initial_data['learning_component_years']:
        volumes = {
            _('Volume total annual'):
            component['hourly_volume_total_annual'] or 0,
            _('Planned classes'):
            component['planned_classes'] or 0,
            _('Volume Q1'):
            component['hourly_volume_partial_q1'] or 0,
            _('Volume Q2'):
            component['hourly_volume_partial_q2'] or 0,
            _('Requirement entity'):
            component['repartition_volume_requirement_entity'] or 0,
            _('Additional requirement entity 1'):
            component['repartition_volume_additional_entity_1'] or 0,
            _('Additional requirement entity 2'):
            component['repartition_volume_additional_entity_2'] or 0
        }
        components_list[_get_value_from_enum(LEARNING_COMPONENT_YEAR_TYPES,
                                             component['type'])] = volumes
    context['components'] = components_list
    return initial_data
Ejemplo n.º 6
0
def get_learning_container_year_context(learning_unit_year):
    learning_container_year_fields = {}
    for field in FIELDS_FOR_LEARNING_CONTAINER_YR_COMPARISON:
        field_name = learning_unit_year.learning_container_year._meta.get_field(field).verbose_name
        if field == 'type_declaration_vacant':
            value = _get_value_from_enum(DECLARATION_TYPE, getattr(learning_unit_year.learning_container_year, field))
        else:
            value = getattr(learning_unit_year.learning_container_year, field)
        learning_container_year_fields[field_name] = value
    return learning_container_year_fields
Ejemplo n.º 7
0
def get_component_values(components, components_list):
    for component in components['components']:
        volumes = {
            _('Volume total annual'): component['volumes'][VOLUME_TOTAL] or 0,
            _('Planned classes'): component['volumes'][PLANNED_CLASSES] or 0,
            _('Volume Q1'): component['volumes'][VOLUME_Q1] or 0,
            _('Volume Q2'): component['volumes'][VOLUME_Q2] or 0,
            _('Requirement entity'): component['volumes'][VOLUME_REQUIREMENT_ENTITY] or 0,
            _('Additional requirement entity 1'): component['volumes'][VOLUME_ADDITIONAL_REQUIREMENT_ENTITY_1] or 0,
            _('Additional requirement entity 2'): component['volumes'][VOLUME_ADDITIONAL_REQUIREMENT_ENTITY_2] or 0
        }
        components_list[_get_value_from_enum(LEARNING_COMPONENT_YEAR_TYPES,
                                             component['learning_component_year'].type)] = volumes
Ejemplo n.º 8
0
def get_full_context(learning_unit_year):
    context = {'learning_unit_year': learning_unit_year}
    initial_data = None
    components_list = {}
    if proposal_learning_unit.is_learning_unit_year_in_proposal(
            learning_unit_year):
        initial_data = reinitialize_learning_unit_year(components_list,
                                                       context, initial_data,
                                                       learning_unit_year)
    context['learning_unit_year_fields'] = get_learning_unit_context(
        learning_unit_year)
    context[
        'learning_container_year_fields'] = get_learning_container_year_context(
            learning_unit_year)
    context['campus'] = learning_unit_year.campus.name
    context['learning_container_year_partims'] = [
        partim.subdivision
        for partim in learning_unit_year.get_partims_related()
    ]
    context['entities_fields'] = get_entities_context(initial_data,
                                                      learning_unit_year)
    if 'components' not in context:
        components = get_components_identification(learning_unit_year)
        for component in components['components']:
            volumes = {
                _('Volume total annual'): component['volumes']['VOLUME_TOTAL']
                or 0,
                _('Planned classes'): component['volumes']['PLANNED_CLASSES']
                or 0,
                _('Volume Q1'): component['volumes']['VOLUME_Q1'] or 0,
                _('Volume Q2'): component['volumes']['VOLUME_Q2'] or 0
            }
            components_list[_get_value_from_enum(
                LEARNING_COMPONENT_YEAR_TYPES,
                component['learning_component_year'].type)] = volumes
        context['components'] = components_list
    return context