コード例 #1
0
def do_dump():
    res = ""

    for m in mappings_by_template(1):
        res += m.mappings_json + "\n"
        res += m.replacements_json + "\n\n"

    return res
コード例 #2
0
ファイル: template.py プロジェクト: strangedev/batch-docx
def delete_template(template_to_delete):

    for usergroup in usergroups_by_template(template_to_delete.id):
        revoke_access(usergroup, template_to_delete)

    for manglermapping in mappings_by_template(template_to_delete.id):
        delete_manglermapping(manglermapping)

    cur = bean.get_db().cursor()
    cur.execute("DELETE FROM template "
                "WHERE id = ?", [template_to_delete.id])

    del template_to_delete
コード例 #3
0
ファイル: template.py プロジェクト: strangedev/batch-docx
def duplicate_template(template_to_duplicate):
    result_name = "{} Kopie".format(template_to_duplicate.name)
    result_path = template_to_duplicate.path
    result_owner = template_to_duplicate.owner

    result_template = new_template(result_name, result_path, result_owner)

    for usergroup in usergroups_by_template(template_to_duplicate.id):
        if usergroup.id == result_template.owner:
            continue

        grant_access(usergroup, result_template)

    for manglermapping in mappings_by_template(template_to_duplicate.id):
        duplicate_mapping = new_manglermapping(result_template.id,
                                               manglermapping.name)
        duplicate_mapping.mappings_json = manglermapping.mappings_json
        duplicate_mapping.replacements_json = manglermapping.replacements_json

    return result_template
コード例 #4
0
def do_swap_template():
    t_id = request.form.get("t_id")

    previous_page = redirect("template_detail?id={}".format(t_id))

    if 'file' not in request.files:
        return previous_page

    file = request.files['file']

    if file.filename == '':
        return previous_page

    if file and file.filename.rsplit('.', 1)[1].lower().startswith("doc"):

        filename = secure_filename(file.filename)
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)

        if os.path.exists(file_path):
            os.remove(file_path)

        file.save(file_path)

        class Dummy(object):
            def __init__(self, path):
                self.path = path

        existing_template = Template(t_id)
        existing_template.path = file_path
        existing_template.name = filename

        dummy_template = Dummy(file_path)
        mangler = Mangler(dummy_template)
        dummy_mapping = mangler.mapping_template

        for m in mappings_by_template(t_id):
            m.merge_from(dummy_mapping,
                         keep_own_values=True,
                         exclusive_merge=True)

        return previous_page
コード例 #5
0
def show_template_detail():
    template_id = request.args.get("id")
    template = Template(template_id)
    attributes = [("Hinzugefügt am", template.date_added),
                  ("Zuletzt verwendet am", template.date_last_used)]

    all_mappings = mappings_by_template(template_id)
    mappings = [(m.id, m.name, m.date_added, m.date_last_used)
                for m in all_mappings]

    all_users = all_usergroups()
    users = [(u.id, u.name) for u in all_users]
    granted_users = [(u.id, u.name) for u in usergroups_by_template(template)]

    return render_template("template_detail.html",
                           current_username=current_username(),
                           page="templates",
                           users=users,
                           granted_users=granted_users,
                           template_id=template_id,
                           name=template.name,
                           attributes=attributes,
                           mappings=mappings)