From af61d45fa4aac2f96722380dfcdb2d9df864002d Mon Sep 17 00:00:00 2001 From: Eden Kirin Date: Wed, 15 May 2024 22:15:27 +0200 Subject: [PATCH] Basic table inline edit functionality --- .gitignore | 1 + db.sqlite3 => db.template.sqlite3 | Bin 131072 -> 135168 bytes project/main/apps.py | 15 +++++ project/main/migrations/0003_person.py | 60 ++++++++++++++++++ project/main/models/__init__.py | 1 + project/main/models/person.py | 10 +++ .../main/components/inline_table_row.html | 43 +++++++++++++ project/main/templates/main/filter_list.html | 1 - .../templates/main/table_inline_edit.html | 21 +++++- .../main/table_inline_table_row.html | 3 + project/main/views/__init__.py | 2 +- project/main/views/table_inline_edit.py | 39 ++++++++++++ project/urls.py | 1 + 13 files changed, 193 insertions(+), 4 deletions(-) rename db.sqlite3 => db.template.sqlite3 (95%) create mode 100644 project/main/migrations/0003_person.py create mode 100644 project/main/models/person.py create mode 100644 project/main/templates/main/components/inline_table_row.html create mode 100644 project/main/templates/main/table_inline_table_row.html diff --git a/.gitignore b/.gitignore index 06e58eb..f7dfdf6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.venv __pycache__ /project/settings_local.py +/db.sqlite3 diff --git a/db.sqlite3 b/db.template.sqlite3 similarity index 95% rename from db.sqlite3 rename to db.template.sqlite3 index 85062288b07995ad019c7eddcc31c321f952d671..eb2d5719e84b0c24e9aa7d1513869fef07a8e2ba 100644 GIT binary patch delta 876 zcmY+DPfXKb7{>dpUAj=VcZ@8vYh@k7Ai=SA107r(BE|%mL@*{80%fb%I5yJ#kqHT_ zi3bCT;!JiRlATOU^iX!-K;q4_gmCfTpNl3Y8ZVwa*{+*FlkfSG=lkW&`##^-Qpr}T z+MY3OT^NS>_0|0Pw=P7iU07e?iI%Ja?xKoi(iyN&MNOTc_&%2va|ec(L^;j#d}MA} zQnHzJm=E^{`GKG?zzNZz$l#C=?F&bR{)>^?YvvB&B4Nb>`|uckzz)2HkFcVt3*e$C zoIz%VEa9=>5mXT;P&*>aJD~`2l@CL`G>c&^dTS)CVelD#!2#4@6V_lyQ}2Qk2se$4 zX3Q#NdGqoL&f1U4WK6I*9QMEV@Ae~2ePJJKBTxX51zCE~=$UONP&XozQcB864UaLs z#62;+*z~+k0{IasCX)?_uKD8MkUrBY20!5we1Khe2^+AgsS-FHB!Ri<eS|70eQR@{`#e3^z7D=iMyt_mmN6csB$88~(fe z=lM7B&*ksl*jUcLxjVkHfLVgSbTaz|pi*1@&87GI8yNYfvnDXgPi$1*?w!CW$;HIV izOj*+b$ez$<7@+F37&-M> + {% if is_editing %} + + + + + + + + + + + + + + {% else %} + {{ person.name }} + {{ person.address }} + {{ person.city }} + + + + {% endif %} + +{% endmacro %} diff --git a/project/main/templates/main/filter_list.html b/project/main/templates/main/filter_list.html index bf0842d..a17ea7c 100644 --- a/project/main/templates/main/filter_list.html +++ b/project/main/templates/main/filter_list.html @@ -50,6 +50,5 @@ - {% include "main/filter_list_content.html" %} {% endblock %} diff --git a/project/main/templates/main/table_inline_edit.html b/project/main/templates/main/table_inline_edit.html index 5eccfae..93d4d24 100644 --- a/project/main/templates/main/table_inline_edit.html +++ b/project/main/templates/main/table_inline_edit.html @@ -1,7 +1,24 @@ {% extends "main/base/layout.html" %} -{% from "main/components/js_alert.html" import js_alert_work_in_progress %} +{% from "main/components/js_alert.html" import no_js_alert %} +{% from "main/components/inline_table_row.html" import inline_table_row %} {% block content %} - {{ js_alert_work_in_progress() }} + {{ no_js_alert() }} + + + + + + + + + + + + {% for person in persons %} + {{ inline_table_row(person, is_editing=False) }} + {% endfor %} + +
NameAddressCity 
{% endblock %} diff --git a/project/main/templates/main/table_inline_table_row.html b/project/main/templates/main/table_inline_table_row.html new file mode 100644 index 0000000..9264292 --- /dev/null +++ b/project/main/templates/main/table_inline_table_row.html @@ -0,0 +1,3 @@ +{% from "main/components/inline_table_row.html" import inline_table_row %} + +{{ inline_table_row(person, is_editing=is_editing) }} diff --git a/project/main/views/__init__.py b/project/main/views/__init__.py index a75755b..2deca66 100644 --- a/project/main/views/__init__.py +++ b/project/main/views/__init__.py @@ -8,4 +8,4 @@ from .filter_list import FilterListFilterView, FilterListView from .form_validation import FormValidationView from .home import HomeView from .swap import SwapView -from .table_inline_edit import TableInlineEditView +from .table_inline_edit import TableInlineEditView, TableInlineEditRowView diff --git a/project/main/views/table_inline_edit.py b/project/main/views/table_inline_edit.py index 3c4486d..2171d36 100644 --- a/project/main/views/table_inline_edit.py +++ b/project/main/views/table_inline_edit.py @@ -1,3 +1,8 @@ +from typing import Any + +from django.http import Http404 + +from project.main.models import Person from project.main.views.demo_view_base import DemoViewBase @@ -5,3 +10,37 @@ class TableInlineEditView(DemoViewBase): template_name = "main/table_inline_edit.html" active_section = "table-inline-edit" title = "Table Inline Edit" + + def get_context_data(self, **kwargs) -> dict[str, Any]: + context_data = super().get_context_data(**kwargs) + + persons = Person.objects.all() + + context_data.update( + { + "persons": persons, + } + ) + return context_data + + +class TableInlineEditRowView(DemoViewBase): + template_name = "main/table_inline_table_row.html" + + def get_context_data(self, **kwargs) -> dict[str, Any]: + context_data = super().get_context_data(**kwargs) + + try: + person = Person.objects.get(pk=kwargs.get("pk")) + except Person.DoesNotExist: + raise Http404("Person not found") + + action = self.request.GET.get("action") + + context_data.update( + { + "person": person, + "is_editing": action != "cancel", + } + ) + return context_data diff --git a/project/urls.py b/project/urls.py index 10f49bc..87448b1 100644 --- a/project/urls.py +++ b/project/urls.py @@ -13,4 +13,5 @@ urlpatterns = [ path("complex-form/handle/reports", views.ReportsHandleView.as_view(), name="complex-form-handle-reports"), path("complex-form/handle/warehouse-management", views.WarehouseManagementHandleView.as_view(), name="complex-form-handle-warehouse-management"), path("table-inline-edit", views.TableInlineEditView.as_view(), name="table-inline-edit"), + path("table-inline-edit/edit/", views.TableInlineEditRowView.as_view(), name="table-inline-edit-row"), ]