Example #1
0
def library_folder(request):
    config = get_user_config(request.user)
    params = request.GET
    lib_root = getParamDefault(params, "root", "")
    lib_folders = getParamDefault(params, "folders", "templates").split(",")
    widgets = []
    warning = None
    if remote_library:
        remote = "Connected to Google Drive"
    else:
        remote = "Not connected to Google Drive"
    try:
        for folder in lib_folders:
            folder_name = (lib_root + "/" + folder).replace(
                "Templates", "templates")
            subfolder = folder_name[folder_name.find("/") + 1:]
            files = folder_files(config,
                                 folder_name,
                                 fields="files(id, name, mimeType)")
            if lib_root.find("/") >= 0:
                parent_root = lib_root[:lib_root.rfind("/")]
                parent_folder = lib_root[lib_root.rfind("/") + 1:]
            else:
                parent_root = lib_root
                parent_folder = ""
            files.append({
                "isdir": True,
                "name": "..",
                "parent": {
                    "root": parent_root,
                    "folder": parent_folder
                }
            })
            files = sorted(files,
                           key=lambda k:
                           ('..' if k['isdir'] else k['ext']) + k['name'])
            widgets.append({
                "path":
                os.path.join("templates", subfolder),
                "subfolder":
                subfolder,
                "title":
                folder_name,
                "files":
                files,
                "glyph":
                "glyphicon glyphicon-file",
                "refreshForm":
                refresh_form(folder_name.replace("Templates", "templates"))
            })
    except GDriveAccessException:
        warning = "Not yet connected to a library"
        remote = "Not connected to Google Drive"
    return render(
        request, library_page, {
            "widgets": widgets,
            "install_display": install_display,
            "warning": warning,
            "remote": remote
        })
Example #2
0
def library_folder(request):
    config = get_user_config(request.user)
    params = request.GET
    lib_root = getParamDefault(params, "root", "")
    lib_folders = getParamDefault(params, "folders", "templates").split(",")
    widgets = []
    warning = None
    if remote_library:
        remote = "Connected to Google Drive"
    else:
        remote = "Not connected to Google Drive"
    try:
        for folder in lib_folders:
            folder_name =(lib_root+"/"+folder).replace("Templates", "templates")
            subfolder = folder_name[folder_name.find("/")+1:]
            files = folder_files(config, folder_name, fields="files(id, name, mimeType)")
            if lib_root.find("/")>=0:
                parent_root = lib_root[:lib_root.rfind("/")]
                parent_folder = lib_root[lib_root.rfind("/")+1:]
            else:
                parent_root = lib_root
                parent_folder = ""
            files.append({"isdir":True,"name":"..", "parent":{"root":parent_root, "folder":parent_folder}})
            files = sorted(files, key=lambda k: ('..' if k['isdir'] else k['ext'])+k['name']) 
            widgets.append({"path":os.path.join("templates", subfolder), "subfolder": subfolder, "title": folder_name, "files":files, "glyph":"glyphicon glyphicon-file", "refreshForm": refresh_form(folder_name.replace("Templates", "templates"))})
    except GDriveAccessException:
        warning = "Not yet connected to a library"
        remote = "Not connected to Google Drive"
    return render(request, library_page, {"widgets":widgets, "install_display": install_display, "warning":warning, "remote":remote})
