def update_index(new_items, new_stations): logging.info('Index being updated') item_index = ItemTypeIndex.query().get() station_index = StationIndex.query().get() if not item_index: item_index = ItemTypeIndex() if not station_index: station_index = StationIndex() item_index.items.update(new_items) item_index.put_async() station_index.stations.update(new_stations) station_index.put_async()
def get(self): filters = json.loads(self.request.get('filters', '{}')) item_index, station_index = ItemTypeIndex.query().get_async(), StationIndex.query().get_async() result = get_filtered_transactions(self.character, filters) results_as_dct = [r.to_dict() for r in result] item_index, station_index = item_index.get_result().items, station_index.get_result().stations for dct in results_as_dct: dct['balance_change'] = dct['unit_price'] * dct['quantity'] if dct['transaction_type'] == WalletTransaction.BUY: dct['balance_change'] *= -1 dct['balance_change_str'] = price_fmt(dct['balance_change']) dct['unit_price_str'] = price_fmt(dct['unit_price']) dct['type_name'] = item_index.get(dct['type_id'], '<Unknown item>') dct['station_name'] = station_index.get(dct['station_id'], '<Unknown station>') self.render_json(results_as_dct, cls=GenericModelEncoder)