add missing api endpoint for LabelSettings and use new_serialize
This commit is contained in:
parent
38c6e6a863
commit
9debd7c845
3 changed files with 23 additions and 30 deletions
|
@ -15,10 +15,10 @@ from c3nav.mapdata.models import (Area, Building, Door, Hole, Level, LocationGro
|
||||||
from c3nav.mapdata.models.access import AccessRestriction, AccessRestrictionGroup
|
from c3nav.mapdata.models.access import AccessRestriction, AccessRestrictionGroup
|
||||||
from c3nav.mapdata.models.geometry.space import (POI, Column, CrossDescription, LeaveDescription, LineObstacle,
|
from c3nav.mapdata.models.geometry.space import (POI, Column, CrossDescription, LeaveDescription, LineObstacle,
|
||||||
Obstacle, Ramp)
|
Obstacle, Ramp)
|
||||||
from c3nav.mapdata.models.locations import DynamicLocation
|
from c3nav.mapdata.models.locations import DynamicLocation, LabelSettings
|
||||||
from c3nav.mapdata.schemas.filters import (ByCategoryFilter, ByGroupFilter, ByOnTopOfFilter, FilterSchema,
|
from c3nav.mapdata.schemas.filters import (ByCategoryFilter, ByGroupFilter, ByOnTopOfFilter, FilterSchema,
|
||||||
LevelGeometryFilter, SpaceGeometryFilter, BySpaceFilter, ByOverlayFilter)
|
LevelGeometryFilter, SpaceGeometryFilter, BySpaceFilter, ByOverlayFilter)
|
||||||
from c3nav.mapdata.schemas.model_base import schema_description
|
from c3nav.mapdata.schemas.model_base import schema_description, LabelSettingsSchema
|
||||||
from c3nav.mapdata.schemas.models import (AccessRestrictionGroupSchema, AccessRestrictionSchema, AreaSchema,
|
from c3nav.mapdata.schemas.models import (AccessRestrictionGroupSchema, AccessRestrictionSchema, AreaSchema,
|
||||||
BuildingSchema, ColumnSchema, CrossDescriptionSchema, DoorSchema,
|
BuildingSchema, ColumnSchema, CrossDescriptionSchema, DoorSchema,
|
||||||
DynamicLocationSchema, HoleSchema, LeaveDescriptionSchema, LevelSchema,
|
DynamicLocationSchema, HoleSchema, LeaveDescriptionSchema, LevelSchema,
|
||||||
|
@ -207,6 +207,10 @@ mapdata_endpoints: dict[str, list[MapdataEndpoint]] = {
|
||||||
model=DynamicLocation,
|
model=DynamicLocation,
|
||||||
schema=DynamicLocationSchema,
|
schema=DynamicLocationSchema,
|
||||||
),
|
),
|
||||||
|
MapdataEndpoint(
|
||||||
|
model=LabelSettings,
|
||||||
|
schema=LabelSettingsSchema,
|
||||||
|
),
|
||||||
MapdataEndpoint(
|
MapdataEndpoint(
|
||||||
model=DataOverlay,
|
model=DataOverlay,
|
||||||
schema=DataOverlaySchema,
|
schema=DataOverlaySchema,
|
||||||
|
|
|
@ -464,6 +464,8 @@ class LocationRedirect(LocationSlug):
|
||||||
|
|
||||||
|
|
||||||
class LabelSettings(SerializableMixin, models.Model):
|
class LabelSettings(SerializableMixin, models.Model):
|
||||||
|
new_serialize = True
|
||||||
|
|
||||||
title = I18nField(_('Title'), plural_name='titles', fallback_any=True)
|
title = I18nField(_('Title'), plural_name='titles', fallback_any=True)
|
||||||
min_zoom = models.DecimalField(_('min zoom'), max_digits=3, decimal_places=1, default=-10,
|
min_zoom = models.DecimalField(_('min zoom'), max_digits=3, decimal_places=1, default=-10,
|
||||||
validators=[MinValueValidator(Decimal('-10')),
|
validators=[MinValueValidator(Decimal('-10')),
|
||||||
|
@ -475,17 +477,6 @@ class LabelSettings(SerializableMixin, models.Model):
|
||||||
validators=[MinValueValidator(12),
|
validators=[MinValueValidator(12),
|
||||||
MaxValueValidator(30)])
|
MaxValueValidator(30)])
|
||||||
|
|
||||||
def _serialize(self, detailed=True, **kwargs):
|
|
||||||
result = super()._serialize(detailed=detailed, **kwargs)
|
|
||||||
if detailed:
|
|
||||||
result['titles'] = self.titles
|
|
||||||
if self.min_zoom > -10:
|
|
||||||
result['min_zoom'] = self.min_zoom
|
|
||||||
if self.max_zoom < 10:
|
|
||||||
result['max_zoom'] = self.max_zoom
|
|
||||||
result['font_size'] = self.font_size
|
|
||||||
return result
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Label Settings')
|
verbose_name = _('Label Settings')
|
||||||
verbose_name_plural = _('Label Settings')
|
verbose_name_plural = _('Label Settings')
|
||||||
|
@ -529,17 +520,6 @@ class DynamicLocation(CustomLocationProxyMixin, SpecificLocation, models.Model):
|
||||||
verbose_name_plural = _('Dynamic locations')
|
verbose_name_plural = _('Dynamic locations')
|
||||||
default_related_name = 'dynamiclocations'
|
default_related_name = 'dynamiclocations'
|
||||||
|
|
||||||
def _serialize(self, **kwargs):
|
|
||||||
"""custom_location = self.get_custom_location()
|
|
||||||
print(custom_location)
|
|
||||||
result = {} if custom_location is None else custom_location.serialize(**kwargs)
|
|
||||||
super_result = super()._serialize(**kwargs)
|
|
||||||
super_result['subtitle'] = '%s %s, %s' % (_('(moving)'), result['title'], result['subtitle'])
|
|
||||||
result.update(super_result)"""
|
|
||||||
result = super()._serialize(**kwargs)
|
|
||||||
result['dynamic'] = True
|
|
||||||
return result
|
|
||||||
|
|
||||||
def register_change(self, force=False):
|
def register_change(self, force=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
from typing import Annotated, Optional, Union, Literal
|
from typing import Annotated, Optional, Union, Literal, ClassVar
|
||||||
|
|
||||||
from pydantic import Field as APIField
|
from pydantic import Field as APIField
|
||||||
from pydantic import PositiveInt
|
from pydantic import PositiveInt
|
||||||
|
@ -127,7 +127,7 @@ class LocationSchema(WithAccessRestrictionSchema, TitledSchema, LocationSlugSche
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class LabelSettingsSchema(DjangoModelSchema): # todo: add titles back in here
|
class LabelSettingsSchema(TitledSchema, DjangoModelSchema): # todo: add titles back in here
|
||||||
"""
|
"""
|
||||||
Settings preset for how and when to display a label. Reusable between objects.
|
Settings preset for how and when to display a label. Reusable between objects.
|
||||||
The title describes the title of this preset, not the displayed label.
|
The title describes the title of this preset, not the displayed label.
|
||||||
|
@ -149,6 +149,15 @@ class LabelSettingsSchema(DjangoModelSchema): # todo: add titles back in here
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EffectiveLabelSettingsSchema(LabelSettingsSchema):
|
||||||
|
"""
|
||||||
|
Settings preset for how and when to display a label.
|
||||||
|
"""
|
||||||
|
id: ClassVar[None]
|
||||||
|
title: ClassVar[None]
|
||||||
|
titles: ClassVar[None]
|
||||||
|
|
||||||
|
|
||||||
class SpecificLocationSchema(LocationSchema):
|
class SpecificLocationSchema(LocationSchema):
|
||||||
grid_square: Union[
|
grid_square: Union[
|
||||||
Annotated[NonEmptyStr, APIField(title="grid square", description="grid square(s) that this location is in")],
|
Annotated[NonEmptyStr, APIField(title="grid square", description="grid square(s) that this location is in")],
|
||||||
|
@ -199,24 +208,24 @@ class SpecificLocationSchema(LocationSchema):
|
||||||
title="label settings",
|
title="label settings",
|
||||||
description=(
|
description=(
|
||||||
schema_description(LabelSettingsSchema) +
|
schema_description(LabelSettingsSchema) +
|
||||||
"\n\nif not set, label settings of location groups might be used"
|
"\n\nif not set, label settings of location groups should be used"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
effective_label_settings: Union[
|
effective_label_settings: Union[
|
||||||
Annotated[LabelSettingsSchema, APIField(
|
Annotated[EffectiveLabelSettingsSchema, APIField(
|
||||||
title="label settings",
|
title="label settings",
|
||||||
description="label settings to use",
|
description="label settings to use",
|
||||||
)],
|
)],
|
||||||
Annotated[None, APIField(
|
Annotated[None, APIField(
|
||||||
title="null",
|
title="null",
|
||||||
description="label settings from location group will be used, if available"
|
description="don't display a label"
|
||||||
)],
|
)],
|
||||||
] = APIField(
|
] = APIField(
|
||||||
default=None,
|
default=None,
|
||||||
title="label settings",
|
title="label settings",
|
||||||
description=(
|
description=(
|
||||||
schema_description(LabelSettingsSchema) +
|
schema_description(LabelSettingsSchema) +
|
||||||
"\n\nif not set, label settings of location groups might be used"
|
"\n\neffective label settings to use for this location"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
label_override: Union[
|
label_override: Union[
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue