Esempio n. 1
0
def merge_raw(request, method="POST"):
    config = get_user_config(request.user)
    if method=="GET":
        params = request.GET
    else:
        params = request.POST
    abs_uri = request.build_absolute_uri()            
    protocol, uri = abs_uri.split("://")
    site = protocol+"://"+uri.split("/")[0]+"/"
    id = getParamDefault(params, "identifier", str(randint(0,1000000)))
    if MULTI_TENANTED:
        tenant_extension = "/"+config.tenant
    else:
        tenant_extension = ""

    flowFolder = getParamDefault(params, "flow_folder", "/"+gdrive_root+tenant_extension+"/Flows")
    flow = getParamDefault(params, "flow", "md")
    remoteTemplateFolder = getParamDefault(params, "template_folder", "/"+gdrive_root+tenant_extension+"/Templates")
    remoteOutputFolder = getParamDefault(params, "output_folder", "/"+gdrive_root+tenant_extension+"/Output")
    template_subfolder = getParamDefault(params, "template_subfolder", None)
    output_subfolder = getParamDefault(params, "output_subfolder", None)
    payload = getParamDefault(params, "payload", None, preserve_plus=True)
    payload_type = getParamDefault(params, "payload_type", None)
    test_case = getParamDefault(params, "test_case", None)
    data_folder = getParamDefault(params, "data_folder", "/"+gdrive_root+tenant_extension+"/Test Data")
    data_file = getParamDefault(params, "data_file", None)
    data_root = getParamDefault(params, "data_root", "docroot")
    branding_folder = getParamDefault(params, "branding_folder", "/"+gdrive_root+tenant_extension+"/Branding")
    branding_file = getParamDefault(params, "branding_file", None)
    if branding_file == "None":
        branding_file = None
    xform_folder = getParamDefault(params, "xform_folder", "/"+gdrive_root+tenant_extension+"/Transforms")
    xform_file = getParamDefault(params, "xform_file", None)
    if xform_file == "None":
        xform_file = None
    templateName = getParamDefault(params, "template", "AddParty.md")
    email = getParamDefault(params, "email", "*****@*****.**")
    templateName = templateName.replace("\\", "/")
    if template_subfolder:
        template_subfolder = template_subfolder.replace("\\", "/")
    subs = getData(config, test_case=test_case, payload=payload, payload_type=payload_type, params = params, local_data_folder="test_data", remote_data_folder = data_folder, data_file=data_file, xform_folder = xform_folder, xform_file=xform_file)
    if data_root:
        if data_root in subs:
            subs = subs[data_root]
#        else:
#            raise ValueError("Invalid data_root: " + data_root)
    if branding_file:
        branding_subs = getData(config, local_data_folder = "branding", remote_data_folder = branding_folder, data_file=branding_file)
        subs["branding"]= branding_subs
        subs["AgreementDate"]=datetime.now()
    subs["docs"]=[templateName]
    #subs["roles"]=[
    #    {"called":"Landlord", "values":["PropertyOwner", "AdditionalLandlord"]},
    #    {"called":"Tenant", "values":["ManuallyInvitedTenant", "AdditionalTenant"]},
    #    {"called":"Guarantor", "values":["Guarantor"]},
    #]    
    subs["site"]= site
#    return mergeDocument(flowFolder, flow, remoteTemplateFolder, templateName, id, subs, remoteOutputFolder, email=email, payload=payload)    
    return mergeDocument(config, flowFolder, flow, remoteTemplateFolder, template_subfolder, templateName, id, subs, 
                        remoteOutputFolder, output_subfolder, email=email, payload=payload)    
Esempio n. 2
0
def compose_preview(request):
    config = get_user_config(request.user)
    params = request.GET
    template_content = getParamDefault(params, "template_content", "")
    template_test_case = getParamDefault(params, "template_test_case", "")
    test_case_xform = getParamDefault(params, "test_case_xform", None)
    stylesheet_content = getParamDefault(params, "template_stylesheet_content",
                                         "")
    try:
        subs = getData(config,
                       data_file=template_test_case,
                       local_data_folder="test_data",
                       xform_file=test_case_xform)
    except:
        subs = {}
    try:
        subs = subs["docroot"]
    except:
        pass

    template_content = preprocess(template_content)
    rendered = substituteVariablesPlainString(config, template_content, subs)
    rendered = convert_markdown_string(rendered)
    rendered = '<div class="echo-publish">' + rendered + "</div>"
    rendered = Pynliner().from_string(rendered).with_cssString(
        stylesheet_content).run()
    return JsonResponse({"preview": rendered})
