it's grid square, not grid cell (even though we don't have square cells)
This commit is contained in:
parent
8824026ce0
commit
c666fd6db5
5 changed files with 33 additions and 33 deletions
|
@ -10,11 +10,11 @@ class AbstractGrid(ABC):
|
||||||
enabled = False
|
enabled = False
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_cell_for_point(self, x, y) -> Optional[str]:
|
def get_square_for_point(self, x, y) -> Optional[str]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_cells_for_bounds(self, bounds) -> Optional[str]:
|
def get_squares_for_bounds(self, bounds) -> Optional[str]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class Grid(AbstractGrid):
|
||||||
else:
|
else:
|
||||||
raise ValueError('column coordinates are not ordered')
|
raise ValueError('column coordinates are not ordered')
|
||||||
|
|
||||||
def get_cell_for_point(self, x, y):
|
def get_square_for_point(self, x, y):
|
||||||
x = bisect.bisect(self.cols, x)
|
x = bisect.bisect(self.cols, x)
|
||||||
if x <= 0 or x >= len(self.cols):
|
if x <= 0 or x >= len(self.cols):
|
||||||
return None
|
return None
|
||||||
|
@ -57,7 +57,7 @@ class Grid(AbstractGrid):
|
||||||
|
|
||||||
return '%s%d' % (string.ascii_uppercase[x-1], y)
|
return '%s%d' % (string.ascii_uppercase[x-1], y)
|
||||||
|
|
||||||
def get_cells_for_bounds(self, bounds):
|
def get_squares_for_bounds(self, bounds):
|
||||||
minx, miny, maxx, maxy = bounds
|
minx, miny, maxx, maxy = bounds
|
||||||
|
|
||||||
if self.invert_x:
|
if self.invert_x:
|
||||||
|
@ -65,22 +65,22 @@ class Grid(AbstractGrid):
|
||||||
if self.invert_y:
|
if self.invert_y:
|
||||||
miny, maxy = maxy, miny
|
miny, maxy = maxy, miny
|
||||||
|
|
||||||
min_cell = self.get_cell_for_point(minx, miny)
|
min_square = self.get_square_for_point(minx, miny)
|
||||||
max_cell = self.get_cell_for_point(maxx, maxy)
|
max_square = self.get_square_for_point(maxx, maxy)
|
||||||
|
|
||||||
if not min_cell or not max_cell:
|
if not min_square or not max_square:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if min_cell == max_cell:
|
if min_square == max_square:
|
||||||
return min_cell
|
return min_square
|
||||||
return '%s-%s' % (min_cell, max_cell)
|
return '%s-%s' % (min_square, max_square)
|
||||||
|
|
||||||
|
|
||||||
class DummyGrid(AbstractGrid):
|
class DummyGrid(AbstractGrid):
|
||||||
def get_cell_for_point(self, x, y):
|
def get_square_for_point(self, x, y):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_cells_for_bounds(self, bounds):
|
def get_squares_for_bounds(self, bounds):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -130,8 +130,8 @@ class Space(LevelGeometryMixin, SpecificLocation, models.Model):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def grid_cell(self):
|
def grid_square(self):
|
||||||
return grid.get_cells_for_bounds(self.geometry.bounds) or ''
|
return grid.get_squares_for_bounds(self.geometry.bounds) or ''
|
||||||
|
|
||||||
def details_display(self, editor_url=True, **kwargs):
|
def details_display(self, editor_url=True, **kwargs):
|
||||||
result = super().details_display(**kwargs)
|
result = super().details_display(**kwargs)
|
||||||
|
|
|
@ -127,8 +127,8 @@ class Area(SpaceGeometryMixin, SpecificLocation, models.Model):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def grid_cell(self):
|
def grid_square(self):
|
||||||
return grid.get_cells_for_bounds(self.geometry.bounds) or ''
|
return grid.get_squares_for_bounds(self.geometry.bounds) or ''
|
||||||
|
|
||||||
def details_display(self, editor_url=True, **kwargs):
|
def details_display(self, editor_url=True, **kwargs):
|
||||||
result = super().details_display(**kwargs)
|
result = super().details_display(**kwargs)
|
||||||
|
@ -237,8 +237,8 @@ class POI(SpaceGeometryMixin, SpecificLocation, models.Model):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def grid_cell(self):
|
def grid_square(self):
|
||||||
return grid.get_cell_for_point(self.x, self.y) or ''
|
return grid.get_square_for_point(self.x, self.y) or ''
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def x(self):
|
def x(self):
|
||||||
|
|
|
@ -117,7 +117,7 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def grid_cell(self):
|
def grid_square(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_color(self, instance=None):
|
def get_color(self, instance=None):
|
||||||
|
@ -139,9 +139,9 @@ class SpecificLocation(Location, models.Model):
|
||||||
def _serialize(self, detailed=True, **kwargs):
|
def _serialize(self, detailed=True, **kwargs):
|
||||||
result = super()._serialize(detailed=detailed, **kwargs)
|
result = super()._serialize(detailed=detailed, **kwargs)
|
||||||
if grid.enabled:
|
if grid.enabled:
|
||||||
grid_cell = self.grid_cell
|
grid_square = self.grid_square
|
||||||
if grid_cell is not None:
|
if grid_square is not None:
|
||||||
result['cell'] = grid_cell or None
|
result['cell'] = grid_square or None
|
||||||
if detailed:
|
if detailed:
|
||||||
groups = {}
|
groups = {}
|
||||||
for group in self.groups.all():
|
for group in self.groups.all():
|
||||||
|
@ -160,10 +160,10 @@ class SpecificLocation(Location, models.Model):
|
||||||
groupcategories.setdefault(group.category, []).append(group)
|
groupcategories.setdefault(group.category, []).append(group)
|
||||||
|
|
||||||
if grid.enabled:
|
if grid.enabled:
|
||||||
grid_cell = self.grid_cell
|
grid_square = self.grid_square
|
||||||
if grid_cell is not None:
|
if grid_square is not None:
|
||||||
grid_square_title = (_('Grid Squares') if grid_cell and '-' in grid_cell else _('Grid Square'))
|
grid_square_title = (_('Grid Squares') if grid_square and '-' in grid_square else _('Grid Square'))
|
||||||
result['display'].insert(3, (grid_square_title, grid_cell or None))
|
result['display'].insert(3, (grid_square_title, grid_square or None))
|
||||||
|
|
||||||
for category, groups in sorted(groupcategories.items(), key=lambda item: item[0].priority):
|
for category, groups in sorted(groupcategories.items(), key=lambda item: item[0].priority):
|
||||||
result['display'].insert(3, (
|
result['display'].insert(3, (
|
||||||
|
@ -183,8 +183,8 @@ class SpecificLocation(Location, models.Model):
|
||||||
groups = tuple(self.groups.all() if 'groups' in getattr(self, '_prefetched_objects_cache', ()) else ())
|
groups = tuple(self.groups.all() if 'groups' in getattr(self, '_prefetched_objects_cache', ()) else ())
|
||||||
groups = tuple(group for group in groups if group.can_describe)
|
groups = tuple(group for group in groups if group.can_describe)
|
||||||
subtitle = groups[0].title if groups else self.__class__._meta.verbose_name
|
subtitle = groups[0].title if groups else self.__class__._meta.verbose_name
|
||||||
if self.grid_cell:
|
if self.grid_square:
|
||||||
return '%s, %s' % (subtitle, self.grid_cell)
|
return '%s, %s' % (subtitle, self.grid_square)
|
||||||
return subtitle
|
return subtitle
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
|
|
@ -367,13 +367,13 @@ class CustomLocation:
|
||||||
return self.description.near_poi
|
return self.description.near_poi
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def grid_cell(self):
|
def grid_square(self):
|
||||||
return grid.get_cell_for_point(self.x, self.y) or ''
|
return grid.get_square_for_point(self.x, self.y) or ''
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def title_subtitle(self):
|
def title_subtitle(self):
|
||||||
grid_cell = self.grid_cell
|
grid_square = self.grid_square
|
||||||
level_subtitle = self.level.title if not grid_cell else ','.join((grid_cell, str(self.level.title)))
|
level_subtitle = self.level.title if not grid_square else ','.join((grid_square, str(self.level.title)))
|
||||||
|
|
||||||
title = _('In %(level)s') % {'level': self.level.title}
|
title = _('In %(level)s') % {'level': self.level.title}
|
||||||
if not self.space:
|
if not self.space:
|
||||||
|
@ -395,7 +395,7 @@ class CustomLocation:
|
||||||
else:
|
else:
|
||||||
return _('In %(space)s') % {'space': self.space.title}, level_subtitle
|
return _('In %(space)s') % {'space': self.space.title}, level_subtitle
|
||||||
|
|
||||||
subtitle_segments = chain((grid_cell, ), subtitle, (self.space.title, self.level.title))
|
subtitle_segments = chain((grid_square, ), subtitle, (self.space.title, self.level.title))
|
||||||
subtitle = ', '.join(str(title) for title in subtitle_segments if title)
|
subtitle = ', '.join(str(title) for title in subtitle_segments if title)
|
||||||
return title, subtitle
|
return title, subtitle
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue