Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions traffic_control/admin/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PlanAdmin(
AuditLogHistoryAdmin,
):
form = PlanModelForm
SHOW_Z_COORD = False
fieldsets = (
(
_("General information"),
Expand Down
2 changes: 2 additions & 0 deletions traffic_control/admin/road_marking.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class RoadMarkingPlanAdmin(
resource_class = RoadMarkingPlanResource
extra_export_resource_classes = [RoadMarkingPlanToRealTemplateResource]
form = RoadMarkingPlanModelForm
SHOW_Z_COORD = False
fieldsets = (
(
_("General information"),
Expand Down Expand Up @@ -234,6 +235,7 @@ class RoadMarkingRealAdmin(
plan_model_field_name = "road_marking_plan"
resource_class = RoadMarkingRealResource
form = RoadMarkingRealModelForm
SHOW_Z_COORD = False
fieldsets = (
(
_("General information"),
Expand Down
4 changes: 2 additions & 2 deletions traffic_control/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def clean(self):
class Geometry3DFieldForm(forms.ModelForm):
"""Form class that allows entering a z coordinate for 3d point and location in ewkt format"""

z_coord = forms.FloatField(label=_("Location (z)"), initial=0)
z_coord = forms.FloatField(label=_("Location (z)"), initial=0, required=False)
location_ewkt = forms.CharField(label=_("Location (EWKT)"), widget=forms.Textarea, required=False)

def __init__(self, *args, **kwargs):
Expand All @@ -195,7 +195,7 @@ def __init__(self, *args, **kwargs):

def clean(self):
cleaned_data = super().clean()
z_coord = cleaned_data.pop("z_coord", 0)
z_coord = cleaned_data.pop("z_coord", 0) or 0
location = cleaned_data.get("location", None)
location_ewkt = cleaned_data.get("location_ewkt", None)
new_geom = self._get_new_geom(location, location_ewkt, z_coord)
Expand Down
11 changes: 11 additions & 0 deletions traffic_control/mixins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ class Geometry3DFieldAdminMixin:
"""

gis_widget = CityInfra3DOSMWidget
SHOW_Z_COORD = True

def get_fieldsets(self, request, obj=None, **kwargs):
fieldsets = super().get_fieldsets(request, obj, **kwargs)
if not self.SHOW_Z_COORD:
for _, fields in fieldsets:
if "z_coord" in fields["fields"]:
temp_list = list(fields["fields"])
temp_list.remove("z_coord")
fields["fields"] = temp_list
return fieldsets


class UserStampedAdminMixin:
Expand Down
Loading