示例#1
0
def import_form(request):
    if request.method == "POST":
        json_file = request.FILES['file']
        json_string = json_file.read()
        json_data = json.loads(json_string)

        template_options = json_data["template"]
        form_options = json_data["form"]

        template = ConfigTemplate()
        template.name = template_options["name"]
        template.description = template_options["description"]
        template.action_provider = template_options["action_provider"]
        template.action_provider_options = template_options["action_provider_options"]
        template.type = template_options["type"]
        template.template = unquote(template_options["template"])

        template.save()

        input_form = InputForm()
        input_form.name = form_options["name"]
        input_form.description = form_options["description"]
        input_form.instuctions = form_options["instructions"]
        input_form.json = unquote(form_options["json"])
        input_form.script = template

        input_form.save()

        return HttpResponseRedirect("/input_forms")
    else:
        form = ImportForm()
        context = {'form': form }
        return render(request, 'input_forms/import.html', context)
示例#2
0
def new_from_template(request, template_id):
    logger.info("__ input_forms new_from_template __")
    config_template = get_object_or_404(ConfigTemplate, pk=template_id)
    try:
        t = engines['django'].from_string(config_template.template)
    except TemplateSyntaxError as e:
        logger.error("Caught a template syntax error!")
        return render(request, "error.html",
                      {"error": "Invalid Template Syntax: %s" % str(e)})

    available_tags = []

    for node in t.template.nodelist:
        defined_tags = node.get_nodes_by_type(VariableNode)
        for v in defined_tags:
            logger.info("adding %s as an available tag" % v.filter_expression)
            variable_string = str(v.filter_expression)
            if variable_string not in available_tags:
                if not variable_string.startswith("af_"):
                    available_tags.append(variable_string)
    widgets = settings.WIDGETS
    widgets_json = json.dumps(widgets)
    context = {
        "config_template": config_template,
        "available_tags": available_tags,
        "widgets": widgets,
        "widgets_json": widgets_json
    }

    if 'cloned_templates' in request.session:
        print 'found cloned templates'
        cloned_templates = request.session['cloned_templates']
        if template_id in cloned_templates:
            print 'found this template_id'
            if 'input_form_id' in cloned_templates[template_id]:
                cloned_input_form_id = cloned_templates[template_id][
                    'input_form_id']
                try:
                    input_form = InputForm.objects.get(pk=cloned_input_form_id)
                    dolly = InputForm()
                    dolly.name = config_template.name
                    dolly.description = config_template.description
                    dolly.instructions = input_form.instructions
                    dolly.json = input_form.json
                    dolly.script = config_template
                    dolly.save()
                    context['input_form'] = dolly
                    return render(request, "input_forms/edit.html", context)
                except ObjectDoesNotExist:
                    print 'Could not find the input for for this cloned template'

    else:
        print 'no cloned templates found!'

    return render(request, "input_forms/new.html", context)
示例#3
0
def import_form(request):
    logger.info("__ input_forms import_form __")
    if request.method == "POST":
        json_file = request.FILES['file']
        json_string = json_file.read()
        json_data = json.loads(json_string)

        template_options = json_data["template"]
        form_options = json_data["form"]

        template = ConfigTemplate()
        template.name = template_options["name"]
        template.description = template_options["description"]
        template.action_provider = template_options["action_provider"]
        template.action_provider_options = template_options["action_provider_options"]
        template.type = template_options["type"]
        template.template = unquote(template_options["template"])

        template.save()

        input_form = InputForm()
        input_form.name = form_options["name"]
        input_form.description = form_options["description"]
        input_form.instuctions = form_options["instructions"]
        input_form.json = unquote(form_options["json"])
        input_form.script = template

        input_form.save()

        return HttpResponseRedirect("/input_forms")
    else:
        form = ImportForm()
        context = {'form': form }
        return render(request, 'input_forms/import.html', context)
示例#4
0
def create(request):
    required_fields = set(["config_template_id", "name", "description", "json"])
    if not required_fields.issubset(request.POST):
        return render(request, "error.html", {"error": "Invalid Parameters in POST"})

    template_id = request.POST["config_template_id"]
    name = request.POST["name"]
    description = request.POST["description"]
    json_data = request.POST["json"]
    instructions = request.POST["instructions"]

    config_template = get_object_or_404(ConfigTemplate, pk=template_id)

    input_form = InputForm()
    input_form.name = name
    input_form.description = description
    input_form.instructions = instructions
    input_form.json = json_data
    input_form.script = config_template
    input_form.save()
    return HttpResponseRedirect("/input_forms")
示例#5
0
def import_form(jd):
    """
    Imports an input_from from serialized json data
    :param jd: json_data object generated from the export_input_form function
    :return: id of the input form or id of the input form if it already exists
    """
    template_options = jd["template"]
    form_options = jd["form"]

    if not ConfigTemplate.objects.filter(
            name=template_options['name']).exists():
        template = ConfigTemplate()
        template.name = template_options["name"]
        template.description = template_options["description"]
        template.action_provider = template_options["action_provider"]
        template.action_provider_options = template_options[
            "action_provider_options"]
        template.type = template_options["type"]
        template.template = unquote(template_options["template"])
        logger.info("Imported template: %s" % template.name)
        template.save()
    else:
        print('ConfigTemplate %s already exists' % template_options['name'])

    if not InputForm.objects.filter(name=form_options['name']).exists():
        input_form = InputForm()
        input_form.name = form_options["name"]
        input_form.description = form_options["description"]
        input_form.instructions = form_options["instructions"]
        input_form.json = unquote(form_options["json"])
        input_form.script = template

        logger.info("Import input form: %s" % input_form.name)
        input_form.save()
    else:
        print('Input form %s already exists' % form_options['name'])
        input_form = InputForm.objects.get(name=form_options['name'])

    return input_form.id
示例#6
0
文件: views.py 项目: rickmur/keyframe
def create(request):
    required_fields = set(["config_template_id", "name", "description", "json"])
    if not required_fields.issubset(request.POST):
        return render(request, "error.html", {"error": "Invalid Parameters in POST"})

    template_id = request.POST["config_template_id"]
    name = request.POST["name"]
    description = request.POST["description"]
    json_data = request.POST["json"]
    instructions = request.POST["instructions"]

    config_template = get_object_or_404(ConfigTemplate, pk=template_id)

    input_form = InputForm()
    input_form.name = name
    input_form.description = description
    input_form.instructions = instructions
    input_form.json = json_data
    input_form.script = config_template
    input_form.save()
    return HttpResponseRedirect("/tools/%s" % template_id)