def recipe_run(request, uid): """ View used to execute recipes and start a 'Queued' job. """ analysis = Analysis.objects.filter(uid=uid).first() project = analysis.project # Form submission. if request.method == "POST": form = forms.RecipeInterface(request=request, analysis=analysis, json_data=analysis.json_data, data=request.POST, files=request.FILES) # The form validation will authorize the job. if form.is_valid(): # Create the job from the recipe and incoming json data. job = auth.create_job(analysis=analysis, user=request.user, fill_with=form.cleaned_data) # Spool the job right away if UWSGI exists. if tasks.HAS_UWSGI: # Spool via UWSGI. tasks.execute_job.spool(job_id=job.id) return redirect(reverse("job_list", kwargs=dict(uid=project.uid))) else: initial = dict(name=f"Results for: {analysis.name}") form = forms.RecipeInterface(request=request, analysis=analysis, json_data=analysis.json_data, initial=initial) is_runnable = auth.authorize_run(user=request.user, recipe=analysis) context = dict(project=project, analysis=analysis, form=form, is_runnable=is_runnable, activate='Run Recipe') context.update(get_counts(project)) return render(request, 'recipe_run.html', context)
def recipe_run(request, uid): """ View used to execute recipes and start a 'Queued' job. """ recipe = Analysis.objects.filter(uid=uid).first() # Form submission. if request.method == "POST": form = forms.RecipeInterface(request=request, analysis=recipe, json_data=recipe.json_data, data=request.POST, files=request.FILES) # The form validation will authorize the job. if form.is_valid(): # Create the job from the recipe and incoming json data. #print(form.cleaned_data) job = auth.create_job(analysis=recipe, user=request.user, fill_with=form.cleaned_data) # Spool via UWSGI or start it synchronously. tasks.execute_job.spool(job_id=job.id) url = reverse("recipe_view", kwargs=dict(uid=recipe.uid)) + "#results" return redirect(url) else: messages.error(request, form.errors) url = reverse("recipe_view", kwargs=dict(uid=recipe.uid)) + "#run" return redirect(url)
def get_part(request, name, id): """ Return a template by name and with uid rendering """ user = request.user # The recipe that needs to be edited. recipe = Analysis.objects.filter(id=id).annotate( job_count=Count("job", filter=Q(job__deleted=False))).first() project = recipe.project if not auth.is_readable(project=project, user=user): message = str("Recipe is not writable by current user") return HttpResponse(message) # Fills in project level counts (results, data and recipe counts). counts = get_counts(recipe.project) if name == "run": initial = dict(name=f"Results for: {recipe.name}") form = forms.RecipeInterface(request=request, analysis=recipe, json_data=recipe.json_data, initial=initial) else: # Initial form loading via a GET request. form = forms.RecipeForm(instance=recipe, user=request.user, project=project) remap = dict( info="parts/recipe_info.html", code="parts/recipe_code.html", interface="parts/recipe_interface.html", run="parts/recipe_run.html", results="parts/recipe_results.html", ) name = remap.get(name, "parts/placeholder.html") # Check to see if this recipe is runnable by the user. is_runnable = auth.authorize_run(user=user, recipe=recipe) # Get the list of jobs required for recipe results jobs = recipe.job_set.filter( deleted=False).order_by("-lastedit_date").all() context = dict(recipe=recipe, form=form, is_runnable=is_runnable, job_list=jobs, rerun_btn=False) context.update(counts) html = render(request, name, context=context) return html
def recipe_view(request, uid): """ Edit meta-data associated with a recipe. """ # The recipe that needs to be edited. recipe = Analysis.objects.filter(uid=uid).first() # The project that recipe belongs to. project = recipe.project user = request.user if request.method == "POST": # Form has been submitted form = forms.RecipeForm(data=request.POST, instance=recipe, files=request.FILES, user=user, project=project) if form.is_valid(): form.save() messages.success(request, "Editted Recipe") return redirect(reverse("recipe_view", kwargs=dict(uid=recipe.uid))) else: # Initial form loading via a GET request. form = forms.RecipeForm(instance=recipe, user=request.user, project=project) action_url = reverse('recipe_edit', kwargs=dict(uid=uid)) initial = dict(name=f"Results for: {recipe.name}") run_form = forms.RecipeInterface(request=request, analysis=recipe, json_data=recipe.json_data, initial=initial) is_runnable = auth.authorize_run(user=request.user, recipe=recipe) recipe = Analysis.objects.filter(uid=uid).annotate( job_count=Count("job", filter=Q(job__deleted=False))).first() context = dict(recipe=recipe, project=project, form=form, is_runnable=is_runnable, name=recipe.name, activate='Recipe View', run_form=run_form, action_url=action_url) counts = get_counts(project) context.update(counts) return render(request, 'recipe_view.html', context)