Skip to content

Commit c436e54

Browse files
Merge pull request #43 from Promptly-Technologies-LLC/8-try-using-fastapis-session-middleware-to-preserve-any-user-entered-form-data-when-redirecting-back-to-a-page-with-an-error-toast
Styled table in documentation for better borders and column widths
2 parents ae0f9f6 + 78dd03b commit c436e54

File tree

1 file changed

+69
-7
lines changed

1 file changed

+69
-7
lines changed

docs/architecture.qmd

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,74 @@ The best solution, I think, is to use really robust client-side form validation
9595

9696
Here are some patterns we've considered for server-side error handling:
9797

98-
| ID | Approach | Returns to same page | Preserves form inputs | Follows PRG pattern | Complexity |
99-
|-----|----------|-------------------|-------------------|------------------|------------|
100-
| 1 | Validate with Pydantic dependency, catch and redirect from middleware (with exception message as context) to an error page with "go back" button | No | Yes | Yes | Low |
101-
| 2 | Validate in FastAPI endpoint function body, redirect to origin page with error message query param | Yes | No | Yes | Medium |
102-
| 3 | Validate in FastAPI endpoint function body, redirect to origin page with error message query param and form inputs as context | Yes | Yes | Yes | High |
103-
| 4 | Validate with Pydantic dependency, use session context to get form inputs from request, redirect to origin page from middleware with exception message and form inputs as context so we can re-render page with original form inputs | Yes | Yes | Yes | High |
104-
| 5 | Validate in either Pydantic dependency or function endpoint body and directly return error message in JSON, then mount it with HTMX or some simple layout-level Javascript | Yes | Yes | No | Low |
98+
<style>
99+
.styled-table, .styled-table th, .styled-table td {
100+
border: 1px solid black;
101+
padding: 8px;
102+
border-collapse: collapse;
103+
}
104+
105+
.styled-table th:nth-child(1) { width: 5%; }
106+
.styled-table th:nth-child(2) { width: 50%; }
107+
.styled-table th:nth-child(3),
108+
.styled-table th:nth-child(4),
109+
.styled-table th:nth-child(5) { width: 15%; }
110+
.styled-table th:nth-child(6) { width: 10%; }
111+
</style>
112+
113+
<table class="styled-table">
114+
<thead>
115+
<tr>
116+
<th>ID</th>
117+
<th>Approach</th>
118+
<th>Returns to same page</th>
119+
<th>Preserves form inputs</th>
120+
<th>Follows PRG pattern</th>
121+
<th>Complexity</th>
122+
</tr>
123+
</thead>
124+
<tbody>
125+
<tr>
126+
<td>1</td>
127+
<td>Validate with Pydantic dependency, catch and redirect from middleware (with exception message as context) to an error page with "go back" button</td>
128+
<td>No</td>
129+
<td>Yes</td>
130+
<td>Yes</td>
131+
<td>Low</td>
132+
</tr>
133+
<tr>
134+
<td>2</td>
135+
<td>Validate in FastAPI endpoint function body, redirect to origin page with error message query param</td>
136+
<td>Yes</td>
137+
<td>No</td>
138+
<td>Yes</td>
139+
<td>Medium</td>
140+
</tr>
141+
<tr>
142+
<td>3</td>
143+
<td>Validate in FastAPI endpoint function body, redirect to origin page with error message query param and form inputs as context so we can re-render page with original form inputs</td>
144+
<td>Yes</td>
145+
<td>Yes</td>
146+
<td>Yes</td>
147+
<td>High</td>
148+
</tr>
149+
<tr>
150+
<td>4</td>
151+
<td>Validate with Pydantic dependency, use session context to get form inputs from request, redirect to origin page from middleware with exception message and form inputs as context so we can re-render page with original form inputs</td>
152+
<td>Yes</td>
153+
<td>Yes</td>
154+
<td>Yes</td>
155+
<td>High</td>
156+
</tr>
157+
<tr>
158+
<td>5</td>
159+
<td>Validate in either Pydantic dependency or function endpoint body and directly return error message or error toast HTML partial in JSON, then mount error toast with HTMX or some simple layout-level Javascript</td>
160+
<td>Yes</td>
161+
<td>Yes</td>
162+
<td>No</td>
163+
<td>Low</td>
164+
</tr>
165+
</tbody>
166+
</table>
105167

106168
Presently this template primarily uses option 1 but also supports option 2. Ultimately, I think option 5 will be preferable; support for that [is planned](https://github.com/Promptly-Technologies-LLC/fastapi-jinja2-postgres-webapp/issues/5) for a future update or fork of this template.

0 commit comments

Comments
 (0)