def get_one(self, pk: str): pk = LayoutsApi._normalize_pk(pk) l_store = layouts_store() w_store = widgets_store() layout = l_store.get(pk=pk) if layout is not None: return LayoutsApi._resolve_widgets(layout, w_store) q = widgets_task_queue() w_pks = [] for spec in widget_specs_for_term(pk): is_new, new_widget = w_store.add( { 'type': spec.widget_type, 'spec_type': spec.spec_type, 'name': spec.name, 'description': spec.description, 'idempotency_key': spec.idempotency_key, 'status': STATUS_LOADING, }, pk=spec.idempotency_key) w_pks.append(new_widget['_id']) q.enqueue(spec.idempotency_key, spec._asdict()) is_new, layout = l_store.add({ 'search_terms': pk, 'widgets': w_pks, }, pk=pk) return LayoutsApi._resolve_widgets(layout, w_store)
def get_one(self, pk): store = widgets_store() widget = store.get(pk=pk) self._add_to_query_log(widget) if widget is not None: return widget abort(404)
def get_one(self, pk: str): refresh = self.get_query_or_default('refresh', 0) refresh = int(refresh) pk = LayoutsApi._normalize_pk(pk) l_store = layouts_store() w_store = widgets_store() layout = l_store.get(pk=pk) if layout is not None and refresh == 0: return LayoutsApi._resolve_widgets(layout, w_store) # Generate mock data if pk == "mock": widgets = generate_mock_widgets() w_pks = [ w_store.add(w, w['type'] + '[\'' + pk + '\']')[1]['_id'] for w in widgets ] is_new, layout = l_store.add( { # TODO: handle when is_new is False 'search_terms': pk, 'widgets': w_pks }, pk=pk) if layout is not None and refresh == 1: is_update = l_store.update(pk, {'widgets': w_pks}) layout = l_store.get(pk=pk) return LayoutsApi._resolve_widgets(layout, w_store) q = widgets_task_queue() w_pks = [] for spec in widget_specs_for_term(pk): is_new, new_widget = w_store.add( { 'type': spec.widget_type, 'spec_type': spec.spec_type, 'name': spec.name, 'description': spec.description, 'idempotency_key': spec.idempotency_key, 'status': STATUS_LOADING, }, pk=spec.idempotency_key) w_pks.append(new_widget['_id']) q.enqueue(spec.idempotency_key, spec._asdict()) if layout is not None and refresh == 1: is_update = l_store.update(pk, {'widgets': w_pks}) layout = l_store.get(pk=pk) else: is_new, layout = l_store.add( { 'search_terms': pk, 'widgets': w_pks, }, pk=pk) return LayoutsApi._resolve_widgets(layout, w_store)
def get_list(self, skip=None, limit=None): w_store = widgets_store() return [ LayoutsApi._resolve_widgets(x, w_store) for x in layouts_store().get(skip=skip, limit=limit) ]
def _update_store(self, task_info, data): store = widgets_store() store.update(task_info['idempotency_key'], { 'data': data, 'status': STATUS_COMPLETE })
def get_list(self, skip=None, limit=None): return widgets_store().get(skip=skip, limit=limit)
def get_one(self, pk): store = widgets_store() widget = store.get(pk=pk) if widget is not None: return widget abort(404)