Exemple #1
0
def ajax_edit(request, id):
    """
    Edit recipes. Uses recipe primary key as access!
    """

    # The user performing the request.
    user = request.user

    # The recipe that needs to be edited.
    recipe = Analysis.objects.filter(id=id).first()

    if not auth.writeable_recipe(source=recipe, user=user):
        message = str("Recipe is not writable by current user")
        return ajax_error(msg=message)

    # The project of for the recipe.
    project = recipe.project

    form = RecipeForm(data=request.POST,
                      instance=recipe,
                      files=request.FILES,
                      user=user,
                      project=project)

    if form.is_valid():
        form.save()
        return ajax_success(msg=f"Recipe saved.")
    else:
        message = str(form.errors)
        return ajax_error(msg=message)
Exemple #2
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(obj=project, user=user):
        message = str("Recipe is not readable 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",
        details='parts/recipe_details.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)

    # Check to see if recipe is editable
    editable = auth.writeable_recipe(user=user, source=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,
                   include_copy=False, editable=editable, user=user, project=recipe.project)
    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)