lint: reformat python code with black
This commit is contained in:
parent
331beb01b4
commit
a406a7974b
88 changed files with 2579 additions and 1608 deletions
|
@ -17,40 +17,52 @@ bp = Blueprint("automation", __name__)
|
|||
|
||||
_SECTION_TEMPLATE_VARS = {
|
||||
"section": "automation",
|
||||
"help_url": "https://bypass.censorship.guide/user/automation.html"
|
||||
"help_url": "https://bypass.censorship.guide/user/automation.html",
|
||||
}
|
||||
|
||||
|
||||
class EditAutomationForm(FlaskForm): # type: ignore
|
||||
enabled = BooleanField('Enabled')
|
||||
submit = SubmitField('Save Changes')
|
||||
enabled = BooleanField("Enabled")
|
||||
submit = SubmitField("Save Changes")
|
||||
|
||||
|
||||
@bp.route("/list")
|
||||
def automation_list() -> ResponseReturnValue:
|
||||
automations = list(filter(
|
||||
lambda a: a.short_name not in current_app.config.get('HIDDEN_AUTOMATIONS', []),
|
||||
Automation.query.filter(
|
||||
Automation.destroyed.is_(None)).order_by(Automation.description).all()
|
||||
))
|
||||
automations = list(
|
||||
filter(
|
||||
lambda a: a.short_name
|
||||
not in current_app.config.get("HIDDEN_AUTOMATIONS", []),
|
||||
Automation.query.filter(Automation.destroyed.is_(None))
|
||||
.order_by(Automation.description)
|
||||
.all(),
|
||||
)
|
||||
)
|
||||
states = {tfs.key: tfs for tfs in TerraformState.query.all()}
|
||||
return render_template("list.html.j2",
|
||||
title="Automation Jobs",
|
||||
item="automation",
|
||||
items=automations,
|
||||
states=states,
|
||||
**_SECTION_TEMPLATE_VARS)
|
||||
return render_template(
|
||||
"list.html.j2",
|
||||
title="Automation Jobs",
|
||||
item="automation",
|
||||
items=automations,
|
||||
states=states,
|
||||
**_SECTION_TEMPLATE_VARS
|
||||
)
|
||||
|
||||
|
||||
@bp.route('/edit/<automation_id>', methods=['GET', 'POST'])
|
||||
@bp.route("/edit/<automation_id>", methods=["GET", "POST"])
|
||||
def automation_edit(automation_id: int) -> ResponseReturnValue:
|
||||
automation: Optional[Automation] = Automation.query.filter(Automation.id == automation_id).first()
|
||||
automation: Optional[Automation] = Automation.query.filter(
|
||||
Automation.id == automation_id
|
||||
).first()
|
||||
if automation is None:
|
||||
return Response(render_template("error.html.j2",
|
||||
header="404 Automation Job Not Found",
|
||||
message="The requested automation job could not be found.",
|
||||
**_SECTION_TEMPLATE_VARS),
|
||||
status=404)
|
||||
return Response(
|
||||
render_template(
|
||||
"error.html.j2",
|
||||
header="404 Automation Job Not Found",
|
||||
message="The requested automation job could not be found.",
|
||||
**_SECTION_TEMPLATE_VARS
|
||||
),
|
||||
status=404,
|
||||
)
|
||||
form = EditAutomationForm(enabled=automation.enabled)
|
||||
if form.validate_on_submit():
|
||||
automation.enabled = form.enabled.data
|
||||
|
@ -59,21 +71,30 @@ def automation_edit(automation_id: int) -> ResponseReturnValue:
|
|||
db.session.commit()
|
||||
flash("Saved changes to bridge configuration.", "success")
|
||||
except exc.SQLAlchemyError:
|
||||
flash("An error occurred saving the changes to the bridge configuration.", "danger")
|
||||
logs = AutomationLogs.query.filter(AutomationLogs.automation_id == automation.id).order_by(
|
||||
desc(AutomationLogs.added)).limit(5).all()
|
||||
return render_template("automation.html.j2",
|
||||
automation=automation,
|
||||
logs=logs,
|
||||
form=form,
|
||||
**_SECTION_TEMPLATE_VARS)
|
||||
flash(
|
||||
"An error occurred saving the changes to the bridge configuration.",
|
||||
"danger",
|
||||
)
|
||||
logs = (
|
||||
AutomationLogs.query.filter(AutomationLogs.automation_id == automation.id)
|
||||
.order_by(desc(AutomationLogs.added))
|
||||
.limit(5)
|
||||
.all()
|
||||
)
|
||||
return render_template(
|
||||
"automation.html.j2",
|
||||
automation=automation,
|
||||
logs=logs,
|
||||
form=form,
|
||||
**_SECTION_TEMPLATE_VARS
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/kick/<automation_id>", methods=['GET', 'POST'])
|
||||
@bp.route("/kick/<automation_id>", methods=["GET", "POST"])
|
||||
def automation_kick(automation_id: int) -> ResponseReturnValue:
|
||||
automation = Automation.query.filter(
|
||||
Automation.id == automation_id,
|
||||
Automation.destroyed.is_(None)).first()
|
||||
Automation.id == automation_id, Automation.destroyed.is_(None)
|
||||
).first()
|
||||
if automation is None:
|
||||
return response_404("The requested bridge configuration could not be found.")
|
||||
return view_lifecycle(
|
||||
|
@ -83,5 +104,5 @@ def automation_kick(automation_id: int) -> ResponseReturnValue:
|
|||
success_view="portal.automation.automation_list",
|
||||
success_message="This automation job will next run within 1 minute.",
|
||||
resource=automation,
|
||||
action="kick"
|
||||
action="kick",
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue