def check_for_create(): """Check for create/initiate operation""" module = get_request_params('app_name', request, **kwargs) flow = flow_config(module).FLOW initial = flow_config(module).INITIAL identifier = get_request_params('pk', request, **kwargs) activity = initial if identifier == REQUEST_IDENTIFIER \ else Task.objects.get(id=identifier).activity_ref return flow[activity]['role'] not in [ group.name for group in groups ]
def get_context_data(self, **kwargs): """Retrieve context data<""" context = super(WorkflowDetail, self).get_context_data(**kwargs) app_title = get_request_params('app_name', **kwargs) config = flow_config(app_title) model = config.FLOW[config.INITIAL]['model']().title context['requests'] = get_workflows_requests(app_title) context['request_identifier'] = REQUEST_IDENTIFIER context['workflow_title'] = config.TITLE context['description'] = config.DESCRIPTION context['initial'] = model return context
def initiate_request(self, user, module): """Initiates new workflow requests""" config = flow_config(self.module_label) role = Group.objects.get(name=config.FLOW[config.INITIAL]['role']) request = Request.objects.create(requester=user, module_ref=module, status='Initiated') task = Task.objects.create(request=request, assignee=role, updated_by=user, activity_ref=config.INITIAL, status='In Progress') self.task = task self.save()
def submit(self, module, user, next_activity=None): """Submits the task""" config = flow_config(module) transitions = transition_config(module, self.activity_ref) role = Group.objects.get(name=config.FLOW[next_activity]['role']) self.status = 'Completed' self.save() if transitions is not None: Task.objects.create(request=self.request, assignee=role, updated_by=user, activity_ref=next_activity, status='Not Started') else: self.request.status = 'Completed' self.request.save()
def global_context(request): """Sets up global template context""" def get_value(key): """Returns value against specified key""" return get_request_params(key, request) app_title = get_value('app_name') activity_identifier = get_value('model_name') try: flow = flow_config(app_title).FLOW activity_title = flow[[ identifier for identifier in flow if flow[identifier]['model']().title == activity_identifier ][0]]['name'] except (IndexError, LookupError, ImportError): activity_title = None return { 'entity_title': activity_identifier, 'app_title': app_title, 'identifier': get_value('pk'), 'activity_title': activity_title }
def activity(self): """Returns the activity associated with the task""" flow = flow_config(self.request.module_ref).FLOW return getattr(self, flow[self.activity_ref]['model']().title.lower(), None)
def is_initial(self): """Checks if the activity is initial activity""" config = flow_config(self.module_label) return True if self.title == config.FLOW[ config.INITIAL]['model']().title else False