From 2ca0045683f74254fd0e248c2567fa2efa358c08 Mon Sep 17 00:00:00 2001 From: Christian Heller <c.heller@plomlompom.de> Date: Sat, 18 May 2024 03:34:44 +0200 Subject: [PATCH] Refactor templates. --- templates/{base.html => _base.html} | 0 templates/calendar.html | 4 +- templates/condition.html | 8 ++-- templates/conditions.html | 2 +- templates/day.html | 21 +++------ templates/msg.html | 4 +- templates/process.html | 70 ++++------------------------- templates/processes.html | 2 +- templates/todo.html | 68 ++++------------------------ 9 files changed, 35 insertions(+), 144 deletions(-) rename templates/{base.html => _base.html} (100%) diff --git a/templates/base.html b/templates/_base.html similarity index 100% rename from templates/base.html rename to templates/_base.html diff --git a/templates/calendar.html b/templates/calendar.html index eae103d..f6208bb 100644 --- a/templates/calendar.html +++ b/templates/calendar.html @@ -1,4 +1,6 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} + + {% block css %} tr.week_row td { diff --git a/templates/condition.html b/templates/condition.html index 00aeedb..8e73e5e 100644 --- a/templates/condition.html +++ b/templates/condition.html @@ -1,4 +1,5 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} +{% import '_macros.html' as macros %} @@ -23,9 +24,6 @@ <tr/> </table> -<input class="btn-harmless" type="submit" name="update" value="update" /> -<div class="btn-to-right"> -<input class="btn-dangerous" type="submit" name="delete" value="delete" /> -</div> +{{ macros.edit_buttons() }} {% endblock %} diff --git a/templates/conditions.html b/templates/conditions.html index a717bf0..e2c4ec1 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} {% block content %} <a href="condition">add</a> diff --git a/templates/day.html b/templates/day.html index a0823f3..da5e17a 100644 --- a/templates/day.html +++ b/templates/day.html @@ -1,4 +1,5 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} +{% import '_macros.html' as macros %} @@ -106,11 +107,6 @@ td.todo_line { comment: <input name="day_comment" value="{{day.comment|e}}" /> <input type="submit" value="OK" /><br /> add todo: <input name="new_todo" list="processes" autocomplete="off" /> -<datalist id="processes"> -{% for process in processes %} -<option value="{{process.id_}}">{{process.title.newest|e}}</option> -{% endfor %} -</datalist> <h4>todo</h4> @@ -148,13 +144,9 @@ add todo: <input name="new_todo" list="processes" autocomplete="off" /> <td class="cond_line_{{(conditions_present|length - loop.index) % 3}}"> {% endif %} {% endfor %} - -<td><input name="new_todo" list="todos_for_{{condition.id_}}" autocomplete="off" /></td> -<datalist name="new_todo" id="todos_for_{{condition.id_}}" /> -{% for process in enablers_for[condition.id_] %} -<option value="{{process.id_}}">{{process.title.newest|e}}</option> -{% endfor %} -</datalist /> +{% set list_name = "todos_for_%s"|format(condition.id_) %} +<td><input name="new_todo" list="{{list_name}}" autocomplete="off" /></td> +{{ macros.datalist_of_direct_titles(list_name, enablers_for[condition.id_]) }} </td> </tr> {% endfor %} @@ -184,5 +176,6 @@ add todo: <input name="new_todo" list="processes" autocomplete="off" /> </table> </form> -{% endblock %} +{{ macros.datalist_of_direct_titles("processes", processes) }} +{% endblock %} diff --git a/templates/msg.html b/templates/msg.html index 90cd61c..3672f21 100644 --- a/templates/msg.html +++ b/templates/msg.html @@ -1,4 +1,6 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} + + {% block content %} <p>{{msg}}</p> diff --git a/templates/process.html b/templates/process.html index 10442cf..41f8117 100644 --- a/templates/process.html +++ b/templates/process.html @@ -1,4 +1,5 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} +{% import '_macros.html' as macros %} @@ -56,59 +57,17 @@ add: <input name="new_step_to_{{step_id}}" list="candidates" autocomplete="off" <tr> <th>conditions</th> -<td> -<table> -{% for condition in process.conditions %} -<tr> -<td> -<input type="checkbox" name="condition" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="condition" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("condition", process.conditions, "condition", "condition_candidates") }}</td> </tr> <tr> <th>enables</th> -<td> -<table> -{% for condition in process.enables %} -<tr> -<td> -<input type="checkbox" name="enables" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="enables" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("enables", process.enables, "condition", "condition_candidates") }}</td> </tr> <tr> <th>disables</th> -<td> -<table> -{% for condition in process.disables %} -<tr> -<td> -<input type="checkbox" name="disables" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="disables" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("disables", process.disables, "condition", "condition_candidates") }}</td> </tr> <tr> @@ -133,20 +92,9 @@ add: <input name="new_top_step" list="step_candidates" autocomplete="off" /> <tr> </table> -<datalist id="condition_candidates"> -{% for condition_candidate in condition_candidates %} -<option value="{{condition_candidate.id_}}">{{condition_candidate.title.newest|e}}</option> -{% endfor %} -</datalist> -<datalist id="step_candidates"> -{% for candidate in step_candidates %} -<option value="{{candidate.id_}}">{{candidate.title.newest|e}}</option> -{% endfor %} -</datalist> - -<input class="btn-harmless" type="submit" name="update" value="update" /> -<div class="btn-to-right"> -<input class="btn-dangerous" type="submit" name="delete" value="delete" /> -</div> +{{ macros.edit_buttons() }} </form> + +{{ macros.datalist_of_direct_titles("condition_candidates", condition_candidates) }} +{{ macros.datalist_of_direct_titles("step_candidates", step_candidates) }} {% endblock %} diff --git a/templates/processes.html b/templates/processes.html index 6dc3e85..6c3c64b 100644 --- a/templates/processes.html +++ b/templates/processes.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} {% block content %} <a href="process">add</a> diff --git a/templates/todo.html b/templates/todo.html index 44cdfa7..d3957af 100644 --- a/templates/todo.html +++ b/templates/todo.html @@ -1,4 +1,5 @@ -{% extends 'base.html' %} +{% extends '_base.html' %} +{% import '_macros.html' as macros %} @@ -29,59 +30,17 @@ <tr> <th>conditions</th> -<td> -<table> -{% for condition in todo.conditions %} -<tr> -<td> -<input type="checkbox" name="condition" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="condition" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("condition", todo.conditions, "condition", "condition_candidates") }}</td> </tr> <tr> <th>enables</th> -<td> -<table> -{% for condition in todo.enables %} -<tr> -<td> -<input type="checkbox" name="enables" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="enables" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("enables", todo.enables, "condition", "condition_candidates") }}</td> </tr> <tr> <th>disables</th> -<td> -<table> -{% for condition in todo.disables%} -<tr> -<td> -<input type="checkbox" name="disables" value="{{condition.id_}}" checked /> -</td> -<td> -<a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a> -</td> -</tr> -{% endfor %} -</table> -add: <input name="disables" list="condition_candidates" autocomplete="off" /> -</td> +<td>{{ macros.simple_checkbox_table("disables", todo.disables, "condition", "condition_candidates") }}</td> </tr> <tr> @@ -109,20 +68,9 @@ adopt: <input name="adopt" list="todo_candidates" autocomplete="off" /> </tr> </table> -<input class="btn-harmless" type="submit" name="update" value="update" /> -<div class="btn-to-right"> -<input class="btn-dangerous" type="submit" name="delete" value="delete" /> -</div> +{{ macros.edit_buttons() }} </form> -<datalist id="condition_candidates"> -{% for condition_candidate in condition_candidates %} -<option value="{{condition_candidate.id_}}">{{condition_candidate.title.newest|e}}</option> -{% endfor %} -</datalist> -<datalist id="todo_candidates"> -{% for candidate in todo_candidates %} -<option value="{{candidate.id_}}">{{candidate.process.title.newest|e}} ({{candidate.id_}})</option> -{% endfor %} -</datalist> +{{ macros.datalist_of_direct_titles("condition_candidates", condition_candidates) }} +{{ macros.datalist_of_indirect_titles("todo_candidates", todo_candidates) }} {% endblock %} -- 2.30.2