lots of typing fixes

This commit is contained in:
Iain Learmonth 2022-05-16 11:44:03 +01:00
parent 51f580a304
commit 3665c34961
43 changed files with 260 additions and 178 deletions

View file

@ -1,6 +1,8 @@
from datetime import datetime
from typing import Optional
from flask import Blueprint, flash, Response, render_template, redirect, url_for
from flask.typing import ResponseReturnValue
from flask_wtf import FlaskForm
from sqlalchemy import exc
from wtforms import StringField, SelectField, SubmitField
@ -22,7 +24,7 @@ def webhook_format_name(s: str) -> str:
return "Unknown"
class NewWebhookForm(FlaskForm):
class NewWebhookForm(FlaskForm): # type: ignore
description = StringField('Description', validators=[DataRequired()])
format = SelectField('Format', choices=[
("telegram", "Telegram"),
@ -33,7 +35,7 @@ class NewWebhookForm(FlaskForm):
@bp.route("/new", methods=['GET', 'POST'])
def webhook_new():
def webhook_new() -> ResponseReturnValue:
form = NewWebhookForm()
if form.validate_on_submit():
webhook = Webhook(
@ -53,7 +55,7 @@ def webhook_new():
@bp.route('/edit/<webhook_id>', methods=['GET', 'POST'])
def webhook_edit(webhook_id):
def webhook_edit(webhook_id: int) -> ResponseReturnValue:
webhook = Webhook.query.filter(Webhook.id == webhook_id).first()
if webhook is None:
return Response(render_template("error.html.j2",
@ -81,7 +83,7 @@ def webhook_edit(webhook_id):
@bp.route("/list")
def webhook_list():
def webhook_list() -> ResponseReturnValue:
webhooks = Webhook.query.all()
return render_template("list.html.j2",
section="webhook",
@ -92,8 +94,8 @@ def webhook_list():
@bp.route("/destroy/<webhook_id>", methods=['GET', 'POST'])
def webhook_destroy(webhook_id: int):
webhook = Webhook.query.filter(Webhook.id == webhook_id, Webhook.destroyed == None).first()
def webhook_destroy(webhook_id: int) -> ResponseReturnValue:
webhook: Optional[Webhook] = Webhook.query.filter(Webhook.id == webhook_id, Webhook.destroyed == None).first()
if webhook is None:
return response_404("The requested webhook could not be found.")
return view_lifecycle(