Skip to content

Commit

Permalink
Merge branch 'master' into App_User_list_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
clr-li committed Oct 26, 2023
2 parents a6e833b + dace3e9 commit 24fd684
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
17 changes: 12 additions & 5 deletions recipes/BulkRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import io
import typing

from django.utils.timesince import timesince
from fastapi import HTTPException
from furl import furl
from pydantic import BaseModel, Field
Expand Down Expand Up @@ -162,6 +161,8 @@ def render_form_v2(self):

with visible_col1:
st.write("##### Inputs")
with hidden_col1:
st.write("##### Inputs")

input_columns_old = st.session_state.pop("input_columns", {})
input_columns_new = st.session_state.setdefault("input_columns", {})
Expand All @@ -184,6 +185,8 @@ def render_form_v2(self):

with visible_col2:
st.write("##### Outputs")
with hidden_col2:
st.write("##### Outputs")

# only show the first output field by default, and hide others
try:
Expand All @@ -198,11 +201,10 @@ def render_form_v2(self):
"run_url": "Run URL",
}
hidden_out_fields = {
k: v for k, v in output_fields.items() if k not in visible_out_fields
} | {
"price": "Price",
"run_time": "Run Time",
"error_msg": "Error Msg",
}
} | {k: v for k, v in output_fields.items() if k not in visible_out_fields}

output_columns_old = st.session_state.pop("output_columns", {})
output_columns_new = st.session_state.setdefault("output_columns", {})
Expand Down Expand Up @@ -274,9 +276,14 @@ def run_v2(
)
result.get(disable_sync_subtasks=False)
sr.refresh_from_db()

run_time = datetime.timedelta(
seconds=int(sr.run_time.total_seconds())
)
state = sr.to_dict()
state["run_time"] = timesince(datetime.datetime.now() - sr.run_time)
state["run_url"] = sr.get_app_url()
state["price"] = sr.price
state["run_time"] = str(run_time)
state["error_msg"] = sr.error_msg

for field, col in request.output_columns.items():
Expand Down
19 changes: 19 additions & 0 deletions routers/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ async def favicon():
return FileResponse("static/favicon.ico")


@app.post("/handleError/")
async def handle_error(request: Request):
context = {"request": request, "settings": settings}

def not_found():
st.html(templates.get_template("errors/404.html").render(**context))

def unknown_error():
st.html(templates.get_template("errors/unknown.html").render(**context))

body = await request.json()

match body["status"]:
case 404:
return st.runner(lambda: page_wrapper(request, not_found))
case _:
return st.runner(lambda: page_wrapper(request, unknown_error))


@app.get("/login/")
def login(request: Request):
if request.user and not request.user.is_anonymous:
Expand Down
11 changes: 0 additions & 11 deletions templates/404.html

This file was deleted.

8 changes: 8 additions & 0 deletions templates/errors/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% block content %}
<div style="text-align: center; margin: 2rem 0;">
<h1>
Oops, we can't find this page!
</h1>
<img src="https://media.tenor.com/IHdlTRsmcS4AAAAC/404.gif" height="404" alt="404">
</div>
{% endblock content %}
8 changes: 8 additions & 0 deletions templates/errors/unknown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% block content %}
<div style="text-align: center; margin: 2rem 0;">
<h1>
Uh oh... Something went wrong
</h1>
<img src="https://media.tenor.com/1Wlr9trTPLwAAAAd/robotically-robot.gif" height="404" alt="404">
</div>
{% endblock %}

0 comments on commit 24fd684

Please sign in to comment.