Esempio n. 3
0
def sample_data(request):
    config = get_user_config(request.user)
    params = request.GET
    template_test_case= getParamDefault(params, "template_test_case", "")
    test_case_xform= getParamDefault(params, "test_case_xform", None)
    filter_param= getParamDefault(params, "filter", None)
    parent_param= getParamDefault(params, "parent", None)
    if filter_param=="docroot":
        filter_param = None
    if filter_param:
        filter_string1=filter_param+"."
    else:
        filter_string1 = None
    if filter_param:
        filter_string2=filter_param+"_item."
    else:
        filter_string2 = None
    if parent_param and not (parent_param =="docroot"):
        filter_string1=parent_param+"."+filter_string1
        filter_string3=parent_param+"_item."+filter_param+"."
        filter_string4=parent_param+"_item."+filter_param+"_item."
    else:
        filter_string3 = "#"
        filter_string4 = "#"
    try:
        subs = getData(config, data_file=template_test_case, local_data_folder="test_data", xform_file=test_case_xform)
    except:
        subs={}
    #try:
    #    subs=subs["docroot"]
    #except:
    #    pass

    fields, groups, tree = fields_from_subs(subs)
    field_string = "Fields"
    for field in sorted(fields.keys()):
        if ((not filter_param) or (clean_field(field)+".").find(filter_string1)>=0 or clean_field(field).find(filter_string2)>=0 
                                    or clean_field(field).find(filter_string3)>=0 or clean_field(field).find(filter_string4)>=0):
                field_string+="\n"
                field_string+='<pre onclick="clip(this);" class="field">'+"{{"+clean_field(field)+"}}"+"</pre>"
    logic_string = "Logic"
    for field in sorted(fields):
        if ((not filter_param) or (clean_field(field)+".").find(filter_string1)>=0 or clean_field(field).find(filter_string2)>=0 
                                    or clean_field(field).find(filter_string3)>=0 or clean_field(field).find(filter_string4)>=0):
                logic_string+="\n"
                logic_string+='<pre onclick="clip(this);" class="field">'+"{% if "+clean_field(field)+" == \""+str(fields[field])+"\" %}{% endif %}"+"</pre>"
    group_string = "Groups"
    for field in sorted(groups):
        if ((not filter_param) or (clean_field(field)+".").find(filter_string1)>=0 or clean_field(field).find(filter_string2)>=0
                                    or clean_field(field).find(filter_string3)>=0 or clean_field(field).find(filter_string4)>=0):
                group_string+="\n"
                itemname = field[1+field.rfind("."):]+"_item"
                group_string+='<pre onclick="clip(this);" class="field">'+"{% for "+itemname+" in "+field.replace("docroot.","")+" %}{% endfor %}"+"</pre>"
    template_sample = {
            "fields": field_string,
            "logic": logic_string, 
            "groups":group_string,
            "tree": tree,
            };
    return JsonResponse({"sample":template_sample})
Esempio n. 4
0
def compose_preview(request):
    config = get_user_config(request.user)
    params = request.GET
    template_content= getParamDefault(params, "template_content", "")
    template_test_case= getParamDefault(params, "template_test_case", "")
    test_case_xform= getParamDefault(params, "test_case_xform", None)
    stylesheet_content = getParamDefault(params, "template_stylesheet_content", "")
    try:
        subs = getData(config, data_file=template_test_case, local_data_folder="test_data", xform_file=test_case_xform)
    except:
        subs={}
    try:
        subs=subs["docroot"]
    except:
        pass

    template_content  = preprocess(template_content)
    rendered = substituteVariablesPlainString(config, template_content, subs)
    rendered = convert_markdown_string(rendered)
    rendered = '<div class="echo-publish">'+rendered+"</div>"
    rendered = Pynliner().from_string(rendered).with_cssString(stylesheet_content).run()
    return JsonResponse({"preview":rendered})