Example #3
0
def test_result(mergeForm, request, method="POST"):
    config = get_user_config(request.user)
    warning = None
    navForm = None
    advMergeForm = None
    json_response = merge_raw_wrapped(request, method=method)
    try:
        params = request.GET
        hideforms = getParamDefault(params, "hide_forms", "N")
        template_subfolder = clean_subfolder(getParamDefault(params, "template_subfolder", ""))
        mergeJob=MergeJob(
            template_folder="templates/",
            template_subfolder = mergeForm["template_subfolder"].value(),
            template=mergeForm["template"].value(),
            output_folder="output",
            data_folder="test_data",
            data_file=mergeForm["data_file"].value(),
            branding_folder="branding",
            branding_file=mergeForm["branding_file"].value(),
            xform_folder="transforms",
            xform_file=mergeForm["xform_file"].value(),
            flow = mergeForm["flow"].value(),
            identifier = mergeForm["identifier"].value(),
            data_root = mergeForm["data_root"].value(),
        )
        navForm, mergeForm, advMergeForm = make_test_forms(config, mergeJob, template_subfolder)
        json_response = merge_raw_wrapped(request, method=method)
    except GDriveAccessException:
        warning = "Not yet connected to a library"
    return render(request, 'dash/test.html', {"sub_title": template_subfolder, "navForm":navForm, "mergeForm": mergeForm, "advMergeForm": advMergeForm, 'merge_response': json_response, "install_display": install_display, "hideforms":hideforms})
Example #4
0
def edit(request):
    cwd = get_working_dir()
    config = get_user_config(request.user)
    params = request.POST
    if len(params) == 0:
        params = request.GET
    edit_form = EditFileForm()
    #    test_form = ComposeTestForm()
    try:
        action = params["action"]
    except:
        action = "none"
    file_path = clean_subfolder(getParamDefault(params, "file_path", ""))
    file_name = getParamDefault(params, "file_name", "")
    file_content = getParamDefault(params, "file_content", "")
    file_folder = getParamDefault(params, "file_path", ".")
    if file_path == "":
        file_path = file_folder + "/"
    else:
        if file_path[0] == "/":
            file_path = file_path[1:]
    if not (file_name == "") and (file_content == ""):
        file_content = get_local_txt_content(cwd, config, file_path, file_name)
        file_content = file_content.replace("\n\n", "\n")

    if action == "save":
        file_content = params["file_content"]
        file_folder = params["file_folder"]
        if file_name.find(".") < 0:
            file_name = file_name + ".txt"
        file_path = file_folder
        push_local_txt(cwd, config, file_path, file_name, file_content)
        #print(edit_form)
    elif action == "nav":
        template_subfolder = clean_subfolder(
            getParamDefault(params, "template_subfolder", ""))
        edit_form.fields["template_subfolder"].initial = template_subfolder

    edit_form.fields["file_name"].initial = file_name
    edit_form.fields["file_name"].label = "File name"
    edit_form.fields["file_content"].initial = file_content
    edit_form.fields["file_content"].label = "File content"
    edit_form.fields["file_folder"].initial = file_folder

    return render(
        request, 'dash/edit.html', {
            "title": "Edit File",
            "glyph": "glyphicon glyphicon-cog",
            "form": edit_form,
            "install_display": install_display
        })
Example #5
0
def test(request):
    config = get_user_config(request.user)
    warning = None
    navForm = None
    mergeForm = None
    advMergeForm = None
    try:
        params = request.GET
        template_subfolder = clean_subfolder(
            getParamDefault(params, "template_subfolder", ""))
        mergeJob = MergeJob(
            template_folder="templates/",
            template_subfolder=template_subfolder,
            #template="AddParty_v3.md",
            output_folder="output",
            data_folder="test_data",
            branding_folder="branding",
            xform_folder="transforms",
            flow="md.txt",
            data_root="docroot")
        navForm, mergeForm, advMergeForm = make_test_forms(
            config, mergeJob, template_subfolder)
    except GDriveAccessException:
        warning = "Not yet connected to a library"
    return render(
        request, 'dash/test.html', {
            "sub_title": template_subfolder,
            "navForm": navForm,
            "mergeForm": mergeForm,
            "advMergeForm": advMergeForm,
            "install_display": install_display,
            "warning": warning,
            "hideforms": "N"
        })
Example #6
0
def edit(request):
    cwd = get_working_dir()
    config = get_user_config(request.user)
    params = request.POST
    if len(params)==0:
        params = request.GET
    edit_form = EditFileForm()
