From a1aa252bc0b1233f4453ddb9c5f3d4341a7ca413 Mon Sep 17 00:00:00 2001 From: Iain Learmonth Date: Wed, 4 May 2022 13:01:46 +0100 Subject: [PATCH] portal: consolidate list templates --- app/portal/__init__.py | 41 ++++++++++++++++++++---- app/portal/templates/bridgeconfs.html.j2 | 8 ----- app/portal/templates/bridges.html.j2 | 7 ---- app/portal/templates/groups.html.j2 | 30 ----------------- app/portal/templates/list.html.j2 | 25 +++++++++++++++ app/portal/templates/mirrorlists.html.j2 | 8 ----- app/portal/templates/origins.html.j2 | 8 ----- app/portal/templates/proxies.html.j2 | 7 ---- app/portal/templates/tables.html.j2 | 31 ++++++++++++++++++ 9 files changed, 90 insertions(+), 75 deletions(-) delete mode 100644 app/portal/templates/bridgeconfs.html.j2 delete mode 100644 app/portal/templates/bridges.html.j2 delete mode 100644 app/portal/templates/groups.html.j2 create mode 100644 app/portal/templates/list.html.j2 delete mode 100644 app/portal/templates/mirrorlists.html.j2 delete mode 100644 app/portal/templates/origins.html.j2 delete mode 100644 app/portal/templates/proxies.html.j2 diff --git a/app/portal/__init__.py b/app/portal/__init__.py index 8d90fcb..ed29fe9 100644 --- a/app/portal/__init__.py +++ b/app/portal/__init__.py @@ -46,7 +46,12 @@ def portal_home(): @portal.route("/groups") def view_groups(): groups = Group.query.order_by(Group.group_name).all() - return render_template("groups.html.j2", section="group", groups=groups) + return render_template("list.html.j2", + section="group", + title="Groups", + item="group", + items=groups, + new_link=url_for("portal.new_group")) @portal.route("/group/new", methods=['GET', 'POST']) @@ -154,13 +159,21 @@ def edit_origin(origin_id): @portal.route("/origins") def view_origins(): origins = Origin.query.order_by(Origin.domain_name).all() - return render_template("origins.html.j2", section="origin", origins=origins) - + return render_template("list.html.j2", + section="origin", + title="Origins", + item="origin", + 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("proxies.html.j2", section="proxy", proxies=proxies) + return render_template("list.html.j2", + section="proxy", + title="Proxies", + item="proxy", + items=proxies) @portal.route("/proxy/block/", methods=['GET', 'POST']) @@ -202,7 +215,12 @@ def view_alarms(): @portal.route('/lists') def view_mirror_lists(): mirrorlists = MirrorList.query.filter(MirrorList.destroyed == None).all() - return render_template("mirrorlists.html.j2", section="list", mirrorlists=mirrorlists) + return render_template("list.html.j2", + section="list", + title="Mirror Lists", + item="mirror list", + new_link=url_for("portal.new_mirror_list"), + items=mirrorlists) @portal.route("/list/destroy/") @@ -254,7 +272,12 @@ def new_mirror_list(group_id=None): @portal.route("/bridgeconfs") def view_bridgeconfs(): bridgeconfs = BridgeConf.query.filter(BridgeConf.destroyed == None).all() - return render_template("bridgeconfs.html.j2", section="bridgeconf", bridgeconfs=bridgeconfs) + return render_template("list.html.j2", + section="bridgeconf", + title="Tor Bridge Configurations", + item="bridge configuration", + items=bridgeconfs, + new_link=url_for("portal.new_bridgeconf")) @portal.route("/bridgeconf/new", methods=['GET', 'POST']) @@ -301,7 +324,11 @@ def new_bridgeconf(group_id=None): @portal.route("/bridges") def view_bridges(): bridges = Bridge.query.filter(Bridge.destroyed == None).all() - return render_template("bridges.html.j2", section="bridge", bridges=bridges) + return render_template("list.html.j2", + section="bridge", + title="Tor Bridges", + item="bridge", + items=bridges) @portal.route('/bridgeconf/edit/', methods=['GET', 'POST']) diff --git a/app/portal/templates/bridgeconfs.html.j2 b/app/portal/templates/bridgeconfs.html.j2 deleted file mode 100644 index 868d9f7..0000000 --- a/app/portal/templates/bridgeconfs.html.j2 +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "base.html.j2" %} -{% from "tables.html.j2" import bridgeconfs_table %} - -{% block content %} -

