def is_service_course(learning_unit_yr): entity_version = learning_unit_yr.entities['REQUIREMENT_ENTITY'] entity_container_yr = mdl_entity_container_year.find_requirement_entity( learning_unit_yr.learning_container_year) enti = mdl_entity_version.find_parent_faculty_version( entity_version, learning_unit_yr.learning_container_year.academic_year) if enti is None and entity_container_yr: enti = entity_container_yr.entity else: enti = enti.entity requirement_entity = mdl_entity_version.get_last_version(enti) entity_containter_yr_allocation = mdl_entity_container_year.find_allocation_entity( learning_unit_yr.learning_container_year) if entity_containter_yr_allocation: allocation_entity = mdl_entity_version.get_last_version( entity_containter_yr_allocation.entity) for entity_descendant in requirement_entity.find_descendants( learning_unit_yr.academic_year.start_date): if entity_descendant == allocation_entity: return False return True
def test_find_latest_requirment_entity(self): work_on_year = 2016 # Change version in order to have multiple version during the year self.entity_versions[work_on_year].end_date = datetime.datetime( work_on_year, 3, 30) self.entity_versions[work_on_year].save() lastest_entity_version = EntityVersionFactory( entity=self.entity, parent=None, acronym="Entity V_{}_3".format(work_on_year), start_date=datetime.datetime(work_on_year, 8, 1), end_date=None) EntityVersionFactory(entity=self.entity, parent=None, acronym="Entity V_{}_2".format(work_on_year), start_date=datetime.datetime(work_on_year, 4, 1), end_date=datetime.datetime(work_on_year, 7, 30)) 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) # Find requirement entity requirement_entity_found = entity_container_year.find_requirement_entity( learning_container_year=l_container_year) self.assertEqual(lastest_entity_version, requirement_entity_found)
def can_delete_learning_unit_year(person, learning_unit_year): # Check person_entity linked requirement_entity_version = entity_container_year.find_requirement_entity( learning_unit_year.learning_container_year) entities_linked = person_entity.find_entities_by_person(person) if not requirement_entity_version or requirement_entity_version.entity not in entities_linked: return False return _can_delete_learning_unit_year_according_type( person.user, learning_unit_year)
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 is_service_course(academic_year, requirement_entity_version, learning_container_year, entity_parent): entity_container_yr_allocation = entity_container_year.find_allocation_entity(learning_container_year) if entity_container_yr_allocation == requirement_entity_version: return False elif entity_container_yr_allocation: entity_container_yr_requirement = entity_container_year.find_requirement_entity(learning_container_year) if not entity_parent and entity_container_yr_requirement: entity_parent = entity_container_yr_requirement.entity else: entity_parent = entity_parent.entity allocation_entity = entity_version.get_last_version(entity_container_yr_allocation.entity) requirement_entity = entity_version.get_last_version(entity_parent) if allocation_entity in requirement_entity.find_descendants(academic_year.start_date): return False return True