Esempio n. 5
0
def sample_data(request):
    config = get_user_config(request.user)
    params = request.GET
    template_test_case = getParamDefault(params, "template_test_case", "")
    test_case_xform = getParamDefault(params, "test_case_xform", None)
    filter_param = getParamDefault(params, "filter", None)
    parent_param = getParamDefault(params, "parent", None)
    if filter_param == "docroot":
        filter_param = None
    if filter_param:
        filter_string1 = filter_param + "."
    else:
        filter_string1 = None
    if filter_param:
        filter_string2 = filter_param + "_item."
    else:
        filter_string2 = None
    if parent_param and not (parent_param == "docroot"):
        filter_string1 = parent_param + "." + filter_string1
        filter_string3 = parent_param + "_item." + filter_param + "."
        filter_string4 = parent_param + "_item." + filter_param + "_item."
    else:
        filter_string3 = "#"
        filter_string4 = "#"
    try:
        subs = getData(config,
                       data_file=template_test_case,
                       local_data_folder="test_data",
                       xform_file=test_case_xform)
    except:
        subs = {}
    #try:
    #    subs=subs["docroot"]
    #except:
    #    pass

    fields, groups, tree = fields_from_subs(subs)
    field_string = "Fields"
    for field in sorted(fields.keys()):
        if ((not filter_param)
                or (clean_field(field) + ".").find(filter_string1) >= 0
                or clean_field(field).find(filter_string2) >= 0
                or clean_field(field).find(filter_string3) >= 0
                or clean_field(field).find(filter_string4) >= 0):
            field_string += "\n"
            field_string += '<pre onclick="clip(this);" class="field">' + "{{" + clean_field(
                field) + "}}" + "</pre>"
    logic_string = "Logic"
    for field in sorted(fields):
        if ((not filter_param)
                or (clean_field(field) + ".").find(filter_string1) >= 0
                or clean_field(field).find(filter_string2) >= 0
                or clean_field(field).find(filter_string3) >= 0
                or clean_field(field).find(filter_string4) >= 0):
            logic_string += "\n"
            logic_string += '<pre onclick="clip(this);" class="field">' + "{% if " + clean_field(
                field) + " == \"" + str(
                    fields[field]) + "\" %}{% endif %}" + "</pre>"
    group_string = "Groups"
    for field in sorted(groups):
        if ((not filter_param)
                or (clean_field(field) + ".").find(filter_string1) >= 0
                or clean_field(field).find(filter_string2) >= 0
                or clean_field(field).find(filter_string3) >= 0
                or clean_field(field).find(filter_string4) >= 0):
            group_string += "\n"
            itemname = field[1 + field.rfind("."):] + "_item"
            group_string += '<pre onclick="clip(this);" class="field">' + "{% for " + itemname + " in " + field.replace(
                "docroot.", "") + " %}{% endfor %}" + "</pre>"
    template_sample = {
        "fields": field_string,
        "logic": logic_string,
        "groups": group_string,
        "tree": tree,
    }
    return JsonResponse({"sample": template_sample})
Esempio n. 6
0
def merge_raw(request, method="POST"):
    config = get_user_config(request.user)
    if method == "GET":
        params = request.GET
    else:
        params = request.POST
    abs_uri = request.build_absolute_uri()
    protocol, uri = abs_uri.split("://")
    site = protocol + "://" + uri.split("/")[0] + "/"
    id = getParamDefault(params, "identifier", str(randint(0, 1000000)))
    if MULTI_TENANTED:
        tenant_extension = "/" + config.tenant
    else:
        tenant_extension = ""

    flowFolder = getParamDefault(
        params, "flow_folder", "/" + gdrive_root + tenant_extension + "/Flows")
    flow = getParamDefault(params, "flow", "md")
    remoteTemplateFolder = getParamDefault(
        params, "template_folder",
        "/" + gdrive_root + tenant_extension + "/Templates")
    remoteOutputFolder = getParamDefault(
        params, "output_folder",
        "/" + gdrive_root + tenant_extension + "/Output")
    template_subfolder = getParamDefault(params, "template_subfolder", None)
    output_subfolder = getParamDefault(params, "output_subfolder", None)
    payload = getParamDefault(params, "payload", None, preserve_plus=True)
    payload_type = getParamDefault(params, "payload_type", None)
    test_case = getParamDefault(params, "test_case", None)
    data_folder = getParamDefault(
        params, "data_folder",
        "/" + gdrive_root + tenant_extension + "/Test Data")
    data_file = getParamDefault(params, "data_file", None)
    data_root = getParamDefault(params, "data_root", "docroot")
    branding_folder = getParamDefault(
        params, "branding_folder",
        "/" + gdrive_root + tenant_extension + "/Branding")
    branding_file = getParamDefault(params, "branding_file", None)
    if branding_file == "None":
        branding_file = None
    xform_folder = getParamDefault(
        params, "xform_folder",
        "/" + gdrive_root + tenant_extension + "/Transforms")
    xform_file = getParamDefault(params, "xform_file", None)
    if xform_file == "None":
        xform_file = None
    templateName = getParamDefault(params, "template", "AddParty.md")
    email = getParamDefault(params, "email",
                            "*****@*****.**")
    templateName = templateName.replace("\\", "/")
    if template_subfolder:
        template_subfolder = template_subfolder.replace("\\", "/")
    subs = getData(config,
                   test_case=test_case,
                   payload=payload,
                   payload_type=payload_type,
                   params=params,
                   local_data_folder="test_data",
                   remote_data_folder=data_folder,
                   data_file=data_file,
                   xform_folder=xform_folder,
                   xform_file=xform_file)
    if data_root:
        if data_root in subs:
            subs = subs[data_root]


