def _row_generator(include_consumption=include_consumption): query = self.base_query.filter(location_type=location_type) for loc in query: model_data, uncategorized_data = self.data_model.get_model_and_uncategorized( loc.metadata) row_data = { 'location_id': loc.location_id, 'site_code': loc.site_code, 'name': loc.name, 'parent_code': loc.parent.site_code if loc.parent else '', 'external_id': loc.external_id, 'latitude': loc.latitude or '', 'longitude': loc.longitude or '', 'do_delete': '', } row = [ row_data[attr] for attr in LOCATION_SHEET_HEADERS_BASE.keys() ] for field in self.data_model.get_fields(): row.append(model_data.get(field.slug, '')) if include_consumption: consumption_data = self.get_consumption(loc) row.extend([ consumption_data[code] for code in self.product_codes ]) row.append(', '.join('{}: {}'.format(*d) for d in uncategorized_data.items())) yield row self._increment_progress()
def _row_generator(include_consumption=include_consumption): for loc in query: model_data, uncategorized_data = self.data_model.get_model_and_uncategorized(loc.metadata) row_data = { 'location_id': loc.location_id, 'site_code': loc.site_code, 'name': loc.name, 'parent_code': loc.parent.site_code if loc.parent else '', 'external_id': loc.external_id, 'latitude': loc.latitude or '', 'longitude': loc.longitude or '', 'do_delete': '', } row = [row_data[attr] for attr in LOCATION_SHEET_HEADERS_BASE.keys()] for field in self.data_model.fields: row.append(model_data.get(field.slug, '')) if include_consumption: consumption_data = self.get_consumption(loc) row.extend([consumption_data[code] for code in self.product_codes]) row.append(', '.join('{}: {}'.format(*d) for d in uncategorized_data.items())) yield row self._increment_progress()
def get_headers(self): headers = OrderedDict([ ('types', [list(LOCATION_TYPE_SHEET_HEADERS.values())]) ]) for loc_type in self.location_types: additional_headers = [] additional_headers.extend('data: {}'.format(f.slug) for f in self.data_model.fields) if self.include_consumption_flag and loc_type.name not in self.administrative_types: additional_headers.extend('consumption: {}'.format(code) for code in self.product_codes) additional_headers.append(LOCATION_SHEET_HEADERS_OPTIONAL['uncategorized_data']) additional_headers.append(LOCATION_SHEET_HEADERS_OPTIONAL['delete_uncategorized_data']) headers[loc_type.code] = [list(LOCATION_SHEET_HEADERS_BASE.values()) + additional_headers] return list(headers.items())
def get_headers(self): headers = OrderedDict([ ('types', [list(LOCATION_TYPE_SHEET_HEADERS.values())]) ]) for loc_type in self.location_types: additional_headers = [] additional_headers.extend('data: {}'.format(f.slug) for f in self.data_model.fields) if self.include_consumption_flag and loc_type.name not in self.administrative_types: additional_headers.extend('consumption: {}'.format(code) for code in self.product_codes) additional_headers.append(LOCATION_SHEET_HEADERS_OPTIONAL['uncategorized_data']) additional_headers.append(LOCATION_SHEET_HEADERS_OPTIONAL['delete_uncategorized_data']) headers[loc_type.code] = [list(LOCATION_SHEET_HEADERS_BASE.values()) + additional_headers] return list(headers.items())