Пример #1
0
def recipe_create(request, uid):
    # Get the project

    project = Project.objects.filter(uid=uid).first()

    # Prepare the form
    name = "Recipe Name"
    initial = dict(name=name, uid=f'recipe-{util.get_uuid(5)}')
    form = forms.RecipeForm(user=request.user, initial=initial, project=project)

    if request.method == "POST":
        form = forms.RecipeForm(data=request.POST, creating=True, project=project, files=request.FILES,
                                user=request.user)
        if form.is_valid():
            image = form.cleaned_data['image']
            recipe_uid = form.cleaned_data['uid']
            name = form.cleaned_data['name']
            json_text = form.cleaned_data['json_text']
            template = form.cleaned_data['template']
            recipe = auth.create_analysis(uid=recipe_uid, stream=image, name=name,
                                          json_text=json_text, template=template,
                                          project=project, user=request.user)

            return redirect(reverse("recipe_view", kwargs=dict(uid=recipe.uid)))

    action_url = reverse('recipe_create', kwargs=dict(uid=uid))
    context = dict(project=project, form=form, action_url=action_url,
                   activate='Create Recipe', name=name)
    counts = get_counts(project)
    context.update(counts)
    return render(request, 'recipe_edit.html', context)
Пример #2
0
def recipe_edit(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()
            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))
    context = dict(recipe=recipe, project=project, form=form, name=recipe.name, activate='Edit Recipe',
                   action_url=action_url)
    counts = get_counts(project)
    context.update(counts)
    return render(request, 'recipe_edit.html', context)
Пример #3
0
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)
Пример #4
0
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 user making the request.
    user = request.user

    # The recipe that needs to be edited.
    recipe = Analysis.objects.filter(uid=uid).annotate(
        job_count=Count("job", filter=Q(job__deleted=False))).first()

    # The project that recipe belongs to.
    project = recipe.project

    # Initial form loading via a GET request.
    form = forms.RecipeForm(instance=recipe,
                            user=request.user,
                            project=project)

    # Fills in project level counts (results, data and recipe counts).
    counts = get_counts(project)

    # Disable buttons if project not writeable.
    btn_state = '' if auth.is_writable(user=user,
                                       project=project) else 'disabled'

    # Get the list of jobs required to view recipe results
    jobs = recipe.job_set.filter(
        deleted=False).order_by("-lastedit_date").all()

    # Check to see if this recipe is runnable by the user.
    is_runnable = auth.authorize_run(user=user, recipe=recipe)

    # Check to see if recipe is editable
    editable = auth.writeable_recipe(user=user, source=recipe)

    # Generate the context.
    context = dict(recipe=recipe,
                   job_list=jobs,
                   project=project,
                   form=form,
                   btn_state=btn_state,
                   is_runnable=is_runnable,
                   activate='Recipe View',
                   rerun_btn=False,
                   include_copy=False,
                   editable=editable)

    # Update context with counts.
    context.update(counts)

    return render(request, 'recipe_view.html', context)