@admin_bp.route('/template/create', methods=['GET', 'POST'])
@login_required
@operator_role_required
def create_template():
    if (request.method == 'GET'):
        return render_template('template_add.html')
    if (request.method == 'POST'):
        try:
            name = request.form.getlist('name')[0]
            description = request.form.getlist('description')[0]
            if ((' ' in name) or (not name) or (not type)):
                flash('Please correct your input', 'error')
                return redirect(url_for('admin.create_template'))
            if DomainTemplate.query.filter((DomainTemplate.name == name)).first():
                flash('A template with the name {0} already exists!'.format(name), 'error')
                return redirect(url_for('admin.create_template'))
            t = DomainTemplate(name=name, description=description)
            result = t.create()
            if (result['status'] == 'ok'):
                history = History(msg='Add domain template {0}'.format(name), detail=json.dumps({'name': name, 'description': description}), created_by=current_user.username)
                history.add()
                return redirect(url_for('admin.templates'))
            else:
                flash(result['msg'], 'error')
                return redirect(url_for('admin.create_template'))
        except Exception as e:
            current_app.logger.error('Cannot create domain template. Error: {0}'.format(e))
            current_app.logger.debug(traceback.format_exc())
            abort(500)
@admin_bp.route('/template/create', methods=['GET', 'POST'])
@login_required
@operator_role_required
def create_template():
    if (request.method == 'GET'):
        return render_template('template_add.html')
    if (request.method == 'POST'):
        try:
            name = request.form.getlist('name')[0]
            description = request.form.getlist('description')[0]
            if ((' ' in name) or (not name) or (not type)):
                flash('Please correct your input', 'error')
                return redirect(url_for('admin.create_template'))
            if DomainTemplate.query.filter((DomainTemplate.name == name)).first():
                flash('A template with the name {0} already exists!'.format(name), 'error')
                return redirect(url_for('admin.create_template'))
            t = DomainTemplate(name=name, description=description)
            result = t.create()
            if (result['status'] == 'ok'):
                history = History(msg='Add domain template {0}'.format(name), detail=json.dumps({'name': name, 'description': description}), created_by=current_user.username)
                history.add()
                return redirect(url_for('admin.templates'))
            else:
                flash(result['msg'], 'error')
                return redirect(url_for('admin.create_template'))
        except Exception as e:
            current_app.logger.error('Cannot create domain template. Error: {0}'.format(e))
            current_app.logger.debug(traceback.format_exc())
            abort(500)