lint: reformat python code with black
This commit is contained in:
parent
331beb01b4
commit
a406a7974b
88 changed files with 2579 additions and 1608 deletions
|
@ -1,8 +1,7 @@
|
|||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
from flask import (Blueprint, Response, flash, redirect, render_template,
|
||||
url_for)
|
||||
from flask import Blueprint, Response, flash, redirect, render_template, url_for
|
||||
from flask.typing import ResponseReturnValue
|
||||
from flask_wtf import FlaskForm
|
||||
from sqlalchemy import exc
|
||||
|
@ -26,47 +25,54 @@ def webhook_format_name(key: str) -> str:
|
|||
|
||||
|
||||
class NewWebhookForm(FlaskForm): # type: ignore
|
||||
description = StringField('Description', validators=[DataRequired()])
|
||||
format = SelectField('Format', choices=[
|
||||
("telegram", "Telegram"),
|
||||
("matrix", "Matrix")
|
||||
], validators=[DataRequired()])
|
||||
url = StringField('URL', validators=[DataRequired()])
|
||||
submit = SubmitField('Save Changes')
|
||||
description = StringField("Description", validators=[DataRequired()])
|
||||
format = SelectField(
|
||||
"Format",
|
||||
choices=[("telegram", "Telegram"), ("matrix", "Matrix")],
|
||||
validators=[DataRequired()],
|
||||
)
|
||||
url = StringField("URL", validators=[DataRequired()])
|
||||
submit = SubmitField("Save Changes")
|
||||
|
||||
|
||||
@bp.route("/new", methods=['GET', 'POST'])
|
||||
@bp.route("/new", methods=["GET", "POST"])
|
||||
def webhook_new() -> ResponseReturnValue:
|
||||
form = NewWebhookForm()
|
||||
if form.validate_on_submit():
|
||||
webhook = Webhook(
|
||||
description=form.description.data,
|
||||
format=form.format.data,
|
||||
url=form.url.data
|
||||
url=form.url.data,
|
||||
)
|
||||
try:
|
||||
db.session.add(webhook)
|
||||
db.session.commit()
|
||||
flash(f"Created new webhook {webhook.url}.", "success")
|
||||
return redirect(url_for("portal.webhook.webhook_edit", webhook_id=webhook.id))
|
||||
return redirect(
|
||||
url_for("portal.webhook.webhook_edit", webhook_id=webhook.id)
|
||||
)
|
||||
except exc.SQLAlchemyError:
|
||||
flash("Failed to create new webhook.", "danger")
|
||||
return redirect(url_for("portal.webhook.webhook_list"))
|
||||
return render_template("new.html.j2", section="webhook", form=form)
|
||||
|
||||
|
||||
@bp.route('/edit/<webhook_id>', methods=['GET', 'POST'])
|
||||
@bp.route("/edit/<webhook_id>", methods=["GET", "POST"])
|
||||
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",
|
||||
section="webhook",
|
||||
header="404 Webhook Not Found",
|
||||
message="The requested webhook could not be found."),
|
||||
status=404)
|
||||
form = NewWebhookForm(description=webhook.description,
|
||||
format=webhook.format,
|
||||
url=webhook.url)
|
||||
return Response(
|
||||
render_template(
|
||||
"error.html.j2",
|
||||
section="webhook",
|
||||
header="404 Webhook Not Found",
|
||||
message="The requested webhook could not be found.",
|
||||
),
|
||||
status=404,
|
||||
)
|
||||
form = NewWebhookForm(
|
||||
description=webhook.description, format=webhook.format, url=webhook.url
|
||||
)
|
||||
if form.validate_on_submit():
|
||||
webhook.description = form.description.data
|
||||
webhook.format = form.description.data
|
||||
|
@ -77,26 +83,29 @@ def webhook_edit(webhook_id: int) -> ResponseReturnValue:
|
|||
flash("Saved changes to webhook.", "success")
|
||||
except exc.SQLAlchemyError:
|
||||
flash("An error occurred saving the changes to the webhook.", "danger")
|
||||
return render_template("edit.html.j2",
|
||||
section="webhook",
|
||||
title="Edit Webhook",
|
||||
item=webhook, form=form)
|
||||
return render_template(
|
||||
"edit.html.j2", section="webhook", title="Edit Webhook", item=webhook, form=form
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/list")
|
||||
def webhook_list() -> ResponseReturnValue:
|
||||
webhooks = Webhook.query.all()
|
||||
return render_template("list.html.j2",
|
||||
section="webhook",
|
||||
title="Webhooks",
|
||||
item="webhook",
|
||||
new_link=url_for("portal.webhook.webhook_new"),
|
||||
items=webhooks)
|
||||
return render_template(
|
||||
"list.html.j2",
|
||||
section="webhook",
|
||||
title="Webhooks",
|
||||
item="webhook",
|
||||
new_link=url_for("portal.webhook.webhook_new"),
|
||||
items=webhooks,
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/destroy/<webhook_id>", methods=['GET', 'POST'])
|
||||
@bp.route("/destroy/<webhook_id>", methods=["GET", "POST"])
|
||||
def webhook_destroy(webhook_id: int) -> ResponseReturnValue:
|
||||
webhook: Optional[Webhook] = Webhook.query.filter(Webhook.id == webhook_id, Webhook.destroyed.is_(None)).first()
|
||||
webhook: Optional[Webhook] = Webhook.query.filter(
|
||||
Webhook.id == webhook_id, Webhook.destroyed.is_(None)
|
||||
).first()
|
||||
if webhook is None:
|
||||
return response_404("The requested webhook could not be found.")
|
||||
return view_lifecycle(
|
||||
|
@ -106,5 +115,5 @@ def webhook_destroy(webhook_id: int) -> ResponseReturnValue:
|
|||
success_view="portal.webhook.webhook_list",
|
||||
section="webhook",
|
||||
resource=webhook,
|
||||
action="destroy"
|
||||
action="destroy",
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue