lots of typing fixes
This commit is contained in:
parent
51f580a304
commit
3665c34961
43 changed files with 260 additions and 178 deletions
|
@ -1,6 +1,8 @@
|
|||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from flask import flash, redirect, url_for, render_template, Response, Blueprint
|
||||
from flask.typing import ResponseReturnValue
|
||||
from flask_wtf import FlaskForm
|
||||
from sqlalchemy import exc
|
||||
from wtforms import StringField, SelectField, SubmitField
|
||||
|
@ -14,7 +16,7 @@ from app.portal.util import response_404, view_lifecycle
|
|||
bp = Blueprint("onion", __name__)
|
||||
|
||||
|
||||
class NewOnionForm(FlaskForm):
|
||||
class NewOnionForm(FlaskForm): # type: ignore
|
||||
domain_name = StringField('Domain Name', validators=[DataRequired()])
|
||||
onion_name = StringField('Onion Name', validators=[DataRequired(), Length(min=56, max=56)],
|
||||
description="Onion service hostname, excluding the .onion suffix")
|
||||
|
@ -23,7 +25,7 @@ class NewOnionForm(FlaskForm):
|
|||
submit = SubmitField('Save Changes')
|
||||
|
||||
|
||||
class EditOnionForm(FlaskForm):
|
||||
class EditOnionForm(FlaskForm): # type: ignore
|
||||
description = StringField('Description', validators=[DataRequired()])
|
||||
group = SelectField('Group', validators=[DataRequired()])
|
||||
submit = SubmitField('Save Changes')
|
||||
|
@ -31,7 +33,7 @@ class EditOnionForm(FlaskForm):
|
|||
|
||||
@bp.route("/new", methods=['GET', 'POST'])
|
||||
@bp.route("/new/<group_id>", methods=['GET', 'POST'])
|
||||
def onion_new(group_id=None):
|
||||
def onion_new(group_id: Optional[int] = None) -> ResponseReturnValue:
|
||||
form = NewOnionForm()
|
||||
form.group.choices = [(x.id, x.group_name) for x in Group.query.all()]
|
||||
if form.validate_on_submit():
|
||||
|
@ -57,8 +59,8 @@ def onion_new(group_id=None):
|
|||
|
||||
|
||||
@bp.route('/edit/<onion_id>', methods=['GET', 'POST'])
|
||||
def onion_edit(onion_id):
|
||||
onion = Onion.query.filter(Onion.id == onion_id).first()
|
||||
def onion_edit(onion_id: int) -> ResponseReturnValue:
|
||||
onion: Optional[Onion] = Onion.query.filter(Onion.id == onion_id).first()
|
||||
if onion is None:
|
||||
return Response(render_template("error.html.j2",
|
||||
section="onion",
|
||||
|
@ -83,7 +85,7 @@ def onion_edit(onion_id):
|
|||
|
||||
|
||||
@bp.route("/list")
|
||||
def onion_list():
|
||||
def onion_list() -> ResponseReturnValue:
|
||||
onions = Onion.query.order_by(Onion.domain_name).all()
|
||||
return render_template("list.html.j2",
|
||||
section="onion",
|
||||
|
@ -94,7 +96,7 @@ def onion_list():
|
|||
|
||||
|
||||
@bp.route("/destroy/<onion_id>", methods=['GET', 'POST'])
|
||||
def onion_destroy(onion_id: int):
|
||||
def onion_destroy(onion_id: int) -> ResponseReturnValue:
|
||||
onion = Onion.query.filter(Onion.id == onion_id, Onion.destroyed == None).first()
|
||||
if onion is None:
|
||||
return response_404("The requested onion service could not be found.")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue