From f2dc83caab621d2c33637636815b80bdf8518c6a Mon Sep 17 00:00:00 2001 From: Eden Kirin Date: Sat, 6 Apr 2024 16:46:24 +0200 Subject: [PATCH] Swap content --- project/main/templates/main/base/base.html | 2 +- .../main/templates/main/components/nav.html | 3 +- project/main/templates/main/home.html | 2 +- project/main/templates/main/swap.html | 24 ++++++++++ project/main/templates/main/swap_content.html | 48 ++++++++++++++++--- project/main/views/__init__.py | 2 +- project/main/views/swap.py | 22 +++++++++ project/main/views/swap_content.py | 7 --- project/urls.py | 2 +- 9 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 project/main/templates/main/swap.html create mode 100644 project/main/views/swap.py delete mode 100644 project/main/views/swap_content.py diff --git a/project/main/templates/main/base/base.html b/project/main/templates/main/base/base.html index d25110f..99fad34 100644 --- a/project/main/templates/main/base/base.html +++ b/project/main/templates/main/base/base.html @@ -8,7 +8,7 @@ {{ title or "Django-html demo" }} - + {% block body_content %}{% endblock %} \ No newline at end of file diff --git a/project/main/templates/main/components/nav.html b/project/main/templates/main/components/nav.html index f574c26..feb408a 100644 --- a/project/main/templates/main/components/nav.html +++ b/project/main/templates/main/components/nav.html @@ -9,10 +9,11 @@ {% endmacro %}
- {{ render_item("Swap Content", "swap-content") }} + {{ render_item("Swap Content", "swap") }} {{ render_item("Form Validation", "form-validation") }} {{ render_item("Complex Form", "complex-form") }} {{ render_item("Filter List", "filter-list") }} {{ render_item("Table Inline Edit", "table-inline-edit") }} + {{ render_item("Back to Home", "home") }}
{% endmacro %} diff --git a/project/main/templates/main/home.html b/project/main/templates/main/home.html index 91707fa..9ae6e65 100644 --- a/project/main/templates/main/home.html +++ b/project/main/templates/main/home.html @@ -25,7 +25,7 @@

- + Start demo

diff --git a/project/main/templates/main/swap.html b/project/main/templates/main/swap.html new file mode 100644 index 0000000..d690234 --- /dev/null +++ b/project/main/templates/main/swap.html @@ -0,0 +1,24 @@ +{% extends "main/base/layout.html" %} + + +{% block content %} + {% macro render_btn(title, cls, content) %} + + {% endmacro %} + + {{ render_btn(title="Initial", cls="btn-outline-secondary", content="initial") }} + {{ render_btn(title="Swap to content 1", cls="btn-info", content="info") }} + {{ render_btn(title="Swap to content 2", cls="btn-warning", content="warning") }} + {{ render_btn(title="Swap to content 3", cls="btn-danger", content="danger") }} + +
+ {% include("main/swap_content.html") %} +
+{% endblock %} diff --git a/project/main/templates/main/swap_content.html b/project/main/templates/main/swap_content.html index 0e792e7..313061b 100644 --- a/project/main/templates/main/swap_content.html +++ b/project/main/templates/main/swap_content.html @@ -1,8 +1,42 @@ -{% extends "main/base/layout.html" %} - - -{% block content %} -

- This is some swappable content bellow. +{% if content == "info" %} +

+ Bacon ipsum dolor amet cow capicola pancetta picanha biltong brisket filet mignon + turducken beef ribs burgdoggen landjaeger meatball venison shank. + Capicola ham pork chop, biltong kielbasa pancetta short loin jowl cupim pig + jerky drumstick turducken burgdoggen beef. Spare ribs flank ribeye cow doner, + shank chuck bacon ham hock porchetta kielbasa tri-tip. Ham t-bone chislic, + capicola andouille ham hock frankfurter tri-tip sausage kevin landjaeger shank ribeye. + Swine tri-tip spare ribs, rump flank bresaola kevin tail. Meatball tail picanha cow, + frankfurter ribeye sirloin pork belly short loin pig. Filet mignon spare ribs pastrami, + tri-tip ball tip tongue fatback pork chop.