#    test_form = ComposeTestForm()
    try:
        action = params["action"]
    except:
        action = "none"
    file_path = clean_subfolder(getParamDefault(params, "file_path", ""))
    file_name= getParamDefault(params, "file_name", "")
    file_content= getParamDefault(params, "file_content", "")
    file_folder = getParamDefault(params, "file_path", ".")
    if file_path=="":
        file_path = file_folder+"/"
    else:
        if file_path[0]=="/":
            file_path= file_path[1:]
    if not(file_name =="") and (file_content==""):
        file_content = get_local_txt_content(cwd, config, file_path, file_name)
        file_content=file_content.replace("\n\n", "\n")

    if action=="save":
        file_content= params["file_content"]
        file_folder= params["file_folder"]
        if file_name.find(".")<0:
            file_name= file_name+".txt"
        file_path = file_folder
        push_local_txt(cwd, config, file_path, file_name, file_content)
        #print(edit_form)
    elif action=="nav":
        template_subfolder = clean_subfolder(getParamDefault(params, "template_subfolder", ""))
        edit_form.fields["template_subfolder"].initial=template_subfolder

    edit_form.fields["file_name"].initial=file_name
    edit_form.fields["file_name"].label="File name"
    edit_form.fields["file_content"].initial=file_content
    edit_form.fields["file_content"].label="File content"
    edit_form.fields["file_folder"].initial=file_folder


    return render(request, 'dash/edit.html', {"title":"Edit File", "glyph":"glyphicon glyphicon-cog", 
                         "form": edit_form, 
                          "install_display": install_display})
Example #7
0
def test_result(mergeForm, request, method="POST"):
    config = get_user_config(request.user)
    warning = None
    navForm = None
    advMergeForm = None
    json_response = merge_raw_wrapped(request, method=method)
    try:
        params = request.GET
        hideforms = getParamDefault(params, "hide_forms", "N")
        template_subfolder = clean_subfolder(
            getParamDefault(params, "template_subfolder", ""))
        mergeJob = MergeJob(
            template_folder="templates/",
            template_subfolder=mergeForm["template_subfolder"].value(),
            template=mergeForm["template"].value(),
            output_folder="output",
            data_folder="test_data",
            data_file=mergeForm["data_file"].value(),
            branding_folder="branding",
            branding_file=mergeForm["branding_file"].value(),
            xform_folder="transforms",
            xform_file=mergeForm["xform_file"].value(),
            flow=mergeForm["flow"].value(),
            identifier=mergeForm["identifier"].value(),
            data_root=mergeForm["data_root"].value(),
        )
        navForm, mergeForm, advMergeForm = make_test_forms(
            config, mergeJob, template_subfolder)
        json_response = merge_raw_wrapped(request, method=method)
    except GDriveAccessException:
        warning = "Not yet connected to a library"
    return render(
        request, 'dash/test.html', {
            "sub_title": template_subfolder,
            "navForm": navForm,
            "mergeForm": mergeForm,
            "advMergeForm": advMergeForm,
            'merge_response': json_response,
            "install_display": install_display,
            "hideforms": hideforms
        })
Example #8
0
def test(request):
    config = get_user_config(request.user)
    warning = None
    navForm = None
    mergeForm = None
    advMergeForm = None
    try:
        params = request.GET
        template_subfolder = clean_subfolder(getParamDefault(params, "template_subfolder", ""))
        mergeJob=MergeJob(
            template_folder="templates/",
            template_subfolder = template_subfolder,
            #template="AddParty_v3.md",
            output_folder="output",
            data_folder="test_data",
            branding_folder="branding",
            xform_folder="transforms",
            flow = "md.txt",
            data_root = "docroot"
            )
        navForm, mergeForm, advMergeForm = make_test_forms(config, mergeJob, template_subfolder)
    except GDriveAccessException:
        warning = "Not yet connected to a library"
    return render(request, 'dash/test.html', {"sub_title": template_subfolder, "navForm": navForm, "mergeForm": mergeForm, "advMergeForm": advMergeForm, "install_display": install_display, "warning":warning, "hideforms":"N"})
