def process_run_request_done( self, request: http.HttpRequest, workflow: models.Workflow, payload: SessionPayload, action: Optional[models.Action] = None, ): """Finish processing the request after item selection.""" # Get the information from the payload if not action: action = workflow.actions.filter(pk=payload['action_id']).first() if not action: return redirect('home') log_item = self._create_log_event(request.user, action, payload.get_store()) tasks.execute_operation.delay(self.log_event, user_id=request.user.id, log_id=log_item.id, workflow_id=workflow.id, action_id=action.id if action else None, payload=payload.get_store()) # Reset object to carry action info throughout dialogs SessionPayload.flush(request.session) # Successful processing. return render(request, 'action/run_done.html', { 'log_id': log_item.id, 'download': payload['export_wf'] })
def process_run_request_done( self, request: http.HttpRequest, workflow: models.Action, payload: SessionPayload, action: Optional[models.Action] = None, ) -> http.HttpResponse: """Finish processing the valid POST request. Get the action and redirect to the action_done page to prompt the download of the zip file. """ # Get the information from the payload if not action: action = workflow.actions.filter(pk=payload['action_id']).first() if not action: return redirect('home') self._create_log_event(request.user, action, payload.get_store()) # Successful processing. return render(request, 'action/action_zip_done.html', {})
def finish( self, request: http.HttpRequest, payload: SessionPayload, schedule_item: models.ScheduledOperation = None, ) -> Optional[http.HttpResponse]: """Finalize the creation of a scheduled operation. All required data is passed through the payload. :param request: Request object received :param schedule_item: ScheduledOperation item being processed. If None, it has to be extracted from the information in the payload. :param payload: Dictionary with all the required data coming from previous requests. :return: Http Response """ s_item_id = payload.pop('schedule_id', None) schedule_item = None if s_item_id: # Get the item being processed if not schedule_item: schedule_item = models.ScheduledOperation.objects.filter( id=s_item_id).first() if not schedule_item: messages.error(request, _('Incorrect request for operation scheduling')) return redirect('action:index') else: action = models.Action.objects.get(pk=payload.pop('action_id')) payload['workflow'] = action.workflow payload['action'] = action # Remove some parameters from the payload for key in [ 'button_label', 'valuerange', 'step', 'prev_url', 'post_url', 'confirm_items', 'action_id', 'page_title', ]: payload.pop(key, None) try: schedule_item = self.create_or_update(request.user, payload.get_store(), schedule_item) except Exception as exc: messages.error( request, str(_('Unable to create scheduled operation: {0}')).format( str(exc))) return redirect('action:index') schedule_item.log(models.Log.SCHEDULE_EDIT) # Reset object to carry action info throughout dialogs SessionPayload.flush(request.session) # Successful processing. tdelta = create_timedelta_string(schedule_item.execute, schedule_item.frequency, schedule_item.execute_until) return render(request, 'scheduler/schedule_done.html', { 'tdelta': tdelta, 's_item': schedule_item })