-{% endblock %} +{% elif content == "warning" %} +

+ Beef ribs bacon sausage meatloaf pork belly kielbasa frankfurter ball tip + corned beef boudin. Ribeye turducken corned beef, ground round picanha doner + kielbasa fatback alcatra. Bresaola shankle ribeye meatloaf sirloin + alcatra short ribs chislic shank turkey brisket chicken. Andouille rump tongue, + landjaeger biltong brisket tail turkey leberkas jowl beef ribs corned beef. + Venison meatball pig short ribs, alcatra cow tenderloin. Leberkas fatback biltong, + pig rump doner short loin tongue filet mignon brisket tri-tip. Alcatra meatloaf biltong + drumstick capicola chislic chuck short ribs fatback ribeye turkey kevin. +

+{% elif content == "danger" %} +

+ Ham hock bacon short loin shank pork loin filet mignon kevin tongue. Chicken andouille + beef pork loin strip steak meatball jerky burgdoggen shoulder picanha. Pork belly tri-tip doner, + chicken frankfurter burgdoggen jerky t-bone. Chicken chuck hamburger tail shank burgdoggen. + Tenderloin biltong pork chop, sirloin leberkas pastrami salami jerky jowl tri-tip corned beef + ground round venison spare ribs chicken. +

+{% else %} +

+ Bacon shankle cupim biltong, burgdoggen hamburger meatloaf frankfurter tenderloin + landjaeger jerky capicola. Leberkas shoulder tri-tip sausage andouille hamburger cow + prosciutto beef ribs drumstick chicken. Capicola hamburger pork landjaeger burgdoggen. + Cupim jerky shank tongue fatback ham corned beef leberkas turkey meatloaf rump pig + ball tip bacon. Ham hock buffalo doner, shankle landjaeger kielbasa chicken pork + loin jowl leberkas alcatra chuck prosciutto brisket andouille. Pancetta meatloaf + shankle burgdoggen. +

+{% endif %} diff --git a/project/main/views/__init__.py b/project/main/views/__init__.py index f9dcfb8..10fec0c 100644 --- a/project/main/views/__init__.py +++ b/project/main/views/__init__.py @@ -2,5 +2,5 @@ from .complex_form import ComplexFormView from .filter_list import FilterListView from .form_validation import FormValidationView from .home import HomeView -from .swap_content import SwapContentView +from .swap import SwapView from .table_inline_edit import TableInlineEditView diff --git a/project/main/views/swap.py b/project/main/views/swap.py new file mode 100644 index 0000000..4e34e67 --- /dev/null +++ b/project/main/views/swap.py @@ -0,0 +1,22 @@ +from django.shortcuts import render +from django.core.handlers.wsgi import WSGIRequest +from django.http import HttpResponse + +from project.main.views.demo_view_base import DemoViewBase + + +class SwapView(DemoViewBase): + template_name = "main/swap.html" + active_section = "swap" + title = "Swap" + + def post(self, request: WSGIRequest, *args, **kwargs) -> HttpResponse: + context = { + "content": request.GET.get("content", "info") + } + + return render( + request=request, + context=context, + template_name="main/swap_content.html", + ) diff --git a/project/main/views/swap_content.py b/project/main/views/swap_content.py deleted file mode 100644 index dc0b875..0000000 --- a/project/main/views/swap_content.py +++ /dev/null @@ -1,7 +0,0 @@ -from project.main.views.demo_view_base import DemoViewBase - - -class SwapContentView(DemoViewBase): - template_name = "main/swap_content.html" - active_section = "swap-content" - title = "Swap Content" diff --git a/project/urls.py b/project/urls.py index 1b50b8f..61a3921 100644 --- a/project/urls.py +++ b/project/urls.py @@ -4,7 +4,7 @@ from project.main import views urlpatterns = [ path("", views.HomeView.as_view(), name="home"), - path("swap-content", views.SwapContentView.as_view(), name="swap-content"), + path("swap", views.SwapView.as_view(), name="swap"), path("filter-list", views.FilterListView.as_view(), name="filter-list"), path("form-validation", views.FormValidationView.as_view(), name="form-validation"), path("complex-form", views.ComplexFormView.as_view(), name="complex-form"),