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 create_and_send_zip( session: SessionBase, action: models.Action, item_column: models.Column, user_fname_column: Optional[models.Column], payload: SessionPayload, ) -> http.HttpResponse: """Process the list of tuples in files and create the ZIP BytesIO object. :param session: Session object while creating a zip (need it to flush it) :param action: Action being used for ZIP :param item_column: Column used to itemize the zip :param user_fname_column: Optional column to create file name :param payload: Dictionary with additional parameters to create the ZIP :return: HttpResponse to send back with the ZIP download header """ files = _create_eval_data_tuple(action, item_column, payload.get('exclude_values', []), user_fname_column) file_name_template = _create_filename_template(payload, user_fname_column) # Create the ZIP and return it for download sbuf = BytesIO() zip_file_obj = zipfile.ZipFile(sbuf, 'w') for user_fname, part_id, msg_body in files: if payload['zip_for_moodle']: # If a zip for Moodle, field is Participant [number]. Take the # number only part_id = part_id.split()[1] zip_file_obj.writestr( file_name_template.format(user_fname=user_fname, part_id=part_id), str(msg_body), ) zip_file_obj.close() SessionPayload.flush(session) suffix = datetime.now().strftime('%y%m%d_%H%M%S') # Attach the compressed value to the response and send compressed_content = sbuf.getvalue() response = http.HttpResponse(compressed_content) response['Content-Type'] = 'application/x-zip-compressed' response['Content-Transfer-Encoding'] = 'binary' response['Content-Disposition'] = ( 'attachment; filename="ontask_zip_action_{0}.zip"'.format(suffix)) response['Content-Length'] = str(len(compressed_content)) return response
def action_index( request: http.HttpRequest, wid: Optional[int] = None, workflow: Optional[models.Workflow] = None, ) -> http.HttpResponse: """Show all the actions attached to the workflow. :param request: HTTP Request :param wid: Primary key of the workflow object to use :param workflow: Workflow for the session. :return: HTTP response """ del wid # Reset object to carry action info throughout dialogs SessionPayload.flush(request.session) return render( request, 'action/index.html', { 'workflow': workflow, 'table': services.ActionTable(workflow.actions.all(), orderable=False) })
def index( request: http.HttpRequest, workflow: Optional[models.Workflow] = None, ) -> http.HttpResponse: """Render the list of actions attached to a workflow. :param request: Request object :param workflow: Workflow currently used :return: HTTP response with the table. """ # Reset object to carry action info throughout dialogs SessionPayload.flush(request.session) return render( request, 'scheduler/index.html', { 'table': services.ScheduleActionTable( models.ScheduledOperation.objects.filter(workflow=workflow.id), orderable=False), 'workflow': workflow })
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 })