Example #9
0
def compose(request):
    cwd = get_working_dir()
    config = get_user_config(request.user)
    file_folder = "templates"
    template_folder = "templates"
    params = request.POST
    if len(params) == 0:
        params = request.GET

#   nav_form = ComposeNavForm()
#   nav_form.fields["template_subfolder"].initial="/"
    template_subfolder = "/"
    compose_form = ComposeTemplateForm()
    compose_form.fields["template_subfolder"].initial = "/"
    #    test_form = ComposeTestForm()
    try:
        action = params["action"]
    except:
        action = "none"
    template_path = clean_subfolder(getParamDefault(params, "file_path", ""))
    if template_path.find("/templates\\") == 0:
        subfolder_default = template_path[11:]
    else:
        subfolder_default = ""

    template_subfolder = clean_subfolder(
        getParamDefault(params, "template_subfolder", subfolder_default))
    file_name = getParamDefault(params, "file_name", "")
    file_content = getParamDefault(params, "file_content", "")
    template_test_case = getParamDefault(params, "template_test_case", "")
    test_case_xform = getParamDefault(params, "test_case_xform", "")
    template_stylesheet = getParamDefault(params, "template_stylesheet", "")
    stylesheet_content = getParamDefault(params, "template_stylesheet_content",
                                         "")
    template_sample = getParamDefault(params, "template_sample", "")
    rendered = ""
    render_type = "txt"
    if template_path == "":
        template_path = file_folder + template_subfolder
    else:
        if template_path[0] == "/":
            template_path = template_path[1:]
    if not (file_name == "") and (file_content == ""):
        file_content = get_local_txt_content(cwd, config, template_path,
                                             file_name)
        file_content = file_content.replace("\n\n", "\n")

    if action == "save":
        file_content = params["file_content"]
        if file_name.find(".") < 0:
            file_name = file_name + ".txt"
        template_path = file_folder + template_subfolder
        push_local_txt(cwd, config, template_path, file_name, file_content)
        #print(compose_form)
    elif action == "nav":
        template_subfolder = clean_subfolder(
            getParamDefault(params, "template_subfolder", ""))
        compose_form.fields["template_subfolder"].initial = template_subfolder
    elif action == "preview":
        try:
            subs = getData(config,
                           data_file=template_test_case,
                           local_data_folder="test_data")
        except:
            subs = {}
        try:
            subs = subs["docroot"]
        except:
            pass

        rendered = substituteVariablesPlainString(config, file_content, subs)
        render_type = "txt"
        if (file_name.find(".md")):  #fix needed
            rendered = convert_markdown_string(rendered)
            rendered = '<div class="echo-publish">' + rendered + "</div>"
            rendered = Pynliner().from_string(rendered).with_cssString(
                stylesheet_content).run()
            render_type = "md"
        ###
    if not (template_stylesheet == ""):
        stylesheet_content = get_local_txt_content(
            cwd, config, template_folder + template_subfolder,
            template_stylesheet)

    if not (template_test_case == ""):
        subs = getData(config,
                       data_file=template_test_case,
                       local_data_folder="test_data")
        try:
            subs = subs["docroot"]
        except:
            pass
        fields, groups, tree = fields_from_subs(subs)
        field_string = "Fields"
        for field in fields:
            field_string += "\n"
            field_string += "{{" + field + "}}"
        logic_string = "Logic"
        for field in fields:
            logic_string += "\n"
            logic_string += "{% if " + field + " == \"\" %}{% endif %}"
        group_string = "Groups"
        for field in fields:
            group_string += "\n"
            group_string += "{% for item in " + field + " %}{% endfor %}"
        template_sample = {
            "fields": field_string,
            "logic": logic_string,
            "groups": group_string
        }

    items = folder_files(config, "templates" + template_subfolder)
    folders, files = get_folders_and_files(template_subfolder, items)
    style_files = [(file["name"], file["name"]) for file in files
                   if file["name"].find(".css") > 0]
    template_files = [(file["name"], file["name"]) for file in files
                      if file["name"].find(".css") < 0]
    compose_form.fields['template_files'].choices = [("", "---")
                                                     ] + template_files
    compose_form.fields["file_name"].initial = file_name
    compose_form.fields["file_name"].label = "File name"
    compose_form.fields["file_content"].initial = file_content
    compose_form.fields["file_content"].label = "File content"
    compose_form.fields["template_subfolder"].initial = template_subfolder
    compose_form.fields['template_subfolder'].choices = [
        (folder["name"], folder["name"]) for folder in folders
    ]
    compose_form.fields["template_subfolder"].initial = template_subfolder
    compose_form.fields['template_test_case'].initial = template_test_case
    compose_form.fields['template_stylesheet'].choices = [("", "---")
                                                          ] + style_files
    compose_form.fields[
        'template_stylesheet_content'].initial = stylesheet_content
    #compose_form.fields['template_sample'].initial = template_sample
    data_files = folder_files(config, "test_data")
    data_files = sorted(data_files, key=lambda k: k['ext'] + k['name'])
    compose_form.fields['template_test_case'].choices = [("", "---")] + [
        (file["name"], file["name"]) for file in data_files
    ]
    data_files = folder_files(config, "transforms")
    data_files = sorted(data_files, key=lambda k: k['ext'] + k['name'])
    compose_form.fields['test_case_xform'].choices = [("", "---")] + [
        (file["name"], file["name"]) for file in data_files
    ]

    return render(
        request,
        compose_page,
        {
            "title": "Compose Template",
            "glyph": "glyphicon glyphicon-cog",
            "form": compose_form,
            "sub_title": template_subfolder,
            "sample":
            template_sample,  #"stylesheet_content": stylesheet_content, 
            "rendered": rendered,
            "render": render_type,
            "install_display": install_display
        })
