tmpl-flask/flaskapp/admin.py

44 lines
1 KiB
Python
Raw Normal View History

"""Admin routes"""
from flask import request, redirect
from flask import render_template
from . import routes
from . import forms
from . import db
class RouteAdmin(routes.Routes):
"""Admin endpoints: GET and POST /add"""
def add_routes(self) -> None:
"""Add admin routes"""
@self.app.route('/add', methods=['GET', 'POST'])
def add_person():
form = forms.AddForm()
if request.method == 'GET':
return render_template(
'admin.html',
form=form,
)
if form.pswd.data != '1234':
return 'Incorrect password', 403
cur = db.get_cursor()
cur.execute(
f'insert into {db.TABLE} '
'(email,name,age) values (%s,%s,%s)',
(
form.email.data,
form.name.data,
form.age.data,
),
)
cur.close()
return redirect('/db')