Files
django-htmx-presenatation/project/main/views/table_inline_edit.py
2024-05-15 22:16:59 +02:00

47 lines
1.2 KiB
Python

from typing import Any
from django.http import Http404
from project.main.models import Person
from project.main.views.demo_view_base import DemoViewBase
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