Views
This commit is contained in:
@ -4,5 +4,7 @@ from jinja2 import Environment
|
|||||||
def environment(**options):
|
def environment(**options):
|
||||||
env = Environment(**options)
|
env = Environment(**options)
|
||||||
|
|
||||||
env.globals.update({})
|
env.globals.update({
|
||||||
|
# "url": reverse_url,
|
||||||
|
})
|
||||||
return env
|
return env
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
content="width=100%, user-scalable=yes, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
content="width=100%, user-scalable=yes, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||||
<script src="https://unpkg.com/htmx.org@1.9.11" integrity="sha384-0gxUXCCR8yv9FM2b+U3FDbsKthCI66oH5IA9fHppQq9DDMHuMauqq1ZHBpJxQ0J0" crossorigin="anonymous"></script>
|
<script src="https://unpkg.com/htmx.org@1.9.11" integrity="sha384-0gxUXCCR8yv9FM2b+U3FDbsKthCI66oH5IA9fHppQq9DDMHuMauqq1ZHBpJxQ0J0" crossorigin="anonymous"></script>
|
||||||
<title>Django-html demo</title>
|
<title>{{ title or "Django-html demo" }}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% block body_content %}{% endblock %}
|
{% block body_content %}{% endblock %}
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
{% extends "main/base/base.html" %}
|
|
||||||
|
|
||||||
{% block body_content %}
|
|
||||||
<div class="container">
|
|
||||||
{% block content %}{% endblock %}
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
20
project/main/templates/main/base/layout.html
Normal file
20
project/main/templates/main/base/layout.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{% extends "main/base/base.html" %}
|
||||||
|
{% from "main/components/nav.html" import nav %}
|
||||||
|
|
||||||
|
{% block body_content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="mt-5 mb-5 pb-3 border-bottom border-dark">
|
||||||
|
{{ title }}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3">
|
||||||
|
{{ nav(active_section=active_section) }}
|
||||||
|
</div>
|
||||||
|
<div class="col-md-9">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
8
project/main/templates/main/complex_form.html
Normal file
8
project/main/templates/main/complex_form.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{% extends "main/base/layout.html" %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p>
|
||||||
|
This is some complex form content bellow.
|
||||||
|
</p>
|
||||||
|
{% endblock %}
|
||||||
18
project/main/templates/main/components/nav.html
Normal file
18
project/main/templates/main/components/nav.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{% macro nav(active_section) %}
|
||||||
|
{% macro render_item(title, link) %}
|
||||||
|
<a
|
||||||
|
href="{{ url(link) }}"
|
||||||
|
class="list-group-item list-group-item-action {% if active_section == link %}active{% endif %}"
|
||||||
|
>
|
||||||
|
{{ title }}
|
||||||
|
</a>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
<div class="list-group list-group-flush">
|
||||||
|
{{ render_item("Swap Content", "swap-content") }}
|
||||||
|
{{ 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") }}
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
||||||
8
project/main/templates/main/filter_list.html
Normal file
8
project/main/templates/main/filter_list.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{% extends "main/base/layout.html" %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p>
|
||||||
|
This is some filter list content bellow.
|
||||||
|
</p>
|
||||||
|
{% endblock %}
|
||||||
8
project/main/templates/main/form_validation.html
Normal file
8
project/main/templates/main/form_validation.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{% extends "main/base/layout.html" %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p>
|
||||||
|
This is some form validation content bellow.
|
||||||
|
</p>
|
||||||
|
{% endblock %}
|
||||||
@ -25,7 +25,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h4 class="mt-5">
|
<h4 class="mt-5">
|
||||||
<a href="#">
|
<a href="{{ url("swap-content") }}">
|
||||||
Start demo
|
Start demo
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|||||||
8
project/main/templates/main/swap_content.html
Normal file
8
project/main/templates/main/swap_content.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{% extends "main/base/layout.html" %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p>
|
||||||
|
This is some swappable content bellow.
|
||||||
|
</p>
|
||||||
|
{% endblock %}
|
||||||
8
project/main/templates/main/table_inline_edit.html
Normal file
8
project/main/templates/main/table_inline_edit.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{% extends "main/base/layout.html" %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p>
|
||||||
|
This is some table inline edit content bellow.
|
||||||
|
</p>
|
||||||
|
{% endblock %}
|
||||||
@ -1 +1,6 @@
|
|||||||
|
from .complex_form import ComplexFormView
|
||||||
|
from .filter_list import FilterListView
|
||||||
|
from .form_validation import FormValidationView
|
||||||
from .home import HomeView
|
from .home import HomeView
|
||||||
|
from .swap_content import SwapContentView
|
||||||
|
from .table_inline_edit import TableInlineEditView
|
||||||
|
|||||||
7
project/main/views/complex_form.py
Normal file
7
project/main/views/complex_form.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from project.main.views.demo_view_base import DemoViewBase
|
||||||
|
|
||||||
|
|
||||||
|
class ComplexFormView(DemoViewBase):
|
||||||
|
template_name = "main/complex_form.html"
|
||||||
|
active_section = "complex-form"
|
||||||
|
title = "Complex Form"
|
||||||
20
project/main/views/demo_view_base.py
Normal file
20
project/main/views/demo_view_base.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from django.core.handlers.wsgi import WSGIRequest
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
|
|
||||||
|
class DemoViewBase(TemplateView):
|
||||||
|
active_section = None
|
||||||
|
title = None
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs) -> dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"title": self.title,
|
||||||
|
"active_section": self.active_section,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get(self, request: WSGIRequest, *args, **kwargs) -> HttpResponse:
|
||||||
|
context = self.get_context_data(**kwargs)
|
||||||
|
return self.render_to_response(context)
|
||||||
7
project/main/views/filter_list.py
Normal file
7
project/main/views/filter_list.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from project.main.views.demo_view_base import DemoViewBase
|
||||||
|
|
||||||
|
|
||||||
|
class FilterListView(DemoViewBase):
|
||||||
|
template_name = "main/filter_list.html"
|
||||||
|
active_section = "filter-list"
|
||||||
|
title = "Filter List"
|
||||||
7
project/main/views/form_validation.py
Normal file
7
project/main/views/form_validation.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from project.main.views.demo_view_base import DemoViewBase
|
||||||
|
|
||||||
|
|
||||||
|
class FormValidationView(DemoViewBase):
|
||||||
|
template_name = "main/form_validation.html"
|
||||||
|
active_section = "form-validation"
|
||||||
|
title = "Form Validation"
|
||||||
7
project/main/views/swap_content.py
Normal file
7
project/main/views/swap_content.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
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"
|
||||||
7
project/main/views/table_inline_edit.py
Normal file
7
project/main/views/table_inline_edit.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
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"
|
||||||
@ -4,4 +4,9 @@ from project.main import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.HomeView.as_view(), name="home"),
|
path("", views.HomeView.as_view(), name="home"),
|
||||||
|
path("swap-content", views.SwapContentView.as_view(), name="swap-content"),
|
||||||
|
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"),
|
||||||
|
path("table-inline-edit", views.TableInlineEditView.as_view(), name="table-inline-edit"),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user