@admin_bp.route('/template/<path:template>/edit', methods=['GET'])
@login_required
@operator_role_required
def edit_template(template):
    try:
        t = DomainTemplate.query.filter((DomainTemplate.name == template)).first()
        records_allow_to_edit = Setting().get_records_allow_to_edit()
        quick_edit = Setting().get('record_quick_edit')
        ttl_options = Setting().get_ttl_options()
        if (t is not None):
            records = []
            for jr in t.records:
                if (jr.type in records_allow_to_edit):
                    record = DomainTemplateRecord(name=jr.name, type=jr.type, status=('Active' if jr.status else 'Disabled'), ttl=jr.ttl, data=jr.data, comment=(jr.comment if jr.comment else ''))
                    records.append(record)
            return render_template('template_edit.html', template=t.name, records=records, editable_records=records_allow_to_edit, quick_edit=quick_edit, ttl_options=ttl_options)
    except Exception as e:
        current_app.logger.error('Cannot open domain template page. DETAIL: {0}'.format(e))
        current_app.logger.debug(traceback.format_exc())
        abort(500)
    return redirect(url_for('admin.templates'))
@admin_bp.route('/template/<path:template>/edit', methods=['GET'])
@login_required
@operator_role_required
def edit_template(template):
    try:
        t = DomainTemplate.query.filter((DomainTemplate.name == template)).first()
        records_allow_to_edit = Setting().get_records_allow_to_edit()
        quick_edit = Setting().get('record_quick_edit')
        ttl_options = Setting().get_ttl_options()
        if (t is not None):
            records = []
            for jr in t.records:
                if (jr.type in records_allow_to_edit):
                    record = DomainTemplateRecord(name=jr.name, type=jr.type, status=('Active' if jr.status else 'Disabled'), ttl=jr.ttl, data=jr.data, comment=(jr.comment if jr.comment else ))
                    records.append(record)
            return render_template('template_edit.html', template=t.name, records=records, editable_records=records_allow_to_edit, quick_edit=quick_edit, ttl_options=ttl_options)
    except Exception as e:
        current_app.logger.error('Cannot open domain template page. DETAIL: {0}'.format(e))
        current_app.logger.debug(traceback.format_exc())
        abort(500)
    return redirect(url_for('admin.templates'))