def test_search(self): result = search(id=[ self.education_group_year_1.id, self.education_group_year_2.id ]) self.assertEqual(len(result), 2) result = search(education_group_type=self.education_group_year_2. education_group_type) self.assertEqual(result.first().education_group_type, self.education_group_year_2.education_group_type) result = search(education_group_type=[ self.education_group_type_training, self.education_group_type_minitraining ]) self.assertEqual(len(result), 4) OfferEnrollmentFactory( education_group_year=self.education_group_year_2, enrollment_state=offer_enrollment_state.SUBSCRIBED) OfferEnrollmentFactory( education_group_year=self.education_group_year_2, enrollment_state=offer_enrollment_state.PENDING) result = search(enrollment_states=[offer_enrollment_state.SUBSCRIBED]) self.assertEqual(len(result), 1)
def test_search(self): result = search(id=[ self.education_group_year_1.id, self.education_group_year_2.id ]) self.assertEqual(len(result), 2) result = search(education_group_type=self.education_group_year_2. education_group_type) self.assertEqual(result.first().education_group_type, self.education_group_year_2.education_group_type) result = search(education_group_type=[ self.education_group_type_training, self.education_group_type_minitraining ]) self.assertEqual(len(result), 3)
def _convert_parent_ids_to_instances(root_ids_by_object_id): flat_root_ids = list(set(itertools.chain.from_iterable(root_ids_by_object_id.values()))) map_instance_by_id = {obj.id: obj for obj in education_group_year.search(id=flat_root_ids)} return { obj_id: sorted([map_instance_by_id[parent_id] for parent_id in parents], key=lambda obj: obj.acronym) for obj_id, parents in root_ids_by_object_id.items() }
def _convert_parent_ids_to_instances(root_ids_by_object_id): flat_root_ids = _flatten_list_of_lists(root_ids_by_object_id.values()) map_instance_by_id = {obj.id: obj for obj in education_group_year.search(id=flat_root_ids)} return { obj_id: sorted([map_instance_by_id[parent_id] for parent_id in parents], key=lambda obj: obj.acronym) for obj_id, parents in root_ids_by_object_id.items() }
def _convert_parent_ids_to_instances(root_ids_by_object_id): flat_root_ids = list( set(itertools.chain.from_iterable(root_ids_by_object_id.values()))) map_instance_by_id = { obj.id: obj for obj in education_group_year.search(id=flat_root_ids) } return { obj_id: sorted([map_instance_by_id[parent_id] for parent_id in parents], key=lambda obj: obj.acronym) for obj_id, parents in root_ids_by_object_id.items() }
def get_object_list(self): clean_data = { key: value for key, value in self.cleaned_data.items() if value is not None } result = education_group_year.search(**clean_data) if clean_data.get('requirement_entity_acronym'): result = _get_filter_entity_management( result, clean_data['requirement_entity_acronym'], clean_data.get('with_entity_subordinated', False)) # TODO User should choice the order return result.order_by('acronym')
def get_object_list(self): clean_data = { key: value for key, value in self.cleaned_data.items() if value is not None } entity_versions_prefetch = models.Prefetch('entity__entityversion_set', to_attr='entity_versions') offer_year_entity_prefetch = models.Prefetch('offeryearentity_set', queryset=offer_year_entity.search(type=offer_year_entity_type.ENTITY_MANAGEMENT)\ .prefetch_related(entity_versions_prefetch), to_attr='offer_year_entities') if clean_data.get('requirement_entity_acronym'): clean_data['id'] = _get_filter_entity_management( clean_data['requirement_entity_acronym'], clean_data.get('with_entity_subordinated', False)) education_groups = education_group_year.search( **clean_data).prefetch_related(offer_year_entity_prefetch) return [ _append_entity_management(education_group) for education_group in education_groups ]
def get_object_list(self): clean_data = { key: value for key, value in self.cleaned_data.items() if value is not None } offer_year_entity_prefetch = models.Prefetch( 'offeryearentity_set', queryset=offer_year_entity.search(type=offer_year_entity_type.ENTITY_MANAGEMENT)\ .prefetch_related( models.Prefetch('entity__entityversion_set', to_attr='entity_versions') ), to_attr='offer_year_entities' ) if clean_data.get('entity_management'): clean_data['id'] = _get_filter_entity_management( clean_data['entity_management']) education_groups = education_group_year.search(**clean_data)[:MAX_RECORDS + 1]\ .prefetch_related(offer_year_entity_prefetch) return [ _append_entity_management(education_group) for education_group in education_groups ]