portal: refactor proxy views into module

This commit is contained in:
Iain Learmonth 2022-05-04 13:31:14 +01:00
parent ef1f3208fc
commit 33e6d58455
5 changed files with 48 additions and 36 deletions

View file

@ -11,11 +11,13 @@ from app import Origin, Proxy
from app.models.base import Group, MirrorList
from app.portal.forms import NewOriginForm, EditOriginForm, LifecycleForm, \
NewBridgeConfForm, EditBridgeConfForm, NewMirrorListForm
from app.portal.group import group, NewGroupForm, EditGroupForm
from app.portal.group import bp as group
from app.portal.proxy import bp as proxy
portal = Blueprint("portal", __name__, template_folder="templates", static_folder="static")
portal.register_blueprint(group, url_prefix="/group")
portal.register_blueprint(proxy, url_prefix="/proxy")
@portal.app_template_filter("mirror_expiry")
@ -111,35 +113,6 @@ def view_origins():
new_link=url_for("portal.new_origin"),
items=origins)
@portal.route("/proxies")
def view_proxies():
proxies = Proxy.query.filter(Proxy.destroyed == None).order_by(desc(Proxy.updated)).all()
return render_template("list.html.j2",
section="proxy",
title="Proxies",
item="proxy",
items=proxies)
@portal.route("/proxy/block/<proxy_id>", methods=['GET', 'POST'])
def blocked_proxy(proxy_id):
proxy = Proxy.query.filter(Proxy.id == proxy_id, Proxy.destroyed == None).first()
if proxy is None:
return Response(render_template("error.html.j2",
header="404 Proxy Not Found",
message="The requested proxy could not be found."))
form = LifecycleForm()
if form.validate_on_submit():
proxy.deprecate(reason="manual")
db.session.commit()
flash("Proxy will be shortly replaced.", "success")
return redirect(url_for("portal.edit_origin", origin_id=proxy.origin.id))
return render_template("lifecycle.html.j2",
header=f"Mark proxy for {proxy.origin.domain_name} as blocked?",
message=proxy.url,
section="proxy",
form=form)
@portal.route("/search")
def search():