def load_ws_data(self): workflow_data = { **self._load_workflow_ws_data(), "tab_slugs": list(self.workflow.live_tabs.values_list("slug", flat=True)), } if self.tab.is_deleted: wfm_ids = list( # tab.live_wf_modules can be nonempty even when tab.is_deleted self.tab.live_wf_modules.values_list("id", flat=True)) return { "updateWorkflow": workflow_data, "clearTabSlugs": [self.tab.slug], "clearWfModuleIds": [str(wfm_id) for wfm_id in wfm_ids], } else: return { "updateWorkflow": workflow_data, "updateTabs": { self.tab.slug: TabSerializer(self.tab).data }, "updateWfModules": { str(wfm.id): WfModuleSerializer(wfm).data for wfm in self.tab.live_wf_modules }, }
def get_workflow_as_delta_and_needs_render(self): """ Return (apply-delta dict, needs_render), or raise Workflow.DoesNotExist needs_render is a (workflow_id, delta_id) pair. """ with Workflow.authorized_lookup_and_cooperative_lock( 'read', self.scope['user'], self.scope['session'], pk=self.workflow_id) as workflow: request = RequestWrapper(self.scope['user'], self.scope['session']) ret = { 'updateWorkflow': (WorkflowSerializer(workflow, context={ 'request': request }).data), } tabs = list(workflow.live_tabs) ret['updateTabs'] = dict( (tab.slug, TabSerializer(tab).data) for tab in tabs) wf_modules = list(WfModule.live_in_workflow(workflow.id)) ret['updateWfModules'] = dict( (str(wfm.id), WfModuleSerializer(wfm).data) for wfm in wf_modules) if workflow.are_all_render_results_fresh(): needs_render = None else: needs_render = (workflow.id, workflow.last_delta_id) return (ret, needs_render)
def load_ws_data(self): workflow_data = { **self._load_workflow_ws_data(), 'tab_slugs': list(self.workflow.live_tabs.values_list('slug', flat=True)) } if self.tab.is_deleted: wfm_ids = list( # tab.live_wf_modules can be nonempty even when tab.is_deleted self.tab.live_wf_modules.values_list('id', flat=True)) return { 'updateWorkflow': workflow_data, 'clearTabSlugs': [self.tab.slug], 'clearWfModuleIds': [str(wfm_id) for wfm_id in wfm_ids], } else: return { 'updateWorkflow': workflow_data, 'updateTabs': { self.tab.slug: TabSerializer(self.tab).data }, 'updateWfModules': { str(wfm.id): WfModuleSerializer(wfm).data for wfm in self.tab.live_wf_modules }, }
def load_ws_data(self): data = super().load_ws_data() if self.tab.is_deleted: data["clearTabSlugs"] = [self.tab.slug] else: data["updateTabs"] = {self.tab.slug: TabSerializer(self.tab).data} data["updateWorkflow"]["tab_slugs"] = list( self.workflow.live_tabs.values_list("slug", flat=True)) return data
def load_ws_data(self): data = super().load_ws_data() if self.tab.is_deleted: data['clearTabSlugs'] = [self.tab.slug] else: data['updateTabs'] = { self.tab.slug: TabSerializer(self.tab).data, } data['updateWorkflow']['tab_slugs'] = list( self.workflow.live_tabs.values_list('slug', flat=True)) return data
def make_init_state(request, workflow=None, modules=None): """ Build a dict to embed as JSON in `window.initState` in HTML. Raise Http404 if the workflow disappeared. """ ret = {} if workflow: try: with workflow.cooperative_lock(): # raise DoesNotExist on race ret['workflowId'] = workflow.id ret['workflow'] = WorkflowSerializer(workflow, context={ 'request': request }).data tabs = list(workflow.live_tabs) ret['tabs'] = dict( (str(tab.slug), TabSerializer(tab).data) for tab in tabs) wf_modules = list(WfModule.live_in_workflow(workflow)) ret['wfModules'] = { str(wfm.id): WfModuleSerializer(wfm).data for wfm in wf_modules } except Workflow.DoesNotExist: raise Http404('Workflow was recently deleted') ret['uploadConfig'] = { 'bucket': minio.UserFilesBucket, 'accessKey': settings.MINIO_ACCESS_KEY, # never _SECRET_KEY 'server': settings.MINIO_EXTERNAL_URL } ret['user_files_bucket'] = minio.UserFilesBucket if modules: modules_data_list = ModuleSerializer(modules, many=True).data ret['modules'] = dict([(str(m['id_name']), m) for m in modules_data_list]) if request.user.is_authenticated: ret['loggedInUser'] = UserSerializer(request.user).data return ret
def make_init_state(request, workflow=None, modules=None): """ Build a dict to embed as JSON in `window.initState` in HTML. Raise Http404 if the workflow disappeared. Side-effect: update workflow.last_viewed_at. """ ret = {} if workflow: try: with workflow.cooperative_lock(): # raise DoesNotExist on race ret['workflowId'] = workflow.id ret['workflow'] = WorkflowSerializer(workflow, context={ 'request': request }).data tabs = list(workflow.live_tabs) ret['tabs'] = dict( (str(tab.slug), TabSerializer(tab).data) for tab in tabs) wf_modules = list(WfModule.live_in_workflow(workflow)) ret['wfModules'] = { str(wfm.id): WfModuleSerializer(wfm).data for wfm in wf_modules } workflow.last_viewed_at = timezone.now() workflow.save(update_fields=['last_viewed_at']) except Workflow.DoesNotExist: raise Http404('Workflow was recently deleted') if modules: modules_data_list = ModuleSerializer(modules, many=True).data ret['modules'] = dict([(str(m['id_name']), m) for m in modules_data_list]) if request.user.is_authenticated: ret['loggedInUser'] = UserSerializer(request.user).data return ret