#        else:
#            raise ValueError("Invalid data_root: " + data_root)
    if branding_file:
        branding_subs = getData(config,
                                local_data_folder="branding",
                                remote_data_folder=branding_folder,
                                data_file=branding_file)
        subs["branding"] = branding_subs
        subs["AgreementDate"] = datetime.now()
    subs["docs"] = [templateName]
    #subs["roles"]=[
    #    {"called":"Landlord", "values":["PropertyOwner", "AdditionalLandlord"]},
    #    {"called":"Tenant", "values":["ManuallyInvitedTenant", "AdditionalTenant"]},
    #    {"called":"Guarantor", "values":["Guarantor"]},
    #]
    subs["site"] = site
    #    return mergeDocument(flowFolder, flow, remoteTemplateFolder, templateName, id, subs, remoteOutputFolder, email=email, payload=payload)
    return mergeDocument(config,
                         flowFolder,
                         flow,
                         remoteTemplateFolder,
                         template_subfolder,
                         templateName,
                         id,
                         subs,
                         remoteOutputFolder,
                         output_subfolder,
                         email=email,
                         payload=payload)
Esempio n. 7
0
def bulk_merge_raw(request, method="POST"):
    config = get_user_config(request.user)
    if method == "GET":
        params = request.GET
    else:
        params = request.POST
    abs_uri = request.build_absolute_uri()
    protocol, uri = abs_uri.split("://")
    site = protocol + "://" + uri.split("/")[0] + "/"
    # todo better way of id. Dot plus serial?
    id = getParamDefault(params, "identifier", str(randint(0, 10000)))
    if MULTI_TENANTED:
        tenant_extension = "/" + config.tenant
    else:
        tenant_extension = ""

    flowFolder = getParamDefault(
        params, "flow_folder", "/" + gdrive_root + tenant_extension + "/Flows")
    flow = getParamDefault(params, "flow", "md")
    remoteTemplateFolder = getParamDefault(
        params, "template_folder",
        "/" + gdrive_root + tenant_extension + "/Templates")
    remoteOutputFolder = getParamDefault(
        params, "output_folder",
        "/" + gdrive_root + tenant_extension + "/Output")
    template_subfolder = getParamDefault(params, "template_subfolder", None)
    output_subfolder = getParamDefault(params, "output_subfolder", None)

    data_folder = getParamDefault(
        params, "data_folder",
        "/" + gdrive_root + tenant_extension + "/Test Data")
    data_file = getParamDefault(params, "data_file", None)
    data_root = getParamDefault(params, "data_root", "docroot")

    branding_folder = getParamDefault(
        params, "branding_folder",
        "/" + gdrive_root + tenant_extension + "/Branding")
    branding_file = getParamDefault(params, "branding_file", None)
    if branding_file == "None":
        branding_file = None

    xform_folder = getParamDefault(
        params, "xform_folder",
        "/" + gdrive_root + tenant_extension + "/Transforms")
    xform_file = getParamDefault(params, "xform_file", None)
    if xform_file == "None":
        xform_file = None
    templateName = getParamDefault(params, "template", "AddParty.md")
    #Hmmm
    email = getParamDefault(params, "email",
                            "*****@*****.**")
    templateName = templateName.replace("\\", "/")
    if template_subfolder:
        template_subfolder = template_subfolder.replace("\\", "/")

    if branding_file:
        branding_subs = getData(config,
                                local_data_folder="branding",
                                remote_data_folder=branding_folder,
                                data_file=branding_file)

    condition = getParamDefault(params, "condition", "True")
    test = getParamDefault(params, "test", "True")
    testemail = getParamDefault(params, "testemail", "*****@*****.**")

    bulk_data = read_bulk_data(data_file, condition, test, testemail, config)
    results = []
    for subs in bulk_data:
        # This within a bulk loop
        if data_root:
            if data_root in subs:
                subs = subs[data_root]
        if branding_file:
            subs["branding"] = branding_subs
        subs["NowDate"] = datetime.now()
        subs["docs"] = [templateName]

        subs["site"] = site

        results += [
            mergeDocument(config,
                          flowFolder,
                          flow,
                          remoteTemplateFolder,
                          template_subfolder,
                          templateName,
                          id,
                          subs,
                          remoteOutputFolder,
                          output_subfolder,
                          email=subs["email"],
                          payload="")
        ]
    return {"bulk_result": results}
