Fixed bugs when generating URLs

This commit is contained in:
2026-04-16 09:14:35 -05:00
parent 4e1fb5e5ec
commit 653740cc3a
4 changed files with 38 additions and 10 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
__pycache__/
helpers/
config.json
priv/

21
app.py
View File

@@ -23,6 +23,7 @@ from colorsys import rgb_to_hsv
from flask import Flask, render_template, request, redirect, url_for, session, abort
from flask_pymongo import PyMongo
from werkzeug.exceptions import HTTPException
from werkzeug.routing.exceptions import BuildError
from bson import ObjectId
import bson.json_util as bson
import requests
@@ -126,16 +127,25 @@ def render_main():
else None
)
results = {"ade": {}, "bea": {}, "cam": {}, "des": {}}
short_results = {"ade": {}, "bea": {}, "cam": {}, "des": {}}
for ddata in dsdata:
if not can_access(ddata, udata):
continue
if ddata["cat"] not in results[ddata["quad"]]:
results[ddata["quad"]][ddata["cat"]] = {}
results[ddata["quad"]][ddata["cat"]][ddata["name"]] = ddata["id"]
if not can_access(ddata, udata):
results[ddata["quad"]][ddata["cat"]][ddata["name"]] = None
continue
try:
url = url_for(ddata["id"])
results[ddata["quad"]][ddata["cat"]][ddata["name"]] = url
short_results[ddata["quad"]][ddata["name"]] = url
except BuildError:
results[ddata["quad"]][ddata["cat"]][ddata["name"]] = None
return render_template(
"index.html",
fpdata=fpdata,
domains=results,
sdomains=short_results,
quad=(request.endpoint or "ade")[-3:],
)
@@ -472,3 +482,8 @@ def lighting():
@app.errorhandler(HTTPException)
def handle_error(error):
return render_template("error.html", error=error), error.code
@app.route("/swt/basic")
def swt_basic():
return render_template("priv/swtbasic.html")

View File

@@ -25,6 +25,11 @@ nav#sidebar {
text-decoration: none;
}
a.failed {
color: #777777;
cursor: not-allowed;
}
ul {
margin: 0;
}
@@ -121,6 +126,11 @@ hr#sectorbar {
color: var(--color);
text-decoration: none;
}
a.failed {
color: #777777;
cursor: not-allowed;
}
}
#other>div {

View File

@@ -9,14 +9,12 @@
<nav id="sidebar">
{% set quads = {"ade":"♢", "bea":"♡", "cam":"♧", "des":"♤"} %}
{% for quad in quads %}
{% if domains[quad] %}
{% if sdomains[quad] %}
<div style="--hue: var(--{{ quad }});">
<h2>{{ quads[quad] }}</h2>
<ul>
{% for category in domains[quad] %}
{% for domain in domains[quad][category] %}
<li><a href="{{ url_for(domains[quad][category][domain]) }}">{{ domain }}</a></li>
{% endfor %}
{% for domain in sdomains[quad] %}
<li><a href="{{ sdomains[quad][domain] }}">{{ domain }}</a></li>
{% endfor %}
</ul>
</div>
@@ -38,7 +36,11 @@
<h2>{{ category }}</h2>
<ul>
{% for domain in domains[quad][category] %}
<li><a href="{{ url_for(domains[quad][category][domain]) }}">{{ domain }}</a></li>
{% if domains[quad][category][domain] %}
<li><a href="{{ domains[quad][category][domain] }}">{{ domain }}</a></li>
{% else %}
<li><a class="failed">{{ domain }}</a></li>
{% endif %}
{% endfor %}
</ul>
</div>