tools/views.py
def clone(request, template_id):
    """
    Clones a template. Allows quickly creating new templates from existing ones.

    :param request:
    :param template_id: id of the template to be cloned
    :return: redirect to edit screen of new template!
    """
    template = get_object_or_404(ConfigTemplate, pk=template_id)

    # create our Dolly the sheep (clone)
    dolly = ConfigTemplate()
    dolly.name = template.name + " Clone"
    dolly.description = template.description
    dolly.action_provider = template.action_provider
    dolly.action_provider_options = template.action_provider_options
    dolly.template = template.template
    dolly.type = template.type

    print("Cloning template %s" % template.name)
    dolly.save()
    dollies_id = dolly.id

    # attempt to save any existing input form associations on the session
    # we'll retrieve this later when creating a new input form
    try:
        input_form = InputForm.objects.get(script=template)

        if 'cloned_templates' in request.session:
            cloned_templates = request.session['cloned_templates']
        else:
            cloned_templates = dict()

        cloned_templates[dollies_id] = dict()
        cloned_templates[dollies_id]['cloned_from'] = template.id
        cloned_templates[dollies_id]['input_form_id'] = input_form.id
        print('added a template to the cloned templates cache in the session')
        print(dollies_id)

        request.session['cloned_templates'] = cloned_templates

    except InputForm.DoesNotExist as dne:
        print('Could not find input_form for this cloned template')

    return HttpResponseRedirect('/tools/edit/%s/' % dolly.id)

    Clones a template. Allows quickly creating new templates from existing ones.

    :param request:
    :param template_id: id of the template to be cloned
    :return: redirect to edit screen of new template!
    
Clones a template. Allows quickly creating new templates from existing ones.
Clones a template . Allows quickly creating new templates from existing ones .
def clone(request, template_id):
    template = get_object_or_404(ConfigTemplate, pk=template_id)
    dolly = ConfigTemplate()
    dolly.name = template.name + " Clone"
    dolly.description = template.description
    dolly.action_provider = template.action_provider
    dolly.action_provider_options = template.action_provider_options
    dolly.template = template.template
    dolly.type = template.type
    print("Cloning template %s" % template.name)
    dolly.save()
    dollies_id = dolly.id
    try:
        input_form = InputForm.objects.get(script=template)
        if 'cloned_templates' in request.session:
            cloned_templates = request.session['cloned_templates']
        else:
            cloned_templates = dict()
        cloned_templates[dollies_id] = dict()
        cloned_templates[dollies_id]['cloned_from'] = template.id
        cloned_templates[dollies_id]['input_form_id'] = input_form.id
        print('added a template to the cloned templates cache in the session')
        print(dollies_id)
        request.session['cloned_templates'] = cloned_templates
    except InputForm.DoesNotExist as dne:
        print('Could not find input_form for this cloned template')
    return HttpResponseRedirect('/tools/edit/%s/' % dolly.id)
def clone ( request , template_id ) : template = get_object_or_404 ( ConfigTemplate , pk = template_id ) dolly = ConfigTemplate ( ) dolly . name = template . name + " Clone" dolly . description = template . description dolly . action_provider = template . action_provider dolly . action_provider_options = template . action_provider_options dolly . template = template . template dolly . type = template . type print ( "Cloning template %s" % template . name ) dolly . save ( ) dollies_id = dolly . id try : input_form = InputForm . objects . get ( script = template ) if 'cloned_templates' in request . session : cloned_templates = request . session [ 'cloned_templates' ] else : cloned_templates = dict ( ) cloned_templates [ dollies_id ] = dict ( ) cloned_templates [ dollies_id ] [ 'cloned_from' ] = template . id cloned_templates [ dollies_id ] [ 'input_form_id' ] = input_form . id print ( 'added a template to the cloned templates cache in the session' ) print ( dollies_id ) request . session [ 'cloned_templates' ] = cloned_templates except InputForm . DoesNotExist as dne : print ( 'Could not find input_form for this cloned template' ) return HttpResponseRedirect ( '/tools/edit/%s/' % dolly . id )
Clones a template.
Clones a template .
"""
    Clones a template. Allows quickly creating new templates from existing ones.

    :param request:
    :param template_id: id of the template to be cloned
    :return: redirect to edit screen of new template!
    """ # create our Dolly the sheep (clone) # attempt to save any existing input form associations on the session # we'll retrieve this later when creating a new input form
redirect to edit screen of new template!
redirect to edit screen of new template!
request
None
template_id
id of the template to be cloned
id of the template to be cloned