def run_json_action( req: HttpRequest, workflow: Workflow, action: Action, ) -> HttpResponse: """Request data to send JSON objects. Form asking for token, key_column and if an item confirmation step is needed :param req: HTTP request (GET) :param workflow: workflow being processed :param action: Action begin run :return: HTTP response """ # Get the payload from the session, and if not, use the given one action_info = get_or_set_action_info( req.session, JSONPayload, initial_values={ 'action_id': action.id, 'prev_url': reverse('action:run', kwargs={'pk': action.id}), 'post_url': reverse('action:json_done') }, ) # Create the form to ask for the email subject and other information form = JSONActionForm(req.POST or None, column_names=[ col.name for col in workflow.columns.filter(is_key=True) ], action_info=action_info) if req.method == 'POST' and form.is_valid(): if action_info['confirm_items']: # Add information to the session object to execute the next pages action_info['button_label'] = ugettext('Send') action_info['valuerange'] = 2 action_info['step'] = 2 set_action_payload(req.session, action_info.get_store()) return redirect('action:item_filter') # Go straight to the final step. return run_json_done(req, action_info=action_info, workflow=workflow) # Render the form return render( req, 'action/request_json_data.html', { 'action': action, 'num_msgs': action.get_rows_selected(), 'form': form, 'valuerange': range(2), 'rows_all_false': action.get_row_all_false_count() })
def edit_action_out( request: HttpRequest, workflow: Workflow, action: Action, ) -> HttpResponse: """Edit action out. :param request: Request object :param workflow: The workflow with the action :param action: Action :return: HTML response """ # Create the form form = EditActionOutForm(request.POST or None, instance=action) form_filter = FilterForm( request.POST or None, instance=action.get_filter(), action=action ) # Processing the request after receiving the text from the editor if request.method == 'POST' and form.is_valid() and form_filter.is_valid(): # Get content text_content = form.cleaned_data.get('text_content') # Render the content as a template and catch potential problems. if text_renders_correctly(text_content, action, form): # Log the event Log.objects.register( request.user, Log.ACTION_UPDATE, action.workflow, {'id': action.id, 'name': action.name, 'workflow_id': workflow.id, 'workflow_name': workflow.name, 'content': text_content}) # Text is good. Update the content of the action action.set_text_content(text_content) if action.action_type == Action.personalized_json: # Update the target_url field action.target_url = form.cleaned_data['target_url'] action.save() if request.POST['Submit'] == 'Submit': return redirect(request.get_full_path()) return redirect('action:index') # This is a GET request or a faulty POST request # Get the filter or None filter_condition = action.get_filter() # Context to render the form context = { 'filter_condition': filter_condition, 'action': action, 'load_summernote': action.action_type == Action.personalized_text, 'conditions': action.conditions.filter(is_filter=False), 'other_conditions': Condition.objects.filter( action__workflow=workflow, is_filter=False, ).exclude(action=action), 'query_builder_ops': workflow.get_query_builder_ops_as_str(), 'attribute_names': [ attr for attr in list(workflow.attributes.keys()) ], 'columns': workflow.columns.all(), 'stat_columns': workflow.columns.filter(is_key=False), 'selected_rows': filter_condition.n_rows_selected if filter_condition else -1, 'has_data': action.workflow.has_table(), 'all_false_conditions': any( cond.n_rows_selected == 0 for cond in action.conditions.all()), 'rows_all_false': action.get_row_all_false_count(), 'total_rows': workflow.nrows, 'form': form, 'form_filter': form_filter, 'vis_scripts': PlotlyHandler.get_engine_scripts(), } # Return the same form in the same page return render(request, 'action/edit_out.html', context=context)
def run_canvas_email_action( req: HttpRequest, workflow: Workflow, action: Action, ) -> HttpResponse: """Request data to send JSON objects. Form asking for subject, item column (contains ids to select unique users), confirm items (add extra step to drop items), export workflow and target_rul (if needed). :param req: HTTP request (GET) :param workflow: workflow being processed :param action: Action begin run :return: HTTP response """ # Get the payload from the session, and if not, use the given one action_info = get_or_set_action_info(req.session, CanvasEmailPayload, initial_values={ 'action_id': action.id, 'prev_url': reverse('action:run', kwargs={'pk': action.id}), 'post_url': reverse('action:email_done') }) # Create the form to ask for the email subject and other information form = CanvasEmailActionForm( req.POST or None, column_names=[ col.name for col in workflow.columns.filter(is_key=True) ], action=action, action_info=action_info) if req.method == 'POST' and form.is_valid(): # Request is a POST and is valid if action_info['confirm_items']: # Create a dictionary in the session to carry over all the # information to execute the next pages action_info['button_label'] = ugettext('Send') action_info['valuerange'] = 2 action_info['step'] = 2 set_action_payload(req.session, action_info.get_store()) return redirect('action:item_filter') # Go straight to the token request step return canvas_get_or_set_oauth_token(req, action_info['target_url']) # Render the form return render( req, 'action/request_canvas_email_data.html', { 'action': action, 'num_msgs': action.get_rows_selected(), 'form': form, 'valuerange': range(2), 'rows_all_false': action.get_row_all_false_count() })