Basic table inline edit functionality

This commit is contained in:
Eden Kirin
2024-05-15 22:15:27 +02:00
parent 7c20d4d23e
commit c7f89a9ab4
13 changed files with 193 additions and 4 deletions

View File

@ -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

View File

@ -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