def post(self, request, **kwargs): """POST request handler for Create operation""" model = get_model(**kwargs) form = get_form_instance(**kwargs)(request.POST) app_title = get_request_params('app_name', **kwargs) if form.is_valid(): instance = model(**form.cleaned_data) if instance.is_initial: instance.initiate_request(request.user, app_title) else: instance.assign_task( get_request_params('pk', **kwargs)) instance.task.initiate() return HttpResponseRedirect( reverse('update', args=( app_title, instance.title, instance.id))) else: context = { 'form': form, 'error_message': get_errors(form.errors) } return render(request, 'core/create.html', context)
def post(self, request, **kwargs): """POST request handler for rollback""" app_title = get_request_params('app_name', **kwargs) identifier = get_request_params('pk', **kwargs) get_task(identifier).rollback() return HttpResponseRedirect( reverse('workflow-detail', args=[app_title]))
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).flow_ref_key return flow[activity]['role'] not in [ group.name for group in groups]
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 dispatch(self, request, *args, **kwargs): """Overriding dispatch on DeleteView""" self.model = get_model(**kwargs) self.success_url = reverse_lazy( 'workflow-detail', args=[get_request_params('app_name', **kwargs)]) return super(DeleteActivity, self).dispatch(request, *args, **kwargs)
def post(self, request, **kwargs): """POST request handler for Update operation""" operation = self.__class__.__name__ redirect_to_update = False instance = get_model_instance(**kwargs) app_title = get_request_params('app_name', **kwargs) form = get_form(**kwargs)(request.POST, instance=instance) formsets = get_formsets(operation, **kwargs) (result, context) = FormHandler(operation, request, form, formsets, instance).handle(**kwargs) if not result: return render(request, 'core/update.html', context) if 'save' in request.POST: redirect_to_update = True instance.update() elif 'finish' in request.POST: instance.finish() else: next_activity = request.POST['submit'] if not instance.validate_rule(next_activity): redirect_to_update = True else: instance.task.submit(app_title, self.request.user, next_activity) return HttpResponseRedirect( reverse('update', args=( app_title, instance.title, instance.id))) if redirect_to_update else HttpResponseRedirect( reverse('workflow-detail', args=[app_title]))
def post(self, request, **kwargs): """POST request handler for Update operation""" instance = get_model_instance(**kwargs) app_title = get_request_params('app_name', **kwargs) form = get_form_instance( **kwargs)(request.POST, instance=instance) if form.is_valid(): form.save() if 'save' in request.POST: instance.update() return HttpResponseRedirect( reverse('update', args=( app_title, instance.title, instance.id))) elif 'finish' in request.POST: instance.finish() else: instance.task.submit( app_title, self.request.user, request.POST['submit']) return HttpResponseRedirect( reverse('workflow-detail', args=[app_title])) else: context = { 'form': form, 'object': instance, 'next': instance.next_activity(), 'error_message': get_errors(form.errors) } return render(request, 'core/update.html', context)
def dispatch(self, request, *args, **kwargs): """Overriding dispatch on DeleteView""" self.model = get_model(**kwargs) self.success_url = reverse_lazy( 'workflow-detail', args=[get_request_params( 'app_name', **kwargs)]) return super(DeleteActivity, self).dispatch( request, *args, **kwargs)
def post(self, request, **kwargs): """POST request handler for Create operation""" model = get_model(**kwargs) form = get_form_instance(**kwargs)(request.POST) app_title = get_request_params('app_name', **kwargs) if form.is_valid(): instance = model(**form.cleaned_data) if instance.is_initial: instance.initiate_request(request.user, app_title) else: instance.assign_task(get_request_params('pk', **kwargs)) instance.task.initiate() return HttpResponseRedirect( reverse('update', args=(app_title, instance.title, instance.id))) else: context = {'form': form, 'error_message': get_errors(form.errors)} return render(request, 'core/create.html', context)
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 post(self, request, **kwargs): """POST request handler for Create operation""" operation = self.__class__.__name__ instance = None form = get_form(**kwargs)(request.POST) formsets = get_formsets(operation, **kwargs) app_title = get_request_params('app_name', **kwargs) (result, context) = FormHandler(operation, request, form, formsets).handle(**kwargs) if not result: return render(request, 'core/create.html', context) else: instance = context if instance.is_initial: instance.initiate_request(request.user, app_title) else: instance.assign_task(get_request_params('pk', **kwargs)) instance.task.initiate() return HttpResponseRedirect( reverse('update', args=(app_title, instance.title, instance.id)))
def post(self, request, **kwargs): """POST request handler for Update operation""" redirect_to_update = False instance = get_model_instance(**kwargs) app_title = get_request_params('app_name', **kwargs) form = get_form_instance(**kwargs)(request.POST, instance=instance) if form.is_valid(): form.save() if 'save' in request.POST: redirect_to_update = True instance.update() elif 'finish' in request.POST: instance.finish() else: next_activity = request.POST['submit'] if not instance.validate_rule(next_activity): redirect_to_update = True else: instance.task.submit(app_title, self.request.user, next_activity) return HttpResponseRedirect( reverse( 'update', args=(app_title, instance.title, instance.id ))) if redirect_to_update else HttpResponseRedirect( reverse('workflow-detail', args=[app_title])) else: context = { 'form': form, 'object': instance, 'next': instance.next_activity(), 'error_message': get_errors(form.errors) } return render(request, 'core/update.html', context)
def get_value(key): """Returns value against specified key""" return get_request_params(key, request)