def dl_component_tooltip(context, key, **kwargs): title = kwargs.get('title', '') default_if_none = kwargs.get('default_if_none', '') value = kwargs.get('value', '') id = kwargs.get('id', '') volumes = {} components_initial_data = context.get('differences', {}).get('components_initial_data', {}) if components_initial_data != {}: for rec in components_initial_data.get('components', {}): if rec.get('learning_component_year').get('id') == id: volumes = rec.get('volumes') break difference = get_component_volume_css(volumes, key, default_if_none, value) or 'title="{}"'.format( _(title)) value = get_style_of_value("", "", volume_format(value)) html_id = "id='id_{}'".format(key.lower()) return mark_safe("<dl><dd {difference} {id}>{value}</dd></dl>".format( difference=difference, id=html_id, value=str(value))) return volume_format(value) if value else default_if_none
def get_component_volume_css(values, parameter, default_if_none="", value=None): if parameter in values and values[parameter] != value: return mark_safe( " data-toggle=tooltip title='{} : {}' class='{}' ".format( LABEL_VALUE_BEFORE_PROPOSAL, volume_format(values[parameter]) or default_if_none, CSS_PROPOSAL_VALUE)) return default_if_none
def _get_data(learning_unit_yr, new_line, first_data, partims=True): organization = get_organization_from_learning_unit_year(learning_unit_yr) data = [ _get_acronym(learning_unit_yr, new_line, first_data), learning_unit_yr.academic_year.name, learning_unit_yr.learning_container_year.get_container_type_display() if learning_unit_yr.learning_container_year.container_type else EMPTY_VALUE, translate_status(learning_unit_yr.status), learning_unit_yr.get_subtype_display() if learning_unit_yr.subtype else EMPTY_VALUE, learning_unit_yr.get_internship_subtype_display() if learning_unit_yr.internship_subtype else EMPTY_VALUE, volume_format(learning_unit_yr.credits), learning_unit_yr.language.name if learning_unit_yr.language else EMPTY_VALUE, learning_unit_yr.get_periodicity_display() if learning_unit_yr.periodicity else EMPTY_VALUE, get_translation(learning_unit_yr.quadrimester), get_translation(learning_unit_yr.session), learning_unit_yr.learning_container_year.common_title, learning_unit_yr.specific_title, learning_unit_yr.learning_container_year.common_title_english, learning_unit_yr.specific_title_english, _get_entity_to_display( learning_unit_yr.entities.get(entity_types.REQUIREMENT_ENTITY)), _get_entity_to_display( learning_unit_yr.entities.get(entity_types.ALLOCATION_ENTITY)), _get_entity_to_display( learning_unit_yr.entities.get( entity_types.ADDITIONAL_REQUIREMENT_ENTITY_1)), _get_entity_to_display( learning_unit_yr.entities.get( entity_types.ADDITIONAL_REQUIREMENT_ENTITY_2)), _('Yes') if learning_unit_yr.professional_integration else _('No'), organization.name if organization else EMPTY_VALUE, learning_unit_yr.campus if learning_unit_yr.campus else EMPTY_VALUE ] if partims: data.append(get_partims_as_str(learning_unit_yr.get_partims_related())) data.extend([ learning_unit_yr.learning_unit.faculty_remark, learning_unit_yr.learning_unit.other_remark, _('Yes') if learning_unit_yr.learning_container_year.team else _('No'), _('Yes') if learning_unit_yr.learning_container_year.is_vacant else _('No'), learning_unit_yr.learning_container_year. get_type_declaration_vacant_display(), learning_unit_yr.get_attribution_procedure_display(), ]) return data
def _get_data_from_initial_data(initial_data): learning_unit_yr = get_by_id(initial_data.get('learning_unit_year')['id']) requirement_entity = find_by_id(initial_data.get('entities')['REQUIREMENT_ENTITY']) allocation_entity = find_by_id(initial_data.get('entities')['ALLOCATION_ENTITY']) add1_requirement_entity = find_by_id(initial_data.get('entities')['ADDITIONAL_REQUIREMENT_ENTITY_1']) add2_requirement_entity = find_by_id(initial_data.get('entities')['ADDITIONAL_REQUIREMENT_ENTITY_2']) campus = find_campus_by_id(initial_data.get('learning_unit_year')['campus']) organization = get_organization_from_learning_unit_year(learning_unit_yr) language = find_language_by_id(initial_data.get('learning_unit_year')['language']) lu_initial = initial_data.get('learning_unit', None) luy_initial = initial_data.get('learning_unit_year', None) lcy_initial = initial_data.get('learning_container_year', None) data = [ str(_('Initial data')), luy_initial['acronym'], learning_unit_yr.academic_year.name, dict(LearningContainerYearType.choices())[lcy_initial['container_type']] if lcy_initial['container_type'] else '-', translate_status(luy_initial['status']), learning_unit_yr.get_subtype_display(), get_translation(luy_initial['internship_subtype']), volume_format(luy_initial['credits']), language.name if language else EMPTY_VALUE, dict(PERIODICITY_TYPES)[luy_initial['periodicity']] if luy_initial['periodicity'] else BLANK_VALUE, get_translation(luy_initial['quadrimester']), get_translation(luy_initial['session']), get_representing_string(lcy_initial['common_title']), get_representing_string(luy_initial['specific_title']), get_representing_string(lcy_initial['common_title_english']), get_representing_string(luy_initial['specific_title_english']), requirement_entity.most_recent_acronym if requirement_entity else BLANK_VALUE, allocation_entity.most_recent_acronym if allocation_entity else BLANK_VALUE, add1_requirement_entity.most_recent_acronym if add1_requirement_entity else BLANK_VALUE, add2_requirement_entity.most_recent_acronym if add2_requirement_entity else BLANK_VALUE, _('Yes') if luy_initial['professional_integration'] else _('No'), organization.name if organization else BLANK_VALUE, campus if campus else BLANK_VALUE, get_representing_string(lu_initial['faculty_remark']), get_representing_string(lu_initial['other_remark']), _('Yes') if lcy_initial.get('team') else _('No'), _('Yes') if lcy_initial.get('is_vacant') else _('No'), dict(vacant_declaration_type.DECLARATION_TYPE)[lcy_initial.get('type_declaration_vacant')] if lcy_initial.get( 'type_declaration_vacant') else BLANK_VALUE, dict(attribution_procedure.ATTRIBUTION_PROCEDURES)[luy_initial.get('attribution_procedure')] if luy_initial.get( 'attribution_procedure') else BLANK_VALUE, ] return _get_data_from_components_initial_data(data, initial_data)
def _get_data(learning_unit_yr, new_line, first_data, partims=True): organization = get_organization_from_learning_unit_year(learning_unit_yr) data = [ _get_acronym(learning_unit_yr, new_line, first_data), learning_unit_yr.academic_year.name, learning_unit_yr.learning_container_year.get_container_type_display() if learning_unit_yr.learning_container_year.container_type else EMPTY_VALUE, translate_status(learning_unit_yr.status), learning_unit_yr.get_subtype_display() if learning_unit_yr.subtype else EMPTY_VALUE, learning_unit_yr.get_internship_subtype_display() if learning_unit_yr.internship_subtype else EMPTY_VALUE, volume_format(learning_unit_yr.credits), learning_unit_yr.language.name if learning_unit_yr.language else EMPTY_VALUE, learning_unit_yr.get_periodicity_display() if learning_unit_yr.periodicity else EMPTY_VALUE, get_translation(learning_unit_yr.quadrimester), get_translation(learning_unit_yr.session), learning_unit_yr.learning_container_year.common_title, learning_unit_yr.specific_title, learning_unit_yr.learning_container_year.common_title_english, learning_unit_yr.specific_title_english, _get_entity_to_display(learning_unit_yr.entities.get(entity_types.REQUIREMENT_ENTITY)), _get_entity_to_display(learning_unit_yr.entities.get(entity_types.ALLOCATION_ENTITY)), _get_entity_to_display(learning_unit_yr.entities.get(entity_types.ADDITIONAL_REQUIREMENT_ENTITY_1)), _get_entity_to_display(learning_unit_yr.entities.get(entity_types.ADDITIONAL_REQUIREMENT_ENTITY_2)), _('Yes') if learning_unit_yr.professional_integration else _('No'), organization.name if organization else EMPTY_VALUE, learning_unit_yr.campus if learning_unit_yr.campus else EMPTY_VALUE] if partims: data.append(get_partims_as_str(learning_unit_yr.get_partims_related())) data.extend( [ learning_unit_yr.learning_unit.faculty_remark, learning_unit_yr.learning_unit.other_remark, _('Yes') if learning_unit_yr.learning_container_year.team else _('No'), _('Yes') if learning_unit_yr.learning_container_year.is_vacant else _('No'), learning_unit_yr.learning_container_year.get_type_declaration_vacant_display(), learning_unit_yr.get_attribution_procedure_display(), ] ) return data
def test_convert_integer_return_string_integer(self): self.assertEqual(convert.volume_format(4.0), '4')
def test_convert_float_number_return_string_number_with_two_decimals(self): self.assertEqual(convert.volume_format(4.2), '4.20')
def test_convert_none_return_empty_string(self): self.assertEqual(convert.volume_format(None), '')
def _get_data_from_initial_data(initial_data): learning_unit_yr = get_by_id(initial_data.get('learning_unit_year')['id']) requirement_entity = find_by_id( initial_data.get('entities')['REQUIREMENT_ENTITY']) allocation_entity = find_by_id( initial_data.get('entities')['ALLOCATION_ENTITY']) add1_requirement_entity = find_by_id( initial_data.get('entities')['ADDITIONAL_REQUIREMENT_ENTITY_1']) add2_requirement_entity = find_by_id( initial_data.get('entities')['ADDITIONAL_REQUIREMENT_ENTITY_2']) campus = find_campus_by_id( initial_data.get('learning_unit_year')['campus']) organization = get_organization_from_learning_unit_year(learning_unit_yr) language = find_language_by_id( initial_data.get('learning_unit_year')['language']) lu_initial = initial_data.get('learning_unit', None) luy_initial = initial_data.get('learning_unit_year', None) lcy_initial = initial_data.get('learning_container_year', None) data = [ str(_('Initial data')), luy_initial['acronym'], learning_unit_yr.academic_year.name, dict( LearningContainerYearType.choices())[lcy_initial['container_type']] if lcy_initial['container_type'] else '-', translate_status(luy_initial['status']), learning_unit_yr.get_subtype_display(), get_translation(luy_initial['internship_subtype']), volume_format(luy_initial['credits']), language.name if language else EMPTY_VALUE, dict(PERIODICITY_TYPES)[luy_initial['periodicity']] if luy_initial['periodicity'] else BLANK_VALUE, get_translation(luy_initial['quadrimester']), get_translation(luy_initial['session']), get_representing_string(lcy_initial['common_title']), get_representing_string(luy_initial['specific_title']), get_representing_string(lcy_initial['common_title_english']), get_representing_string(luy_initial['specific_title_english']), requirement_entity.most_recent_acronym if requirement_entity else BLANK_VALUE, allocation_entity.most_recent_acronym if allocation_entity else BLANK_VALUE, add1_requirement_entity.most_recent_acronym if add1_requirement_entity else BLANK_VALUE, add2_requirement_entity.most_recent_acronym if add2_requirement_entity else BLANK_VALUE, _('Yes') if luy_initial['professional_integration'] else _('No'), organization.name if organization else BLANK_VALUE, campus if campus else BLANK_VALUE, get_representing_string(lu_initial['faculty_remark']), get_representing_string(lu_initial['other_remark']), _('Yes') if lcy_initial.get('team') else _('No'), _('Yes') if lcy_initial.get('is_vacant') else _('No'), dict(vacant_declaration_type.DECLARATION_TYPE)[lcy_initial.get( 'type_declaration_vacant')] if lcy_initial.get('type_declaration_vacant') else BLANK_VALUE, dict(attribution_procedure.ATTRIBUTION_PROCEDURES)[luy_initial.get( 'attribution_procedure')] if luy_initial.get('attribution_procedure') else BLANK_VALUE, ] return _get_data_from_components_initial_data(data, initial_data)
def _get_data_from_initial_data(initial_data, proposal_comparison=False): luy_initial = initial_data.get('learning_unit_year', {}) lcy_initial = initial_data.get('learning_container_year', {}) lu_initial = initial_data.get('learning_unit', {}) if luy_initial.get('id'): learning_unit_yr = get_by_id(luy_initial.get('id')) else: learning_unit_yr = None requirement_entity = find_by_id(lcy_initial.get('requirement_entity')) allocation_entity = find_by_id(lcy_initial.get('allocation_entity')) add1_requirement_entity = find_by_id(lcy_initial.get('additional_entity_1')) add2_requirement_entity = find_by_id(lcy_initial.get('additional_entity_2')) campus = find_campus_by_id(luy_initial.get('campus')) organization = None if learning_unit_yr: organization = get_organization_from_learning_unit_year(learning_unit_yr) language = find_language_by_id(luy_initial.get('language')) if proposal_comparison: academic_year = _format_academic_year(learning_unit_yr.academic_year.name, find_academic_year_by_id(lu_initial.get('end_year')) if lu_initial.get('end_year') else None) else: academic_year = learning_unit_yr.academic_year.name data = [ str(_('Initial data')), luy_initial.get('acronym', ''), academic_year, dict(LearningContainerYearType.choices())[lcy_initial.get('container_type')] if lcy_initial.get('container_type') else BLANK_VALUE, translate_status(luy_initial.get('status')), learning_unit_yr.get_subtype_display() if learning_unit_yr and learning_unit_yr.get_subtype_display() else BLANK_VALUE, get_translation(luy_initial.get('internship_subtype')), volume_format(Decimal(luy_initial['credits'])) if luy_initial.get('credits') else BLANK_VALUE, language.name if language else BLANK_VALUE, dict(PERIODICITY_TYPES)[luy_initial['periodicity']] if luy_initial.get('periodicity') else BLANK_VALUE, get_translation(luy_initial.get('quadrimester')), get_translation(luy_initial.get('session')), get_representing_string(lcy_initial.get('common_title')), get_representing_string(luy_initial.get('specific_title')), get_representing_string(lcy_initial.get('common_title_english')), get_representing_string(luy_initial.get('specific_title_english')), requirement_entity.most_recent_acronym if requirement_entity else BLANK_VALUE, allocation_entity.most_recent_acronym if allocation_entity else BLANK_VALUE, add1_requirement_entity.most_recent_acronym if add1_requirement_entity else BLANK_VALUE, add2_requirement_entity.most_recent_acronym if add2_requirement_entity else BLANK_VALUE, _('Yes') if luy_initial.get('professional_integration') else _('No'), organization.name if organization else BLANK_VALUE, campus if campus else BLANK_VALUE, get_representing_string(lu_initial.get('faculty_remark')), get_representing_string(lu_initial.get('other_remark')), _('Yes') if lcy_initial.get('team') else _('No'), _('Yes') if lcy_initial.get('is_vacant') else _('No'), dict(vacant_declaration_type.DECLARATION_TYPE)[lcy_initial.get('type_declaration_vacant')] if lcy_initial.get( 'type_declaration_vacant') else BLANK_VALUE, dict(attribution_procedure.ATTRIBUTION_PROCEDURES)[luy_initial.get('attribution_procedure')] if luy_initial.get( 'attribution_procedure') else BLANK_VALUE, ] return _get_data_from_components_initial_data(data, initial_data)