Esempio n. 8
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
        })
Esempio n. 9
0
def bulk_merge_raw(request, method="POST"):
    config = get_user_config(request.user)
    if method=="GET":
        params = request.GET
    else:
        params = request.POST
    abs_uri = request.build_absolute_uri()            
    protocol, uri = abs_uri.split("://")
    site = protocol+"://"+uri.split("/")[0]+"/"
    # todo better way of id. Dot plus serial?
    id = getParamDefault(params, "identifier", str(randint(0,10000)))
    if MULTI_TENANTED:
        tenant_extension = "/"+config.tenant
    else:
        tenant_extension = ""

    flowFolder = getParamDefault(params, "flow_folder", "/"+gdrive_root+tenant_extension+"/Flows")
    flow = getParamDefault(params, "flow", "md")
    remoteTemplateFolder = getParamDefault(params, "template_folder", "/"+gdrive_root+tenant_extension+"/Templates")
    remoteOutputFolder = getParamDefault(params, "output_folder", "/"+gdrive_root+tenant_extension+"/Output")
    template_subfolder = getParamDefault(params, "template_subfolder", None)
    output_subfolder = getParamDefault(params, "output_subfolder", None)

    data_folder = getParamDefault(params, "data_folder", "/"+gdrive_root+tenant_extension+"/Test Data")
    data_file = getParamDefault(params, "data_file", None)
    data_root = getParamDefault(params, "data_root", "docroot")

    branding_folder = getParamDefault(params, "branding_folder", "/"+gdrive_root+tenant_extension+"/Branding")
    branding_file = getParamDefault(params, "branding_file", None)
    if branding_file == "None":
        branding_file = None

    xform_folder = getParamDefault(params, "xform_folder", "/"+gdrive_root+tenant_extension+"/Transforms")
    xform_file = getParamDefault(params, "xform_file", None)
    if xform_file == "None":
        xform_file = None
    templateName = getParamDefault(params, "template", "AddParty.md")
    #Hmmm
    email = getParamDefault(params, "email", "*****@*****.**")
    templateName = templateName.replace("\\", "/")
    if template_subfolder:
        template_subfolder = template_subfolder.replace("\\", "/")

    if branding_file:
        branding_subs = getData(config, local_data_folder = "branding", remote_data_folder = branding_folder, data_file=branding_file)

    condition = getParamDefault(params, "condition", "True")
    test = getParamDefault(params, "test", "True")
    testemail = getParamDefault(params, "testemail", "*****@*****.**")


    bulk_data = read_bulk_data(data_file, condition, test, testemail, config)
    results = []
    for subs in bulk_data:
    # This within a bulk loop
        if data_root:
            if data_root in subs:
                subs = subs[data_root]
        if branding_file:
            subs["branding"]= branding_subs
        subs["NowDate"]=datetime.now()
        subs["docs"]=[templateName]

        subs["site"]= site


        results+= [mergeDocument(config, flowFolder, flow, remoteTemplateFolder, template_subfolder, templateName, id, subs, 
                        remoteOutputFolder, output_subfolder, email=subs["email"], payload="")]
    return {"bulk_result":results}    
Esempio n. 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})