diff --git a/project/main/templates/main/components/inline_table_row.html b/project/main/templates/main/components/inline_table_row.html index 0c11523..62dbb67 100644 --- a/project/main/templates/main/components/inline_table_row.html +++ b/project/main/templates/main/components/inline_table_row.html @@ -1,4 +1,22 @@ -{% macro inline_table_row(person, is_editing, errors={}) %} +{% macro inline_table_row(person) %} + + {{ person.name }} + {{ person.address }} + {{ person.city }} + + + + +{% endmacro %} + + +{% macro inline_table_row_edit(person, cities, errors={}) %} {% macro render_input(field_name, value) %} {% set has_error = field_name in errors %} {% endmacro %} - {% if is_editing %} - - - {{ render_input(field_name="name", value=person.name) }} - - - {{ render_input(field_name="address", value=person.address) }} - - - {{ render_input(field_name="city", value=person.city) }} - - - - - - - {% else %} - - {{ person.name }} - {{ person.address }} - {{ person.city }} - - - - - {% endif %} + {% macro render_select(field_name, value, options) %} + {% set has_error = field_name in errors %} + + {% endmacro %} + + + + {{ render_input(field_name="name", value=person.name) }} + + + {{ render_input(field_name="address", value=person.address) }} + + +{# {{ render_input(field_name="city", value=person.city) }}#} + {{ render_select(field_name="city", value=person.city, options=cities) }} + + + + + + {% endmacro %} diff --git a/project/main/templates/main/table_inline_edit.html b/project/main/templates/main/table_inline_edit.html index 93d4d24..04b0b2b 100644 --- a/project/main/templates/main/table_inline_edit.html +++ b/project/main/templates/main/table_inline_edit.html @@ -17,7 +17,7 @@ {% for person in persons %} - {{ inline_table_row(person, is_editing=False) }} + {{ inline_table_row(person) }} {% endfor %} diff --git a/project/main/templates/main/table_inline_table_row.html b/project/main/templates/main/table_inline_table_row.html index 42b8039..baacd0c 100644 --- a/project/main/templates/main/table_inline_table_row.html +++ b/project/main/templates/main/table_inline_table_row.html @@ -1,3 +1,7 @@ -{% from "main/components/inline_table_row.html" import inline_table_row %} +{% from "main/components/inline_table_row.html" import inline_table_row, inline_table_row_edit %} -{{ inline_table_row(person, is_editing=is_editing, errors=errors) }} +{% if is_editing %} + {{ inline_table_row_edit(person, cities=cities, errors=errors) }} +{% else %} + {{ inline_table_row(person) }} +{% endif %} diff --git a/project/main/views/table_inline_edit.py b/project/main/views/table_inline_edit.py index c40e424..88af0c0 100644 --- a/project/main/views/table_inline_edit.py +++ b/project/main/views/table_inline_edit.py @@ -8,6 +8,15 @@ from django.shortcuts import render from project.main.models import Person from project.main.views.demo_view_base import DemoViewBase +CITIES: list[str] = [ + "", + "Zagreb", + "Split", + "Pula", + "Rijeka", + "Kozari bok", +] + def get_person(pk: int) -> Person: try: @@ -46,6 +55,7 @@ class TableInlineEditRowView(DemoViewBase): context_data.update( { "person": person, + "cities": CITIES, "is_editing": action == "edit", } ) @@ -66,12 +76,11 @@ class TableInlineEditRowView(DemoViewBase): else: person.save() - print(errors) - return render( context={ "person": person, "errors": errors, + "cities": CITIES, "is_editing": errors is not None, }, template_name=self.template_name,