def get_xml_nodes(self, domain, fixture_id, user_id, locations_queryset): data_fields = get_location_data_fields(domain) all_types = LocationType.objects.filter(domain=domain).values_list( 'code', flat=True ) location_type_attrs = ['{}_id'.format(t) for t in all_types if t is not None] attrs_to_index = ['@{}'.format(attr) for attr in location_type_attrs] attrs_to_index.extend(['@id', '@type', 'name']) return [get_index_schema_node(fixture_id, attrs_to_index), self._get_fixture_node(fixture_id, user_id, locations_queryset, location_type_attrs, data_fields)]
def __call__(self, restore_state): if not toggles.RELATED_LOCATIONS.enabled(restore_state.domain): return [] user = restore_state.restore_user changed, location_relations = self._query_users_related_locations(user, restore_state.last_sync_log) if not changed: return [] xml_node = self._users_related_locations_for_xml(user, location_relations) return [get_index_schema_node(self.id, ['@id']), xml_node]
def get_xml_nodes(self, fixture_id, restore_user, locations_queryset, data_fields): all_types = LocationType.objects.filter(domain=restore_user.domain).values_list( 'code', flat=True ) location_type_attrs = ['{}_id'.format(t) for t in all_types if t is not None] attrs_to_index = ['@{}'.format(attr) for attr in location_type_attrs] attrs_to_index.extend(_get_indexed_field_name(field.slug) for field in data_fields if field.index_in_fixture) attrs_to_index.extend(['@id', '@type', 'name']) return [get_index_schema_node(fixture_id, attrs_to_index), self._get_fixture_node(fixture_id, restore_user, locations_queryset, location_type_attrs, data_fields)]
def __call__(self, restore_state): if not toggles.RELATED_LOCATIONS.enabled(restore_state.domain): return [] user = restore_state.restore_user changed, location_relations = self._query_users_related_locations( user, restore_state.last_sync_log) if not changed: return [] xml_node = self._users_related_locations_for_xml( user, location_relations) return [get_index_schema_node(self.id, ['@id']), xml_node]
def get_xml_nodes(self, fixture_id, restore_user, locations_queryset, data_fields): all_types = LocationType.objects.filter(domain=restore_user.domain).values_list( 'code', flat=True ) location_type_attrs = ['{}_id'.format(t) for t in all_types if t is not None] attrs_to_index = ['@{}'.format(attr) for attr in location_type_attrs] attrs_to_index.extend(_get_indexed_field_name(field.slug) for field in data_fields if field.index_in_fixture) attrs_to_index.extend(['@id', '@type', 'name']) return [get_index_schema_node(fixture_id, attrs_to_index), self._get_fixture_node(fixture_id, restore_user, locations_queryset, location_type_attrs, data_fields)]
def __call__(self, restore_state): indexed = ( not restore_state.params.openrosa_version or restore_state.params.openrosa_version >= LooseVersion(OPENROSA_VERSION_MAP['INDEXED_PRODUCTS_FIXTURE']) ) fixture_nodes = self._get_fixture_items(restore_state, indexed) if not fixture_nodes: return [] if not indexed: # Don't include index schema when openrosa version is specified and below 2.1 return fixture_nodes else: schema_node = get_index_schema_node(self.id, ['@id', 'code', 'program_id', 'category']) return [schema_node] + fixture_nodes
def __call__(self, restore_state): indexed = (not restore_state.params.openrosa_version or restore_state.params.openrosa_version >= LooseVersion( OPENROSA_VERSION_MAP['INDEXED_PRODUCTS_FIXTURE'])) data_fn = partial(self._get_fixture_items, restore_state, indexed) cache_prefix = PRODUCT_FIXTURE_BUCKET_INDEXED if indexed else PRODUCT_FIXTURE_BUCKET fixture_nodes = get_or_cache_global_fixture(restore_state, cache_prefix, self.id, data_fn) if not indexed: # Don't include index schema when openrosa version is specified and below 2.1 return fixture_nodes else: schema_node = get_index_schema_node( self.id, ['@id', 'code', 'program_id', 'category']) return [schema_node] + fixture_nodes
def __call__(self, restore_state): restore_user = restore_state.restore_user def get_products(): return sorted( Product.by_domain(restore_user.domain), key=lambda product: product.code ) fixture_nodes = simple_fixture_generator( restore_user, self.id, "product", PRODUCT_FIELDS, get_products, restore_state.last_sync_log ) if not fixture_nodes: return [] if (restore_state.params.openrosa_version and restore_state.params.openrosa_version < LooseVersion(OPENROSA_VERSION_MAP['INDEXED_PRODUCTS_FIXTURE'])): # Don't include index schema when openrosa version is specified and below 2.1 return fixture_nodes else: schema_node = get_index_schema_node(self.id, ['@id', 'code', 'program_id', 'category']) fixture_nodes[0].attrib['indexed'] = 'true' return [schema_node] + fixture_nodes
def get_xml_nodes(self, fixture_id, restore_user, locations_queryset, data_fields): all_types = LocationType.objects.filter(domain=restore_user.domain).values_list( 'code', flat=True ) location_type_attrs = ['{}_id'.format(t) for t in all_types if t is not None] attrs_to_index = ['@{}'.format(attr) for attr in location_type_attrs] attrs_to_index.extend(_get_indexed_field_name(field.slug) for field in data_fields if field.index_in_fixture) attrs_to_index.extend(['@id', '@type', 'name', '@distance']) xml_nodes = self._get_fixture_node(fixture_id, restore_user, locations_queryset, location_type_attrs, data_fields) user_locations = restore_user.get_sql_locations(restore_user.domain) distance_dict = LocationRelation.relation_distance_dictionary(user_locations) child_node = xml_nodes.getchildren()[0] for grandchild_node in child_node.getchildren(): location_id = grandchild_node.get('id') if location_id in distance_dict: minimum_distance = min(six.itervalues(distance_dict[location_id])) grandchild_node.set('distance', str(minimum_distance)) return [get_index_schema_node(fixture_id, attrs_to_index), xml_nodes]
def __call__(self, restore_state): restore_user = restore_state.restore_user def get_products(): return sorted(Product.by_domain(restore_user.domain), key=lambda product: product.code) fixture_nodes = simple_fixture_generator(restore_user, self.id, "product", PRODUCT_FIELDS, get_products, restore_state.last_sync_log) if not fixture_nodes: return [] if (restore_state.params.openrosa_version and restore_state.params.openrosa_version < OPENROSA_VERSION_MAP['INDEXED_PRODUCTS_FIXTURE']): # Don't include index schema when openrosa version is specified and below 2.1 return fixture_nodes else: schema_node = get_index_schema_node( self.id, ['@id', 'code', 'program_id', 'category']) fixture_nodes[0].attrib['indexed'] = 'true' return [schema_node] + fixture_nodes