Bugfix: /admin/printers, handle 404 from files_info
This commit is contained in:
parent
3f41b63582
commit
c749adfaf6
7 changed files with 24 additions and 38 deletions
|
@ -6,6 +6,7 @@ py_project(
|
||||||
main_deps = [
|
main_deps = [
|
||||||
"//projects/anosql",
|
"//projects/anosql",
|
||||||
"//projects/anosql-migrations",
|
"//projects/anosql-migrations",
|
||||||
|
py_requirement("aiosql"),
|
||||||
py_requirement("attrs"),
|
py_requirement("attrs"),
|
||||||
py_requirement("click"),
|
py_requirement("click"),
|
||||||
py_requirement("flask"),
|
py_requirement("flask"),
|
||||||
|
|
|
@ -23,11 +23,6 @@ from tentacles.workers import *
|
||||||
from tentacles.workers import assign_jobs, Worker
|
from tentacles.workers import assign_jobs, Worker
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
|
||||||
def cli():
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def db_factory(app):
|
def db_factory(app):
|
||||||
store = Db(app.config.get("db", {}).get("uri"))
|
store = Db(app.config.get("db", {}).get("uri"))
|
||||||
store.connect()
|
store.connect()
|
||||||
|
@ -99,7 +94,7 @@ def make_app():
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@click.command()
|
||||||
@click.option("--hostname", "hostname", type=str, default="0.0.0.0")
|
@click.option("--hostname", "hostname", type=str, default="0.0.0.0")
|
||||||
@click.option("--port", "port", type=int, default=8080)
|
@click.option("--port", "port", type=int, default=8080)
|
||||||
@click.option("--trace/--no-trace", "trace", default=False)
|
@click.option("--trace/--no-trace", "trace", default=False)
|
||||||
|
@ -154,4 +149,4 @@ def serve(hostname: str, port: int, config: Path, trace: bool):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
serve()
|
||||||
|
|
|
@ -74,13 +74,7 @@ def get_users():
|
||||||
return redirect("/admin")
|
return redirect("/admin")
|
||||||
|
|
||||||
|
|
||||||
@BLUEPRINT.route("/admin/printers")
|
@BLUEPRINT.route("/admin/printers", methods=["GET"])
|
||||||
@requires_admin
|
|
||||||
def printers():
|
|
||||||
return render_template("printers.html.j2")
|
|
||||||
|
|
||||||
|
|
||||||
@BLUEPRINT.route("/admin/printers/add", methods=["GET"])
|
|
||||||
@requires_admin
|
@requires_admin
|
||||||
def add_printer():
|
def add_printer():
|
||||||
return render_template("add_printer.html.j2")
|
return render_template("add_printer.html.j2")
|
||||||
|
|
|
@ -71,11 +71,14 @@ def post_register():
|
||||||
try:
|
try:
|
||||||
username = request.form["username"]
|
username = request.form["username"]
|
||||||
email = request.form["email"]
|
email = request.form["email"]
|
||||||
|
has_config = False
|
||||||
group_id = 1 # Normal users
|
group_id = 1 # Normal users
|
||||||
status_id = -3 # Unverified
|
status_id = -3 # Unverified
|
||||||
|
|
||||||
for user_config in current_app.config.get("users", []):
|
for user_config in current_app.config.get("users", []):
|
||||||
if user_config["email"] == email:
|
if user_config["email"] == email:
|
||||||
|
has_config = True
|
||||||
|
|
||||||
if "group_id" in user_config:
|
if "group_id" in user_config:
|
||||||
group_id = user_config["group_id"]
|
group_id = user_config["group_id"]
|
||||||
|
|
||||||
|
@ -109,6 +112,11 @@ def post_register():
|
||||||
)
|
)
|
||||||
|
|
||||||
elif user.status_id == 1:
|
elif user.status_id == 1:
|
||||||
|
# Do the entire approval dance just to be absolutely sure any statically configured users work
|
||||||
|
ctx.db.try_verify_user(token=user.verification_token)
|
||||||
|
ctx.db.approve_user(uid=user.id)
|
||||||
|
ctx.db.enable_user(uid=user.id)
|
||||||
|
|
||||||
flash("Welcome, please log in", category="success")
|
flash("Welcome, please log in", category="success")
|
||||||
|
|
||||||
return render_template("register.html.j2")
|
return render_template("register.html.j2")
|
||||||
|
|
|
@ -21,30 +21,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<input type="hidden" name="tested" value="false" />
|
<input id="tested" type="hidden" name="tested" value="false" />
|
||||||
<input id="test" type="button" value="Test" enabled="false" />
|
|
||||||
<input id="submit" type="submit" value="Add" onclick="maybeSubmit();" />
|
<input id="submit" type="submit" value="Add" onclick="maybeSubmit();" />
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
document.getElementById("input").disabled = True;
|
|
||||||
|
|
||||||
function testSettings() {
|
|
||||||
var formData = new FormData(document.getElementById("form"))
|
|
||||||
var req = new XMLHttpRequest();
|
|
||||||
req.open("POST", "/printer/test");
|
|
||||||
req.send(formData);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
function maybeSubmit() {
|
|
||||||
if (document.getElementById("tested").value == "true") {
|
|
||||||
document.getElementById("form").submit();
|
|
||||||
} else {
|
|
||||||
console.error("Form values have not been tested!");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -21,10 +21,10 @@
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if ctx.is_admin %}
|
{% if ctx.is_admin %}
|
||||||
<a class="button" href="/printers/add">Add a printer</a>
|
<a class="button" href="/admin/printers">Add a printer</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
No printers available. {% if ctx.is_admin %}<a href="/printers/add">Configure one!</a>{% else %}Ask the admin to configure one!{% endif %}
|
No printers available. {% if ctx.is_admin %}<a href="/admin/printers">Configure one!</a>{% else %}Ask the admin to configure one!{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -38,6 +38,15 @@ class OctoRest(_OR):
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def files_info(self, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
return super().files_info(*args, **kwargs)
|
||||||
|
except HTTPError as e:
|
||||||
|
if e.response.status_code == 404:
|
||||||
|
return {}
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue