def test_find_entities_no_values(self): l_container_year = LearningContainerYearFactory( academic_year=self.academic_years[2015]) # No link between an entity/learning_container_year, so no result no_entity = entity_container_year.find_last_entity_version_grouped_by_linktypes( learning_container_year=l_container_year) self.assertFalse(no_entity)
def test_find_entities_with_empty_link_type(self): l_container_year = LearningContainerYearFactory( academic_year=self.academic_years[2015]) # Requirement entity EntityContainerYearFactory( entity=self.entity, learning_container_year=l_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) # No link between an entity/learning_container_year, so no result no_entity = entity_container_year.find_last_entity_version_grouped_by_linktypes( learning_container_year=l_container_year, link_type=[]) self.assertFalse(no_entity)
def _change_requirement_entity_value(self, academic_year): entity_version_by_type = entity_container_year.find_last_entity_version_grouped_by_linktypes( self.learning_unit_year_full.learning_container_year) initial_status_value = entity_version_by_type.get( entity_container_year_link_type.REQUIREMENT_ENTITY).entity new_entity_value = self.learn_unit_structure.entities[2] EntityContainerYear.objects.filter( learning_container_year__learning_container=self. learning_unit_year_full.learning_container_year.learning_container, learning_container_year__academic_year=academic_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY).update( entity=new_entity_value) return initial_status_value, new_entity_value
def get_all_attributions(learning_unit_year): attributions = {} if learning_unit_year.learning_container_year: all_attributions = entity_container_year.find_last_entity_version_grouped_by_linktypes( learning_unit_year.learning_container_year) attributions['requirement_entity'] = all_attributions.get(entity_container_year_link_type.REQUIREMENT_ENTITY) attributions['allocation_entity'] = all_attributions.get(entity_container_year_link_type.ALLOCATION_ENTITY) attributions['additional_requirement_entity_1'] = \ all_attributions.get(entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1) attributions['additional_requirement_entity_2'] = \ all_attributions.get(entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2) return attributions
def get_all_attributions(learning_unit_year): attributions = {} if learning_unit_year.learning_container_year: all_attributions = entity_container_year.find_last_entity_version_grouped_by_linktypes( learning_unit_year.learning_container_year) attributions['requirement_entity'] = all_attributions.get(entity_container_year_link_type.REQUIREMENT_ENTITY) attributions['allocation_entity'] = all_attributions.get(entity_container_year_link_type.ALLOCATION_ENTITY) attributions['additional_requirement_entity_1'] = \ all_attributions.get(entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1) attributions['additional_requirement_entity_2'] = \ all_attributions.get(entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2) return attributions
def compute_form_initial_data(learning_unit_year): entities_version = find_last_entity_version_grouped_by_linktypes( learning_unit_year.learning_container_year) initial_data = { "academic_year": learning_unit_year.academic_year.id, "first_letter": learning_unit_year.acronym[0], "acronym": learning_unit_year.acronym[1:], "title": learning_unit_year.title, "title_english": learning_unit_year.title_english, "container_type": learning_unit_year.learning_container_year.container_type, "subtype": learning_unit_year.subtype, "internship_subtype": learning_unit_year.internship_subtype, "credits": learning_unit_year.credits, "periodicity": learning_unit_year.learning_unit.periodicity, "status": learning_unit_year.status, "language": learning_unit_year.learning_container_year.language, "quadrimester": learning_unit_year.quadrimester, "campus": learning_unit_year.learning_container_year.campus, "requirement_entity": entities_version.get( entity_container_year_link_type.REQUIREMENT_ENTITY), "allocation_entity": entities_version.get( entity_container_year_link_type.ALLOCATION_ENTITY), "additional_entity_1": entities_version.get( entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1), "additional_entity_2": entities_version.get( entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2) } return { key: value for key, value in initial_data.items() if value is not None }
def test_find_entities(self): work_on_year = 2015 l_container_year = LearningContainerYearFactory( academic_year=self.academic_years[work_on_year]) # Create a link between entity and container # Requirement entity EntityContainerYearFactory( entity=self.entity, learning_container_year=l_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) # Allocation entity EntityContainerYearFactory( entity=self.entity, learning_container_year=l_container_year, type=entity_container_year_link_type.ALLOCATION_ENTITY) # Find all entities entities = entity_container_year.find_last_entity_version_grouped_by_linktypes( learning_container_year=l_container_year) self.assertIsInstance(entities, dict) self.assertTrue( entity_container_year_link_type.REQUIREMENT_ENTITY in entities) self.assertTrue( entity_container_year_link_type.ALLOCATION_ENTITY in entities) self.assertFalse(entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_1 in entities) self.assertFalse(entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_2 in entities) # Find requirement entity self.assertEqual( self.entity_versions[work_on_year], entity_container_year.find_requirement_entity( learning_container_year=l_container_year)) # Find allocation entity self.assertEqual( self.entity_versions[work_on_year], entity_container_year.find_allocation_entity( learning_container_year=l_container_year)) # No additional allocation entity self.assertFalse( entity_container_year.find_all_additional_requirement_entities( learning_container_year=l_container_year))
def get_all_attributions(learning_unit_year): attributions = {} if learning_unit_year.learning_container_year: all_attributions = entity_container_year.find_last_entity_version_grouped_by_linktypes( learning_unit_year.learning_container_year) attributions['requirement_entity'] = all_attributions.get( entity_container_year_link_type.REQUIREMENT_ENTITY) attributions['allocation_entity'] = all_attributions.get( entity_container_year_link_type.ALLOCATION_ENTITY) attributions['additional_requirement_entities'] = [ all_attributions[link_type] for link_type in all_attributions if link_type not in [ entity_container_year_link_type.REQUIREMENT_ENTITY, entity_container_year_link_type.ALLOCATION_ENTITY ] ] return attributions
def _instantiate_base_learning_unit_form(learning_unit_year_instance, person): entity_version_by_type = entity_container_year.find_last_entity_version_grouped_by_linktypes( learning_unit_year_instance.learning_container_year) learning_unit_instance = learning_unit_year_instance.learning_unit if learning_unit_year_instance.subtype == learning_unit_year_subtypes.FULL: form = FullForm learning_unit_full_instance = None else: form = PartimForm learning_unit_full_instance = learning_unit_year_instance.parent.learning_unit form_args = { 'academic_year': learning_unit_year_instance.academic_year, 'learning_unit_full_instance': learning_unit_full_instance, 'learning_unit_instance': learning_unit_instance, 'data': { # Learning component year data model form 'form-TOTAL_FORMS': '2', 'form-INITIAL_FORMS': '0', 'form-MAX_NUM_FORMS': '2', 'form-0-hourly_volume_total_annual': 20, 'form-0-hourly_volume_partial_q1': 10, 'form-0-hourly_volume_partial_q2': 10, 'form-1-hourly_volume_total_annual': 20, 'form-1-hourly_volume_partial_q1': 10, 'form-1-hourly_volume_partial_q2': 10, 'acronym': learning_unit_year_instance.acronym, 'acronym_0': learning_unit_year_instance.acronym[0], 'acronym_1': learning_unit_year_instance.acronym[1:], 'subtype': learning_unit_year_instance.subtype, 'academic_year': learning_unit_year_instance.academic_year.id, 'specific_title': learning_unit_year_instance.specific_title, 'specific_title_english': learning_unit_year_instance.specific_title_english, 'credits': learning_unit_year_instance.credits, 'session': learning_unit_year_instance.session, 'quadrimester': learning_unit_year_instance.quadrimester, 'status': learning_unit_year_instance.status, 'internship_subtype': learning_unit_year_instance.internship_subtype, 'attribution_procedure': learning_unit_year_instance.attribution_procedure, 'language': learning_unit_year_instance.language.id, 'campus': learning_unit_year_instance.campus.id, 'periodicity': learning_unit_year_instance.periodicity, # Learning unit data model form 'faculty_remark': learning_unit_instance.faculty_remark, 'other_remark': learning_unit_instance.other_remark, # Learning container year data model form 'common_title': learning_unit_year_instance.learning_container_year.common_title, 'common_title_english': learning_unit_year_instance.learning_container_year. common_title_english, 'container_type': learning_unit_year_instance.learning_container_year.container_type, 'type_declaration_vacant': learning_unit_year_instance.learning_container_year. type_declaration_vacant, 'team': learning_unit_year_instance.learning_container_year.team, 'is_vacant': learning_unit_year_instance.learning_container_year.is_vacant, 'requirement_entity-entity': entity_version_by_type.get( entity_container_year_link_type.REQUIREMENT_ENTITY).id, 'allocation_entity-entity': entity_version_by_type.get( entity_container_year_link_type.ALLOCATION_ENTITY).id, 'additional_requirement_entity_1-entity': entity_version_by_type.get(entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_1).id, 'additional_requirement_entity_2-entity': entity_version_by_type.get(entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_2).id, }, 'person': person } return form(**form_args)
def _get_attributions_of_learning_unit_year(learning_unit_year): attributions = entity_container_year.find_last_entity_version_grouped_by_linktypes( learning_unit_year.learning_container_year) return {k.lower(): v.pk for k, v in attributions.items() if v is not None}