This commit is contained in:
Eden Kirin
2024-04-06 23:32:41 +02:00
parent 5e1989a60f
commit 1b1d0f1b5c
11 changed files with 386 additions and 182 deletions

View File

@ -1,43 +1,23 @@
from dataclasses import dataclass
from typing import Any
from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponse
from django.views.generic import TemplateView
from project.main.views.complex_form.state_models import CheckboxState, FormState, SelectState, RouteModuleState
from project.main.views.complex_form.reports_state import ReportsState
from project.main.views.complex_form.route_module_state import RouteModuleState
from project.main.views.demo_view_base import DemoViewBase
@dataclass
class FormState:
route_module: RouteModuleState
reports: ReportsState
# def control_state(state: FormState) -> None:
# state.smart_routing.enabled = state.route_module.checked
# state.geo_routing.enabled = state.route_module.checked
# state.warehouse.enabled = state.route_module.checked
# state.custom_forms_in_routing.enabled = state.route_module.checked
#
# state.predictive_pickup.visible = (
# state.smart_routing.checked and state.smart_routing.enabled
# )
# state.automatic_planning.visible = (
# state.smart_routing.checked and state.smart_routing.enabled
# )
# # state.prekitting_to_box.visible = (
# # state.use_packing_model_per_route.enabled
# # and state.use_packing_model_per_route.checked
# # )
# # state.prekitting_to_pallet.visible = (
# # state.use_packing_model_per_route.enabled
# # and state.use_packing_model_per_route.checked
# # )
# # state.real_time_stock.visible = (
# # state.use_packing_model_per_route.enabled
# # and state.use_packing_model_per_route.checked
# # )
# state.end_warehouse_tracking.visible = state.warehouse.checked
#
# print(state)
# print("-" * 100)
def control_state(self) -> None:
self.route_module.control_state()
self.reports.control_state()
class ComplexFormView(DemoViewBase):
@ -49,9 +29,10 @@ class ComplexFormView(DemoViewBase):
context = super().get_context_data(**kwargs)
state = FormState(
route_module=RouteModuleState.from_form(values={})
route_module=RouteModuleState.from_form(values={}),
reports=ReportsState.from_form(values={}),
)
# control_state(state)
state.control_state()
context.update(
{
@ -64,19 +45,29 @@ class ComplexFormView(DemoViewBase):
...
class ComplexFormHandleView(TemplateView):
class RouteModuleHandleView(TemplateView):
template_name = "main/complex_form/route_module.html"
def post(self, request: WSGIRequest, *args, **kwargs) -> HttpResponse:
print(request.POST)
state = FormState(
route_module=RouteModuleState.from_form(values=request.POST),
)
# state = route_module_form_to_state(values=request.POST)
# control_state(state)
state = RouteModuleState.from_form(values=request.POST)
state.control_state()
return self.render_to_response(
context={
"form_state": state,
"state": state,
}
)
class ReportsHandleView(TemplateView):
template_name = "main/complex_form/reports.html"
def post(self, request: WSGIRequest, *args, **kwargs) -> HttpResponse:
state = ReportsState.from_form(values=request.POST)
state.control_state()
return self.render_to_response(
context={
"state": state,
}
)