예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
    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)
예제 #4
0
 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)
     ]
예제 #5
0
 def _update_store(self, task_info, data):
     store = widgets_store()
     store.update(task_info['idempotency_key'], {
         'data': data,
         'status': STATUS_COMPLETE
     })
예제 #6
0
 def get_list(self, skip=None, limit=None):
     return widgets_store().get(skip=skip, limit=limit)
예제 #7
0
 def get_one(self, pk):
     store = widgets_store()
     widget = store.get(pk=pk)
     if widget is not None:
         return widget
     abort(404)