add some more type hinting
This commit is contained in:
parent
39a6104d7a
commit
2da1bf0bd5
2 changed files with 5 additions and 6 deletions
|
@ -15,9 +15,9 @@ validate_bssid_lines = RegexValidator(regex=r'^([0-9a-f]{2}(:[0-9a-f]{2}){5}(\r?
|
||||||
message=_('please enter a newline seperated lowercase list of BSSIDs'))
|
message=_('please enter a newline seperated lowercase list of BSSIDs'))
|
||||||
|
|
||||||
|
|
||||||
def validate_geometry(geometry):
|
def validate_geometry(geometry: BaseGeometry):
|
||||||
if not isinstance(geometry, BaseGeometry):
|
if not isinstance(geometry, BaseGeometry):
|
||||||
raise ValidationError('GeometryField expexted a Shapely BaseGeometry child-class.')
|
raise ValidationError('GeometryField expected a Shapely BaseGeometry child-class.')
|
||||||
|
|
||||||
if not geometry.is_valid:
|
if not geometry.is_valid:
|
||||||
raise ValidationError('Invalid geometry: %s' % validation.explain_validity(geometry))
|
raise ValidationError('Invalid geometry: %s' % validation.explain_validity(geometry))
|
||||||
|
|
|
@ -2,7 +2,6 @@ from collections import OrderedDict
|
||||||
|
|
||||||
from shapely.geometry import Point, mapping
|
from shapely.geometry import Point, mapping
|
||||||
|
|
||||||
from c3nav.mapdata.fields import GeometryField
|
|
||||||
from c3nav.mapdata.models.base import EditorFormMixin
|
from c3nav.mapdata.models.base import EditorFormMixin
|
||||||
from c3nav.mapdata.utils.json import format_geojson
|
from c3nav.mapdata.utils.json import format_geojson
|
||||||
|
|
||||||
|
@ -18,13 +17,13 @@ class GeometryMixin(EditorFormMixin):
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def get_geojson_properties(self):
|
def get_geojson_properties(self) -> dict:
|
||||||
return OrderedDict((
|
return OrderedDict((
|
||||||
('type', self.__class__.__name__.lower()),
|
('type', self.__class__.__name__.lower()),
|
||||||
('id', self.id),
|
('id', self.id),
|
||||||
))
|
))
|
||||||
|
|
||||||
def to_geojson(self):
|
def to_geojson(self) -> dict:
|
||||||
return OrderedDict((
|
return OrderedDict((
|
||||||
('type', 'Feature'),
|
('type', 'Feature'),
|
||||||
('properties', self.get_geojson_properties()),
|
('properties', self.get_geojson_properties()),
|
||||||
|
@ -34,5 +33,5 @@ class GeometryMixin(EditorFormMixin):
|
||||||
def get_shadow_geojson(self):
|
def get_shadow_geojson(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def contains(self, x, y):
|
def contains(self, x, y) -> bool:
|
||||||
return self.geometry.contains(Point(x, y))
|
return self.geometry.contains(Point(x, y))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue