89 lines
2.6 KiB
Python
89 lines
2.6 KiB
Python
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.demo_view_base import DemoViewBase
|
|
|
|
|
|
@dataclass
|
|
class ComplexFormContext:
|
|
...
|
|
|
|
|
|
@dataclass
|
|
class ControlState:
|
|
checked: bool = False
|
|
visible: bool = True
|
|
enabled: bool = True
|
|
|
|
|
|
@dataclass
|
|
class FormState:
|
|
route_module: ControlState
|
|
smart_routing: ControlState
|
|
geo_routing: ControlState
|
|
use_packing_model_per_route: ControlState
|
|
prekitting_to_box: ControlState
|
|
prekitting_to_pallet: ControlState
|
|
real_time_stock: ControlState
|
|
use_packing_model_per_machine: ControlState
|
|
warehouse: ControlState
|
|
custom_forms_in_routing: ControlState
|
|
|
|
|
|
def form_to_state(values: dict) -> FormState:
|
|
return FormState(
|
|
route_module=ControlState(checked=values.get("route_module") == "on"),
|
|
smart_routing=ControlState(checked=values.get("smart_routing") == "on"),
|
|
geo_routing=ControlState(checked=values.get("geo_routing") == "on"),
|
|
use_packing_model_per_route=ControlState(
|
|
checked=values.get("use_packing_model_per_route") == "on"
|
|
),
|
|
prekitting_to_box=ControlState(checked=values.get("prekitting_to_box") == "on"),
|
|
prekitting_to_pallet=ControlState(
|
|
checked=values.get("prekitting_to_pallet") == "on"
|
|
),
|
|
real_time_stock=ControlState(checked=values.get("real_time_stock") == "on"),
|
|
use_packing_model_per_machine=ControlState(
|
|
checked=values.get("use_packing_model_per_machine") == "on"
|
|
),
|
|
warehouse=ControlState(checked=values.get("warehouse") == "on"),
|
|
custom_forms_in_routing=ControlState(
|
|
checked=values.get("custom_forms_in_routing") == "on"
|
|
),
|
|
)
|
|
|
|
|
|
class ComplexFormView(DemoViewBase):
|
|
template_name = "main/complex_form.html"
|
|
active_section = "complex-form"
|
|
title = "Complex Form"
|
|
|
|
def get_context_data(self, **kwargs) -> dict[str, Any]:
|
|
context = super().get_context_data(**kwargs)
|
|
context.update(
|
|
{
|
|
"state": form_to_state(values={}),
|
|
}
|
|
)
|
|
return context
|
|
|
|
def post(self, request: WSGIRequest, *args, **kwargs) -> HttpResponse:
|
|
...
|
|
|
|
|
|
class ComplexFormHandleView(TemplateView):
|
|
template_name = "main/complex_form_content.html"
|
|
|
|
def post(self, request: WSGIRequest, *args, **kwargs) -> HttpResponse:
|
|
state = form_to_state(values=request.POST)
|
|
|
|
return self.render_to_response(
|
|
context={
|
|
"state": state,
|
|
}
|
|
)
|