def __call__(self, context, request): self.context = context self.request = request result = {} context = self.context result['condition'] = isinstance(context, Amendment) if not result['condition']: return result result['current_step'] = 0 result['step1_message'] = "" result['step2_message'] = "" result['step3_message'] = "" result['step4_message'] = "" to_submit = getBusinessAction(context, request, 'amendmentmanagement', 'submit') if ('draft' in context.state and 'explanation' not in context.state) or \ request.view_name.endswith('duplicateamendment'): result['current_step'] = 1 # result['step1_message'] = self._get_step1_informations( # context, self.request) elif 'explanation' in context.state and not to_submit: result['current_step'] = 2 # result['step2_message'] = self._get_step2_informations( # context, self.request) elif 'explanation' in context.state and to_submit: result['current_step'] = 3 # result['step3_message'] = self._get_step3_informations( # context, self.request) elif 'submitted' in context.state: result['current_step'] = 4 # result['step4_message'] = self._get_step4_informations( # context, self.request) return result
def __call__(self): site = get_site_folder(True, self.request) if not getattr(site, 'activate_improve', False): return {'improve': None} resources = deepcopy( getattr(self.request, 'resources', { 'js_links': [], 'css_links': [] })) result = {'css_links': [], 'js_links': []} root = self.request.root actions = getBusinessAction(context=root, request=self.request, process_id='lacviewmanager', node_id='improve') result['improve'] = None if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['improve'] = actions_result[3][0] result['css_links'] = [ c for c in actions_result[2].get('css_links', []) if c not in resources['css_links'] ] result['js_links'] = [ c for c in actions_result[2].get('js_links', []) if c not in resources['js_links'] ] update_resources(self.request, result) return result
def get_instance(cls, context, request, **kw): action_uid = request.params.get('action_uid', None) source_action = None if action_uid: source_action = get_obj(int(action_uid)) if source_action and \ source_action._class_ is cls and \ source_action.validate(context, request): return source_action instances = getBusinessAction(context, request, cls.node_definition.process.id, cls.node_definition.__name__, action_type=cls, validate=kw.get('validate', True)) if instances is None: return None isstart = request.params.get('isstart', False) if isstart: for inst in instances: if inst.isstart: return inst return instances[0]
def __call__(self): site = get_site_folder(True, self.request) if not getattr(site, 'activate_improve', False): return {'improve': None} resources = deepcopy(getattr( self.request, 'resources', {'js_links': [], 'css_links': []})) result = {'css_links': [], 'js_links': []} root = self.request.root actions = getBusinessAction( context=root, request=self.request, process_id='lacviewmanager', node_id='improve') result['improve'] = None if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['improve'] = actions_result[3][0] result['css_links'] = [c for c in actions_result[2].get('css_links', []) if c not in resources['css_links']] result['js_links'] = [c for c in actions_result[2].get('js_links', []) if c not in resources['js_links']] update_resources(self.request, result) return result
def _getaction(view, process_id, action_id): root = getSite() actions = getBusinessAction(root, view.request, process_id, action_id) action = None action_view = None if actions is not None: action = actions[0] if action.__class__ in DEFAULTMAPPING_ACTIONS_VIEWS: action_view = DEFAULTMAPPING_ACTIONS_VIEWS[action.__class__] return action, action_view
def _execute_action(self, process_id, node_id, appstruct): actions = getBusinessAction(self.context, self.request, process_id, node_id) if actions: try: action = actions[0] action.validate(self.context, self.request) action.before_execution(self.context, self.request) action.execute(self.context, self.request, appstruct) return {'state': True, 'action_obj': action} except Exception: return {'state': False} return {'state': False}
def _execute_action(self, process_id, node_id, appstruct): actions = getBusinessAction( self.context, self.request, process_id, node_id) if actions: try: action = actions[0] action.validate(self.context, self.request) action.before_execution(self.context, self.request) action.execute(self.context, self.request, appstruct) return {'state': True, 'action_obj': action} except Exception: return {'state': False} return {'state': False}
def __call__(self): user = get_current(self.request) resources = deepcopy( getattr(self.request, 'resources', { 'js_links': [], 'css_links': [] })) search_view_instance = SearchView(self.context, self.request) search_view_result = search_view_instance() search_body = '' result = {'css_links': [], 'js_links': []} if isinstance(search_view_result, dict) and \ 'coordinates' in search_view_result: search_body = search_view_result['coordinates'][ search_view_instance.coordinates][0]['body'] result['css_links'] = [ c for c in search_view_result['css_links'] if c not in resources['css_links'] ] result['js_links'] = [ c for c in search_view_result['js_links'] if c not in resources['js_links'] ] result['search_body'] = search_body result['view'] = self result['alerts'] = [] if hasattr(user, 'get_alerts'): site = get_site_folder(True, self.request) result['alerts'] = user.get_alerts(site=site) result['login_action'] = None if self.request.user is None: root = self.request.root actions = getBusinessAction(context=root, request=self.request, process_id='usermanagement', node_id='login') if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['login_action'] = actions_result[3][0] update_resources(self.request, result) return result
def __call__(self): site = get_site_folder(True, self.request) if self.request.view_name in ('@@resetpassword', '@@registration', 'login', '@@login') or \ not getattr(site, 'activate_questionnaire', False): return {'questionnaire': None} user = get_current() email = getattr(user, 'email', '') if email: db = arango_server.db("lac") collection = create_collection(db, CURRENT_QUEST) doc = collection.get_first_example({"email": email}) if doc: return {'questionnaire': None} resources = deepcopy( getattr(self.request, 'resources', { 'js_links': [], 'css_links': [] })) result = {'css_links': [], 'js_links': []} root = self.request.root actions = getBusinessAction(context=root, request=self.request, process_id='lacviewmanager', node_id='questionnaire') result['questionnaire'] = None result['current_questionnaire'] = CURRENT_QUEST if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['questionnaire'] = actions_result[3][0] result['css_links'] = [ c for c in actions_result[2].get('css_links', []) if c not in resources['css_links'] ] result['js_links'] = [ c for c in actions_result[2].get('js_links', []) if c not in resources['js_links'] ] update_resources(self.request, result) return result
def start(self, context, request, appstruct, **kw): root = getSite() last_version = context.version copy_of_idea = copy(context, (context, 'version'), new_name=context.__name__, select=('modified_at',), omit=('created_at',), roles=True) copy_keywords, newkeywords = root.get_keywords(context.keywords) copy_of_idea.setproperty('keywords_ref', copy_keywords) copy_of_idea.setproperty('version', last_version) copy_of_idea.setproperty('originalentity', context.originalentity) if last_version is not None: grant_roles(roles=(('Owner', last_version), )) files = [f['_object_data'] for f in appstruct.pop('attached_files')] appstruct['attached_files'] = files keywords_ids = appstruct.pop('keywords') result, newkeywords = root.get_keywords(keywords_ids) for nkw in newkeywords: root.addtoproperty('keywords', nkw) result.extend(newkeywords) appstruct['keywords_ref'] = result copy_of_idea.state = PersistentList(['archived', 'version']) copy_of_idea.setproperty('author', get_current()) note = appstruct.pop('note', '') context.note = note context.set_data(appstruct) context.modified_at = datetime.datetime.today() copy_of_idea.reindex() context.reindex() if 'archived' in context.state: recuperate_actions = getBusinessAction(context, request, 'ideamanagement', 'recuperate') if recuperate_actions: recuperate_actions[0].execute(context, request, appstruct, **kw) return {}
def __call__(self): user = get_current(self.request) resources = deepcopy(getattr( self.request, 'resources', {'js_links': [], 'css_links': []})) search_view_instance = SearchView(self.context, self.request) search_view_result = search_view_instance() search_body = '' result = {'css_links': [], 'js_links': []} if isinstance(search_view_result, dict) and \ 'coordinates' in search_view_result: search_body = search_view_result['coordinates'][search_view_instance.coordinates][0]['body'] result['css_links'] = [c for c in search_view_result['css_links'] if c not in resources['css_links']] result['js_links'] = [c for c in search_view_result['js_links'] if c not in resources['js_links']] result['search_body'] = search_body result['view'] = self result['alerts'] = [] if hasattr(user, 'get_alerts'): site = get_site_folder(True, self.request) result['alerts'] = user.get_alerts(site=site) result['login_action'] = None if self.request.user is None: root = self.request.root actions = getBusinessAction( context=root, request=self.request, process_id='usermanagement', node_id='login') if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['login_action'] = actions_result[3][0] update_resources(self.request, result) return result
def __call__(self): site = get_site_folder(True, self.request) if self.request.view_name in ('@@resetpassword', '@@registration', 'login', '@@login') or \ not getattr(site, 'activate_questionnaire', False): return {'questionnaire': None} user = get_current() email = getattr(user, 'email', '') if email: db = arango_server.db("lac") collection = create_collection(db, CURRENT_QUEST) doc = collection.get_first_example({"email": email}) if doc: return {'questionnaire': None} resources = deepcopy(getattr( self.request, 'resources', {'js_links': [], 'css_links': []})) result = {'css_links': [], 'js_links': []} root = self.request.root actions = getBusinessAction( context=root, request=self.request, process_id='lacviewmanager', node_id='questionnaire') result['questionnaire'] = None result['current_questionnaire'] = CURRENT_QUEST if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['questionnaire'] = actions_result[3][0] result['css_links'] = [c for c in actions_result[2].get('css_links', []) if c not in resources['css_links']] result['js_links'] = [c for c in actions_result[2].get('js_links', []) if c not in resources['js_links']] update_resources(self.request, result) return result
def start(self, context, request, appstruct, **kw): root = getSite() user = context.author last_version = context.version copy_of_idea = copy( context, (context, 'version'), new_name=context.__name__, select=('modified_at',), omit=('created_at',), roles=True) copy_of_idea.keywords = context.keywords copy_of_idea.setproperty('version', last_version) copy_of_idea.setproperty('originalentity', context.originalentity) if last_version is not None: grant_roles(user=user, roles=(('Owner', last_version), )) files = [f['_object_data'] for f in appstruct.pop('attached_files')] appstruct['attached_files'] = files copy_of_idea.state = PersistentList(['version', 'archived']) copy_of_idea.setproperty('author', user) note = appstruct.pop('note', '') context.note = note context.set_data(appstruct) context.modified_at = datetime.datetime.now(tz=pytz.UTC) copy_of_idea.reindex() context.format(request) context.reindex() if 'archived' in context.state: recuperate_actions = getBusinessAction(context, request, 'ideamanagement', 'recuperate') if recuperate_actions: recuperate_actions[0].execute(context, request, appstruct, **kw) request.registry.notify(ActivityExecuted(self, [context], user)) return {}
def __call__(self, context, request): self.context = context self.request = request result = {} context = self.context result['condition'] = isinstance(context, Amendment) if not result['condition']: return result result['current_step'] = 0 result['step1_message'] = "" result['step2_message'] = "" result['step3_message'] = "" result['step4_message'] = "" to_submit = getBusinessAction( context, request, 'amendmentmanagement', 'submit') if ('draft' in context.state and 'explanation' not in context.state) or \ request.view_name.endswith('duplicateamendment'): result['current_step'] = 1 # result['step1_message'] = self._get_step1_informations( # context, self.request) elif 'explanation' in context.state and not to_submit: result['current_step'] = 2 # result['step2_message'] = self._get_step2_informations( # context, self.request) elif 'explanation' in context.state and to_submit: result['current_step'] = 3 # result['step3_message'] = self._get_step3_informations( # context, self.request) elif 'submitted' in context.state: result['current_step'] = 4 # result['step4_message'] = self._get_step4_informations( # context, self.request) return result
def test_actions(self): self.logAdmin() y, pd = self._process_valid_actions() y._init_contexts([ActionY]) self.def_container.add_definition(pd) start_wi = pd.start_process('x')['x'] actions_x = start_wi.actions self.assertEqual(len(actions_x), 1) action_x = actions_x[0] self.assertIs(action_x.workitem, start_wi) self.assertEqual(action_x.node_id, 'x') self.assertEqual(isinstance(action_x, ActionX), True) objecta= ObjectA() self.app['objecta'] = objecta call_actions = objecta.actions self.assertEqual(len(call_actions), 5) actions_id = [a.action.node_id for a in call_actions] self.assertIn('x', actions_id) self.assertIn('y', actions_id) self.assertIn('z', actions_id) actions_y = [a.action for a in call_actions if a.action.node_id == 'y'] self.assertEqual(len(actions_y), 3) action_y = actions_y[0] action_y.before_execution(objecta, self.request) wi, proc = action_y.workitem.consume() wi.start_test_empty() action_y.execute(objecta, self.request, None, **{}) self.assertIs(action_y.workitem, wi) actions_y_executed = [a for a in actions_y if a.isexecuted] self.assertEqual(len(actions_y_executed), 1) self.assertIn(action_y, actions_y_executed) workitems = proc.getWorkItems() self.assertEqual(len(workitems), 2) self.assertIn('sample.x', workitems.keys()) self.assertIn('sample.y', workitems.keys()) actions_x = workitems['sample.x'].actions self.assertEqual(len(actions_x), 1) actions_y = workitems['sample.y'].actions self.assertEqual(len(actions_y), 4)# +1 pour l'action principale (3 pour les instances) actions_y_executed = [a for a in actions_y if a.isexecuted] self.assertEqual(len(actions_y_executed), 2)# +1 pour l'action principale (1 pour les instances) actions_y_validated = [] for a in actions_y: try: a.validate(objecta, self.request, **{}) actions_y_validated.append(a) except Exception: continue self.assertEqual(len(actions_y_validated), 2) action_y = actions_y_validated[0] action_y.before_execution(objecta, self.request)# user == 'admin', lock action self.logAlice()#user == 'alice' actions_y_validated_alice = [] for a in actions_y: try: a.validate(objecta, self.request, **{}) actions_y_validated_alice.append(a) except Exception: continue self.assertEqual(len(actions_y_validated_alice), 0)# ActionY is sequential self.logAdmin() action_y.after_execution(objecta, self.request) # unlock action self.logAlice()# user == 'alice' actions_y_validated_alice = [] for a in actions_y: try: a.validate(objecta, self.request, **{}) actions_y_validated_alice.append(a) except Exception: continue self.assertEqual(len(actions_y_validated_alice), 2) # get sample.y business action for alice allaction_y_alice = getBusinessAction(objecta, self.request, 'sample', 'y') self.assertEqual(len(allaction_y_alice), 2)# 2 for actions_y_validated_alice. StartWorkItems are ignored (no new execution) self.assertIn(actions_y_validated_alice[0], allaction_y_alice) self.assertIn(actions_y_validated_alice[1], allaction_y_alice) workitems_y_alice = [] for a in allaction_y_alice: if a.workitem not in workitems_y_alice: workitems_y_alice.append(a.workitem) self.assertEqual(len(workitems_y_alice), 1) self.assertIn(workitems['sample.y'], workitems_y_alice) self.logAdmin() for action in actions_y_validated: action.before_execution(objecta, self.request) action.execute(objecta, self.request, None, **{}) workitems = proc.getWorkItems() self.assertEqual(len(workitems), 1) self.assertIn('sample.x', workitems.keys()) workitems['sample.x'].start_test_empty() actions_x[0].before_execution(objecta, self.request) actions_x[0].execute(objecta, self.request, None, **{}) workitems = proc.getWorkItems() self.assertEqual(len(workitems), 0)
def get_allinstances(cls, context, request, **kw): instance = getBusinessAction(context, request, cls.node_definition.process.id, cls.node_definition.__name__) return instance