new serializer for locationgroup
This commit is contained in:
parent
db938414fb
commit
cc2020e7c3
10 changed files with 58 additions and 57 deletions
18
src/c3nav/mapdata/utils/cache/stats.py
vendored
18
src/c3nav/mapdata/utils/cache/stats.py
vendored
|
@ -90,7 +90,7 @@ def convert_locate(data):
|
|||
for measurement in BeaconMeasurement.objects.all().select_related('space', 'space__level'):
|
||||
pos = CustomLocation(measurement.space.level, measurement.geometry.x, measurement.geometry.y,
|
||||
permissions=set())
|
||||
space_slug = measurement.space.get_slug()
|
||||
space_slug = measurement.space.effective_slug
|
||||
level_label = measurement.space.level.short_label
|
||||
grid_square = pos.grid_square if grid.enabled else None
|
||||
measurement_lookup[pos.pk] = (measurement.pk, grid_square, space_slug, level_label)
|
||||
|
@ -143,23 +143,23 @@ def convert_location(data):
|
|||
location = location.get_child()
|
||||
if isinstance(location, LocationRedirect):
|
||||
continue
|
||||
result['locations']['by_type'].setdefault(location.__class__.__name__.lower(), {})[location.get_slug()] = 0
|
||||
location_slugs[location.pk] = location.get_slug()
|
||||
result['locations']['by_type'].setdefault(location.__class__.__name__.lower(), {})[location.effective_slug] = 0
|
||||
location_slugs[location.pk] = location.effective_slug
|
||||
if isinstance(location, Level):
|
||||
result['locations']['by_level'][location.short_label] = 0
|
||||
result['coordinates']['by_level'][location.short_label] = 0
|
||||
level_labels[location.pk] = location.short_label
|
||||
if isinstance(location, Space):
|
||||
result['locations']['by_space'][location.get_slug()] = 0
|
||||
result['coordinates']['by_space'][location.get_slug()] = 0
|
||||
result['locations']['by_space'][location.effective_slug] = 0
|
||||
result['coordinates']['by_space'][location.effective_slug] = 0
|
||||
if isinstance(location, Area):
|
||||
if getattr(location, 'can_search', False) or getattr(location, 'can_describe', False):
|
||||
result['coordinates']['by_area'][location.get_slug()] = 0
|
||||
result['coordinates']['by_area'][location.effective_slug] = 0
|
||||
if isinstance(location, POI):
|
||||
if getattr(location, 'can_search', False) or getattr(location, 'can_describe', False):
|
||||
result['coordinates']['by_poi'][location.get_slug()] = 0
|
||||
result['coordinates']['by_poi'][location.effective_slug] = 0
|
||||
if isinstance(location, LocationGroup):
|
||||
result['locations']['by_group'][location.get_slug()] = 0
|
||||
result['locations']['by_group'][location.effective_slug] = 0
|
||||
|
||||
for name, value in data:
|
||||
if name[0] != 'pk' or name[0] == 'c:anywhere':
|
||||
|
@ -187,7 +187,7 @@ def convert_location(data):
|
|||
result['locations']['total'] += value
|
||||
location = getattr(location, 'target', location)
|
||||
result['locations']['by_type'].setdefault(location.__class__.__name__.lower(),
|
||||
{})[location.get_slug()] += value
|
||||
{})[location.effective_slug] += value
|
||||
if hasattr(location, 'space_id'):
|
||||
result['locations']['by_space'][location_slugs[location.space_id]] += value
|
||||
if hasattr(location, 'level_id'):
|
||||
|
|
|
@ -342,32 +342,32 @@ class CustomLocation:
|
|||
(_('Slug'), self.pk),
|
||||
(_('Level'), {
|
||||
'id': self.level.pk,
|
||||
'slug': self.level.get_slug(),
|
||||
'slug': self.level.effective_slug,
|
||||
'title': self.level.title,
|
||||
'can_search': self.level.can_search,
|
||||
}),
|
||||
(_('Space'), {
|
||||
'id': self.space.pk,
|
||||
'slug': self.space.get_slug(),
|
||||
'slug': self.space.effective_slug,
|
||||
'title': self.space.title,
|
||||
'can_search': self.space.can_search,
|
||||
} if self.space else None),
|
||||
(_('Areas'), tuple({
|
||||
'id': area.pk,
|
||||
'slug': area.get_slug(),
|
||||
'slug': area.effective_slug,
|
||||
'title': area.title,
|
||||
'can_search': area.can_search,
|
||||
} for area in self.areas)),
|
||||
(_('Grid Square'), self.grid_square or None),
|
||||
(_('Near Area'), {
|
||||
'id': self.near_area.pk,
|
||||
'slug': self.near_area.get_slug(),
|
||||
'slug': self.near_area.effective_slug,
|
||||
'title': self.near_area.title,
|
||||
'can_search': self.near_area.can_search,
|
||||
} if self.near_area else None),
|
||||
(_('Near POI'), {
|
||||
'id': self.near_poi.pk,
|
||||
'slug': self.near_poi.get_slug(),
|
||||
'slug': self.near_poi.effective_slug,
|
||||
'title': self.near_poi.title,
|
||||
'can_search': self.near_poi.can_search,
|
||||
} if self.near_poi else None),
|
||||
|
@ -459,7 +459,8 @@ class CustomLocation:
|
|||
def get_icon(self):
|
||||
return self.icon
|
||||
|
||||
def get_slug(self):
|
||||
@property
|
||||
def effective_slug(self):
|
||||
return self.pk
|
||||
|
||||
@cached_property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue