Пример #1
0
def field_render(request):
    """
    Renders and returns an HTML field based on the incoming toml data.
    """
    from .forms import RecipeInterface
    from django.http import HttpResponse
    import toml

    demo = """
    [demo]
    label = "Demo"
    display = "INTEGER"
    value = 10000000
    """
    text = request.POST.get("toml", demo)

    try:
        data = toml.loads(text)
    except Exception as exc:
        return HttpResponse(exc)

    form = RecipeInterface(request, json_data=data)

    context = dict(form=form)

    return render(request, "parts/form_field_render.html", context=context)
Пример #2
0
def field_render(request):
    """
    Renders and returns an HTML field based on the incoming toml data.
    """

    demo = """
    [demo]
    label = "Demo"
    display = "INTEGER"
    value = 10000000
    """
    text = request.POST.get("toml", demo)

    # Get the project uid
    uid = request.POST.get('recipe')
    recipe = Analysis.objects.filter(id=uid).first()
    try:
        data = toml.loads(text)
    except Exception as exc:
        return HttpResponse(exc)

    form = RecipeInterface(request, json_data=data, analysis=recipe)

    context = dict(form=form)

    return render(request, "parts/form_field_render.html", context=context)
Пример #3
0
def preview_json(request):
    # Get the recipe
    recipe_name = request.POST.get('name')
    project_uid = request.POST.get('project_uid')

    json_text = request.POST.get('json_text', '')
    try:
        json_data = toml.loads(json_text)
    except Exception as exc:
        return ajax_error(msg=f"{exc}")

    project = Project.objects.filter(uid=project_uid).first()
    if not project:
        return ajax_error(msg=f"Project does not exist")

    # Render the recipe interface
    interface = RecipeInterface(request=request,
                                json_data=json_data,
                                project=project,
                                initial=dict(name=recipe_name),
                                add_captcha=False)

    tmpl = loader.get_template('widgets/recipe_form.html')
    context = dict(form=interface, focus=True)
    template = tmpl.render(context=context)

    return ajax_success(msg="Recipe json", html=template)
Пример #4
0
def preview_json(request):
    # Get the recipe
    uid = request.POST.get('recipe')
    text = request.POST.get('toml', '')
    recipe = Analysis.objects.filter(id=uid).first()

    if not recipe:
        return ajax_error(msg=f"Project does not exist")

    try:
        json_data = toml.loads(text)
    except Exception as exc:
        return ajax_error(msg=f"{exc}")

    project = recipe.project

    # Render the recipe interface
    interface = RecipeInterface(request=request,
                                json_data=json_data,
                                project=project,
                                add_captcha=False)

    tmpl = loader.get_template('widgets/recipe_form.html')
    context = dict(form=interface, focus=True)
    template = tmpl.render(context=context)

    return ajax_success(msg="Recipe json", html=template)