Tor Bridge Configurations

- Create new configuration - {{ bridgeconfs_table(bridgeconfs) }} -{% endblock %} diff --git a/app/portal/templates/bridges.html.j2 b/app/portal/templates/bridges.html.j2 deleted file mode 100644 index 3d38537..0000000 --- a/app/portal/templates/bridges.html.j2 +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "base.html.j2" %} -{% from "tables.html.j2" import bridges_table %} - -{% block content %} -

Tor Bridges

- {{ bridges_table(bridges) }} -{% endblock %} diff --git a/app/portal/templates/groups.html.j2 b/app/portal/templates/groups.html.j2 deleted file mode 100644 index ef92d58..0000000 --- a/app/portal/templates/groups.html.j2 +++ /dev/null @@ -1,30 +0,0 @@ -{% extends "base.html.j2" %} - -{% block content %} -

Groups

- Create new group -
- - - - - - - - - - - - {% for group in groups %} - - - - - - - - {% endfor %} - -
NameDescriptionEOTKSitesActions
{{ group.group_name }}{{ group.description }}{% if group.eotk %}✅{% else %}❌{% endif %}{{ group.origins | length }}View/Edit
-
-{% endblock %} \ No newline at end of file diff --git a/app/portal/templates/list.html.j2 b/app/portal/templates/list.html.j2 new file mode 100644 index 0000000..8810ba4 --- /dev/null +++ b/app/portal/templates/list.html.j2 @@ -0,0 +1,25 @@ +{% extends "base.html.j2" %} +{% from "tables.html.j2" import bridgeconfs_table, bridges_table, + groups_table, mirrorlists_table, origins_table, proxies_table %} + +{% block content %} +

{{ title }}

+ {% if new_link %} + Create new {{ item }} + {% endif %} + {% if item == "bridge configuration" %} + {{ bridgeconfs_table(items) }} + {% elif item == "bridge" %} + {{ bridges_table(items) }} + {% elif item == "eotk" %} + {{ eotk_table(items) }} + {% elif item == "group" %} + {{ groups_table(items) }} + {% elif item == "mirror list" %} + {{ mirrorlists_table(items) }} + {% elif item == "origin" %} + {{ origins_table(items) }} + {% elif item == "proxy" %} + {{ proxies_table(items) }} + {% endif %} +{% endblock %} diff --git a/app/portal/templates/mirrorlists.html.j2 b/app/portal/templates/mirrorlists.html.j2 deleted file mode 100644 index a584091..0000000 --- a/app/portal/templates/mirrorlists.html.j2 +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "base.html.j2" %} -{% from "tables.html.j2" import mirrorlists_table %} - -{% block content %} -

Mirror Lists

- Create new mirror list - {{ mirrorlists_table(mirrorlists) }} -{% endblock %} diff --git a/app/portal/templates/origins.html.j2 b/app/portal/templates/origins.html.j2 deleted file mode 100644 index ba0f1b6..0000000 --- a/app/portal/templates/origins.html.j2 +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "base.html.j2" %} -{% from "tables.html.j2" import origins_table %} - -{% block content %} -

Origins

- Create new origin - {{ origins_table(origins) }} -{% endblock %} diff --git a/app/portal/templates/proxies.html.j2 b/app/portal/templates/proxies.html.j2 deleted file mode 100644 index c3441af..0000000 --- a/app/portal/templates/proxies.html.j2 +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "base.html.j2" %} -{% from "tables.html.j2" import proxies_table %} - -{% block content %} -

Proxies

- {{ proxies_table(proxies) }} -{% endblock %} diff --git a/app/portal/templates/tables.html.j2 b/app/portal/templates/tables.html.j2 index 70e10c1..1d94822 100644 --- a/app/portal/templates/tables.html.j2 +++ b/app/portal/templates/tables.html.j2 @@ -22,6 +22,37 @@ {% endmacro %} +{% macro eotk_table(eotks) %} +
Not implemented yet.
+{% endmacro %} + +{% macro groups_table(groups) %} +
+ + + + + + + + + + + + {% for group in groups %} + + + + + + + + {% endfor %} + +
NameDescriptionEOTKSitesActions
{{ group.group_name }}{{ group.description }}{% if group.eotk %}✅{% else %}❌{% endif %}{{ group.origins | length }}View/Edit
+
+{% endmacro %} + {% macro origins_table(origins) %}