Example #10
0
def compose(request):
    cwd = get_working_dir()
    config = get_user_config(request.user)
    file_folder = "templates"
    template_folder = "templates"
    params = request.POST
    if len(params)==0:
        params = request.GET
 #   nav_form = ComposeNavForm()
 #   nav_form.fields["template_subfolder"].initial="/"
    template_subfolder= "/"
    compose_form = ComposeTemplateForm()
    compose_form.fields["template_subfolder"].initial="/"
#    test_form = ComposeTestForm()
    try:
        action = params["action"]
    except:
        action = "none"
    template_path = clean_subfolder(getParamDefault(params, "file_path", ""))
    if template_path.find("/templates\\")==0:
        subfolder_default = template_path[11:]
    else:
        subfolder_default = ""

    template_subfolder = clean_subfolder(getParamDefault(params, "template_subfolder", subfolder_default))
    file_name= getParamDefault(params, "file_name", "")
    file_content= getParamDefault(params, "file_content", "")
    template_test_case= getParamDefault(params, "template_test_case", "")
    test_case_xform= getParamDefault(params, "test_case_xform", "")
    template_stylesheet= getParamDefault(params, "template_stylesheet", "")
    stylesheet_content = getParamDefault(params, "template_stylesheet_content", "")
    template_sample = getParamDefault(params, "template_sample", "")
    rendered = ""
    render_type = "txt"
    if template_path=="":
        template_path = file_folder+template_subfolder
    else:
        if template_path[0]=="/":
            template_path= template_path[1:]
    if not(file_name =="") and (file_content==""):
        file_content = get_local_txt_content(cwd, config, template_path, file_name)
        file_content=file_content.replace("\n\n", "\n")


    if action=="save":
        file_content= params["file_content"]
        if file_name.find(".")<0:
            file_name= file_name+".txt"
        template_path = file_folder+template_subfolder
        push_local_txt(cwd, config, template_path, file_name, file_content)
        #print(compose_form)
    elif action=="nav":
        template_subfolder = clean_subfolder(getParamDefault(params, "template_subfolder", ""))
        compose_form.fields["template_subfolder"].initial=template_subfolder
    elif action=="preview":
        try:
            subs = getData(config, data_file=template_test_case, local_data_folder="test_data")
        except:
            subs={}
        try:
            subs=subs["docroot"]
        except:
            pass

        rendered = substituteVariablesPlainString(config, file_content, subs)
        render_type = "txt"
        if (file_name.find(".md")):#fix needed
            rendered = convert_markdown_string(rendered)
            rendered = '<div class="echo-publish">'+rendered+"</div>"
            rendered = Pynliner().from_string(rendered).with_cssString(stylesheet_content).run()
            render_type = "md"
        ###
    if not(template_stylesheet==""):
        stylesheet_content = get_local_txt_content(cwd, config, template_folder+template_subfolder, template_stylesheet)

    if not(template_test_case==""):
        subs = getData(config, data_file=template_test_case, local_data_folder="test_data")
        try:
            subs=subs["docroot"]
        except:
            pass
        fields, groups, tree  = fields_from_subs(subs)
        field_string = "Fields"
        for field in fields:
            field_string+="\n"
            field_string+="{{"+field+"}}"
        logic_string = "Logic"
        for field in fields:
            logic_string+="\n"
            logic_string+="{% if "+field+" == \"\" %}{% endif %}"
        group_string = "Groups"
        for field in fields:
            group_string+="\n"
            group_string+="{% for item in "+field+" %}{% endfor %}"
        template_sample = {"fields":field_string, "logic":logic_string, "groups":group_string}

    items = folder_files(config, "templates"+template_subfolder)
    folders, files = get_folders_and_files(template_subfolder, items)
    style_files = [(file["name"],file["name"]) for file in files if file["name"].find(".css")>0]
    template_files = [(file["name"],file["name"]) for file in files if file["name"].find(".css")<0]
    compose_form.fields['template_files'].choices=[("","---")]+template_files
    compose_form.fields["file_name"].initial=file_name
    compose_form.fields["file_name"].label="File name"
    compose_form.fields["file_content"].initial=file_content
    compose_form.fields["file_content"].label="File content"
    compose_form.fields["template_subfolder"].initial=template_subfolder
    compose_form.fields['template_subfolder'].choices=[(folder["name"],folder["name"]) for folder in folders]
    compose_form.fields["template_subfolder"].initial=template_subfolder
    compose_form.fields['template_test_case'].initial = template_test_case
    compose_form.fields['template_stylesheet'].choices=[("","---")]+style_files
    compose_form.fields['template_stylesheet_content'].initial=stylesheet_content
    #compose_form.fields['template_sample'].initial = template_sample
    data_files = folder_files(config, "test_data")
    data_files = sorted(data_files, key=lambda k: k['ext']+k['name']) 
    compose_form.fields['template_test_case'].choices=[("","---")]+[(file["name"],file["name"]) for file in data_files]
    data_files = folder_files(config, "transforms")
    data_files = sorted(data_files, key=lambda k: k['ext']+k['name']) 
    compose_form.fields['test_case_xform'].choices=[("","---")]+[(file["name"],file["name"]) for file in data_files]

    return render(request, compose_page, {"title":"Compose Template", "glyph":"glyphicon glyphicon-cog", 
                         "form": compose_form, "sub_title":template_subfolder, "sample": template_sample, #"stylesheet_content": stylesheet_content, 
                          "rendered":rendered, "render":render_type, "install_display": install_display})