satisfy linter and type checker in many places
This commit is contained in:
parent
9d21f8c933
commit
fb4da7c768
16 changed files with 38 additions and 26 deletions
|
@ -68,7 +68,7 @@ class APIRoot(GenericAPIView):
|
||||||
@cached_property
|
@cached_property
|
||||||
def urls(self):
|
def urls(self):
|
||||||
include_editor = can_access_editor(self.request)
|
include_editor = can_access_editor(self.request)
|
||||||
urls = OrderedDict()
|
urls: dict[str, dict[str, str] | str] = OrderedDict()
|
||||||
for urlpattern in router.urls:
|
for urlpattern in router.urls:
|
||||||
if not include_editor and inspect.getmodule(urlpattern.callback).__name__.startswith('c3nav.editor.'):
|
if not include_editor and inspect.getmodule(urlpattern.callback).__name__.startswith('c3nav.editor.'):
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -643,7 +643,7 @@ def graph_edit(request, level=None, space=None):
|
||||||
'obj_title': node.title
|
'obj_title': node.title
|
||||||
})
|
})
|
||||||
|
|
||||||
permissions = AccessPermission.get_for_request(request) | set([None])
|
permissions = AccessPermission.get_for_request(request) | {None}
|
||||||
edge_settings_form = GraphEdgeSettingsForm(instance=GraphEdge(), request=request, data=request.POST)
|
edge_settings_form = GraphEdgeSettingsForm(instance=GraphEdge(), request=request, data=request.POST)
|
||||||
graph_action_form = GraphEditorActionForm(request=request, allow_clicked_position=create_nodes,
|
graph_action_form = GraphEditorActionForm(request=request, allow_clicked_position=create_nodes,
|
||||||
data=request.POST)
|
data=request.POST)
|
||||||
|
|
|
@ -475,7 +475,7 @@ class BaseQueryWrapper(BaseWrapper):
|
||||||
if not segments:
|
if not segments:
|
||||||
# if the check is just 'pk' or the name or the name of the primary key, return the mathing object
|
# if the check is just 'pk' or the name or the name of the primary key, return the mathing object
|
||||||
if is_created_pk(filter_value):
|
if is_created_pk(filter_value):
|
||||||
return Q(pk__in=()), set([filter_value])
|
return Q(pk__in=()), {filter_value}
|
||||||
if filter_value is None or int(filter_value) in self._changeset.deleted_existing.get(model, ()):
|
if filter_value is None or int(filter_value) in self._changeset.deleted_existing.get(model, ()):
|
||||||
return Q(pk__in=()), set()
|
return Q(pk__in=()), set()
|
||||||
return q, set()
|
return q, set()
|
||||||
|
|
|
@ -213,7 +213,7 @@ class AccessPermission(models.Model):
|
||||||
access_restriction_ids = set(permissions.keys())
|
access_restriction_ids = set(permissions.keys())
|
||||||
|
|
||||||
expire_date = min((e for e in permissions.values() if e), default=timezone.now()+timedelta(seconds=120))
|
expire_date = min((e for e in permissions.values() if e), default=timezone.now()+timedelta(seconds=120))
|
||||||
cache.set(cache_key, access_restriction_ids, max(0, (expire_date-timezone.now()).total_seconds()))
|
cache.set(cache_key, access_restriction_ids, max(0.0, (expire_date-timezone.now()).total_seconds()))
|
||||||
return set(access_restriction_ids)
|
return set(access_restriction_ids)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -343,8 +343,10 @@ class AltitudeArea(LevelGeometryMixin, models.Model):
|
||||||
csgraph[area.tmpid, connected_tmpid] = True
|
csgraph[area.tmpid, connected_tmpid] = True
|
||||||
|
|
||||||
repeat = True
|
repeat = True
|
||||||
|
|
||||||
while repeat:
|
while repeat:
|
||||||
repeat = False
|
repeat = False
|
||||||
|
# noinspection PyTupleAssignmentBalance
|
||||||
distances, predecessors = dijkstra(csgraph, directed=False, return_predecessors=True, unweighted=True)
|
distances, predecessors = dijkstra(csgraph, directed=False, return_predecessors=True, unweighted=True)
|
||||||
np_areas_with_altitude = np.array(areas_with_altitude, dtype=np.uint32)
|
np_areas_with_altitude = np.array(areas_with_altitude, dtype=np.uint32)
|
||||||
relevant_distances = distances[np_areas_with_altitude[:, None], np_areas_with_altitude]
|
relevant_distances = distances[np_areas_with_altitude[:, None], np_areas_with_altitude]
|
||||||
|
|
|
@ -19,7 +19,7 @@ class AbstractOpenScadElem(ABC):
|
||||||
raise NotADirectoryError
|
raise NotADirectoryError
|
||||||
|
|
||||||
|
|
||||||
class AbstractOpenScadBlock(AbstractOpenScadElem, UserList):
|
class AbstractOpenScadBlock(AbstractOpenScadElem, UserList, ABC):
|
||||||
def render_children(self):
|
def render_children(self):
|
||||||
return '\n'.join(child.render() for child in self.data if child is not None)
|
return '\n'.join(child.render() for child in self.data if child is not None)
|
||||||
|
|
||||||
|
@ -290,6 +290,7 @@ class OpenSCADEngine(Base3DEngine):
|
||||||
main_building_block.append(obstacles_block)
|
main_building_block.append(obstacles_block)
|
||||||
|
|
||||||
if self.min_width and geoms.on_top_of_id is None:
|
if self.min_width and geoms.on_top_of_id is None:
|
||||||
|
# noinspection PyUnboundLocalVariable
|
||||||
main_building_block_inner.append(
|
main_building_block_inner.append(
|
||||||
self._add_polygon('min width',
|
self._add_polygon('min width',
|
||||||
self._satisfy_min_width(buildings).intersection(self.bbox).buffer(0),
|
self._satisfy_min_width(buildings).intersection(self.bbox).buffer(0),
|
||||||
|
|
|
@ -32,7 +32,7 @@ class MapRenderer:
|
||||||
|
|
||||||
def render(self, engine_cls, center=True):
|
def render(self, engine_cls, center=True):
|
||||||
# add no access restriction to “unlocked“ access restrictions so lookup gets easier
|
# add no access restriction to “unlocked“ access restrictions so lookup gets easier
|
||||||
access_permissions = self.access_permissions | set([None])
|
access_permissions = self.access_permissions | {None}
|
||||||
|
|
||||||
bbox = prepared.prep(self.bbox)
|
bbox = prepared.prep(self.bbox)
|
||||||
|
|
||||||
|
|
4
src/c3nav/mapdata/utils/cache/indexed.py
vendored
4
src/c3nav/mapdata/utils/cache/indexed.py
vendored
|
@ -75,7 +75,7 @@ class GeometryIndexed:
|
||||||
self._write_metadata(f)
|
self._write_metadata(f)
|
||||||
f.write(self.data.tobytes('C'))
|
f.write(self.data.tobytes('C'))
|
||||||
|
|
||||||
def _write_metadata(cls, f):
|
def _write_metadata(self, f):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _get_geometry_bounds(self, geometry):
|
def _get_geometry_bounds(self, geometry):
|
||||||
|
@ -180,7 +180,9 @@ class GeometryIndexed:
|
||||||
int(math.ceil((maxx-minx)/self.resolution))), dtype=np.uint8)
|
int(math.ceil((maxx-minx)/self.resolution))), dtype=np.uint8)
|
||||||
|
|
||||||
if self.data.size:
|
if self.data.size:
|
||||||
|
# noinspection PyArgumentList
|
||||||
minval = min(self.data.min(), 0)
|
minval = min(self.data.min(), 0)
|
||||||
|
# noinspection PyArgumentList
|
||||||
maxval = max(self.data.max(), minval+0.01)
|
maxval = max(self.data.max(), minval+0.01)
|
||||||
visible_data = ((self.data.astype(float)-minval)*255/(maxval-minval)).clip(0, 255).astype(np.uint8)
|
visible_data = ((self.data.astype(float)-minval)*255/(maxval-minval)).clip(0, 255).astype(np.uint8)
|
||||||
image_data[self.y:self.y+height, self.x:self.x+width] = visible_data
|
image_data[self.y:self.y+height, self.x:self.x+width] = visible_data
|
||||||
|
|
21
src/c3nav/mapdata/utils/cache/stats.py
vendored
21
src/c3nav/mapdata/utils/cache/stats.py
vendored
|
@ -59,16 +59,17 @@ fake_request = FakeRequest()
|
||||||
|
|
||||||
def convert_stats(stats):
|
def convert_stats(stats):
|
||||||
stats = [(name.split('__')[1:], value) for name, value in stats['data'].items()]
|
stats = [(name.split('__')[1:], value) for name, value in stats['data'].items()]
|
||||||
result = {}
|
result = {
|
||||||
result['locate'] = convert_locate(_filter_stats('locate', stats))
|
'locate': convert_locate(_filter_stats('locate', stats)),
|
||||||
result['location_retrieve'] = convert_location(_filter_stats('location_retrieve', stats))
|
'location_retrieve': convert_location(_filter_stats('location_retrieve', stats)),
|
||||||
result['location_geometry'] = convert_location(_filter_stats('location_geometry', stats))
|
'location_geometry': convert_location(_filter_stats('location_geometry', stats)),
|
||||||
result['route_origin'] = convert_location(
|
'route_origin': convert_location(
|
||||||
(['pk']+name, value) for name, value in _filter_stats('route_origin_', stats, startswith=True)
|
(['pk'] + name, value) for name, value in _filter_stats('route_origin_', stats, startswith=True)
|
||||||
)
|
),
|
||||||
result['route_destination'] = convert_location(
|
'route_destination': convert_location(
|
||||||
(['pk'] + name, value) for name, value in _filter_stats('route_destination_', stats, startswith=True)
|
(['pk'] + name, value) for name, value in _filter_stats('route_destination_', stats, startswith=True)
|
||||||
)
|
),
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ def triangulate_rings(rings, holes=None):
|
||||||
|
|
||||||
# remove triangles with no area
|
# remove triangles with no area
|
||||||
facets = np.dstack((np.zeros(mesh_elements.shape), mesh_points[mesh_elements]))
|
facets = np.dstack((np.zeros(mesh_elements.shape), mesh_points[mesh_elements]))
|
||||||
|
# noinspection PyArgumentList
|
||||||
ok_index = np.cross(facets[:, 1] - facets[:, 0], facets[:, 2] - facets[:, 1]).max(axis=1) != 0
|
ok_index = np.cross(facets[:, 1] - facets[:, 0], facets[:, 2] - facets[:, 1]).max(axis=1) != 0
|
||||||
mesh_elements = mesh_elements[ok_index]
|
mesh_elements = mesh_elements[ok_index]
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ class MplPolygonPath(MplPathProxy):
|
||||||
def shapely_to_mpl(geometry):
|
def shapely_to_mpl(geometry):
|
||||||
"""
|
"""
|
||||||
convert a shapely Polygon or Multipolygon to a matplotlib Path
|
convert a shapely Polygon or Multipolygon to a matplotlib Path
|
||||||
:param polygon: shapely Polygon or Multipolygon
|
:param geometry: shapely Polygon or Multipolygon
|
||||||
:return: MplPathProxy
|
:return: MplPathProxy
|
||||||
"""
|
"""
|
||||||
if isinstance(geometry, Polygon):
|
if isinstance(geometry, Polygon):
|
||||||
|
|
|
@ -81,7 +81,7 @@ def tile(request, level, zoom, x, y, access_permissions=None):
|
||||||
access_permissions = parse_tile_access_cookie(cookie, settings.SECRET_TILE_KEY)
|
access_permissions = parse_tile_access_cookie(cookie, settings.SECRET_TILE_KEY)
|
||||||
access_permissions &= set(level_data.restrictions[minx:maxx, miny:maxy])
|
access_permissions &= set(level_data.restrictions[minx:maxx, miny:maxy])
|
||||||
else:
|
else:
|
||||||
access_permissions = set(int(i) for i in access_permissions.split('-')) - set([0])
|
access_permissions = set(int(i) for i in access_permissions.split('-')) - {0}
|
||||||
|
|
||||||
# build cache keys
|
# build cache keys
|
||||||
last_update = level_data.history.last_update(minx, miny, maxx, maxy)
|
last_update = level_data.history.last_update(minx, miny, maxx, maxy)
|
||||||
|
|
|
@ -108,7 +108,7 @@ class LocatorStations:
|
||||||
station = self.stations[station_id]
|
station = self.stations[station_id]
|
||||||
station.frequencies.add(frequency)
|
station.frequencies.add(frequency)
|
||||||
elif create:
|
elif create:
|
||||||
station = LocatorStation(bssid, ssid, set((frequency, )))
|
station = LocatorStation(bssid, ssid, {frequency})
|
||||||
station_id = len(self.stations)
|
station_id = len(self.stations)
|
||||||
self.stations_lookup[(bssid, None)] = station_id
|
self.stations_lookup[(bssid, None)] = station_id
|
||||||
self.stations.append(station)
|
self.stations.append(station)
|
||||||
|
|
|
@ -95,6 +95,7 @@ class Route:
|
||||||
description = item.waytype.description
|
description = item.waytype.description
|
||||||
if item.waytype.up_separate and item.edge.rise > 0:
|
if item.waytype.up_separate and item.edge.rise > 0:
|
||||||
description = item.waytype.description_up
|
description = item.waytype.description_up
|
||||||
|
# noinspection PyComparisonWithNone
|
||||||
if (item.waytype.level_change_description != False and last_primary_level and
|
if (item.waytype.level_change_description != False and last_primary_level and
|
||||||
((item.last_item and item.level != item.last_item.level) or
|
((item.last_item and item.level != item.last_item.level) or
|
||||||
item.level.on_top_of_id)): # != False because it's lazy
|
item.level.on_top_of_id)): # != False because it's lazy
|
||||||
|
@ -124,8 +125,9 @@ class Route:
|
||||||
description = current_space.leave_descriptions.get(next_space.pk, None)
|
description = current_space.leave_descriptions.get(next_space.pk, None)
|
||||||
if description is None:
|
if description is None:
|
||||||
description = item.space.enter_description
|
description = item.space.enter_description
|
||||||
|
# noinspection PyComparisonWithNone
|
||||||
if description == None: # could be a lazy None
|
if description == None: # could be a lazy None
|
||||||
description = _('Go to %(space_title)s.') % {'space_title': item.space.title}
|
description = _('Go to %(space_title)s.') % {'space_title': item.space.title}
|
||||||
|
|
||||||
item.descriptions.append(('more_vert', description))
|
item.descriptions.append(('more_vert', description))
|
||||||
|
|
||||||
|
@ -140,7 +142,9 @@ class Route:
|
||||||
if item.edge:
|
if item.edge:
|
||||||
remaining_distance += item.edge.distance
|
remaining_distance += item.edge.distance
|
||||||
if remaining_distance:
|
if remaining_distance:
|
||||||
item.descriptions.append(('more_vert', _('%d m remaining to your destination.') % max(remaining_distance, 1)))
|
item.descriptions.append(
|
||||||
|
('more_vert', _('%d m remaining to your destination.') % max(remaining_distance, 1))
|
||||||
|
)
|
||||||
|
|
||||||
items[-1].descriptions.append(('done', _('You have reached your destination.')))
|
items[-1].descriptions.append(('done', _('You have reached your destination.')))
|
||||||
|
|
||||||
|
@ -240,6 +244,5 @@ class RouteItem:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NoRoute:
|
class NoRoute:
|
||||||
distance = np.inf
|
distance = np.inf
|
||||||
|
|
|
@ -38,6 +38,7 @@ class AtPositionConverter:
|
||||||
|
|
||||||
|
|
||||||
class ConditionalConverter:
|
class ConditionalConverter:
|
||||||
|
# noinspection PyMethodOverriding
|
||||||
def __init_subclass__(cls, /, name):
|
def __init_subclass__(cls, /, name):
|
||||||
cls.path = '%s/' % name
|
cls.path = '%s/' % name
|
||||||
cls.regex = '(%s/)?' % name
|
cls.regex = '(%s/)?' % name
|
||||||
|
|
|
@ -36,15 +36,16 @@ class ReportUpdateForm(ModelForm):
|
||||||
('false', _('closed')),
|
('false', _('closed')),
|
||||||
)
|
)
|
||||||
|
|
||||||
def save(self):
|
def save(self, commit=True):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
super().save()
|
super().save(commit=commit)
|
||||||
report = self.instance.report
|
report = self.instance.report
|
||||||
if self.instance.open is not None:
|
if self.instance.open is not None:
|
||||||
report.open = self.instance.open
|
report.open = self.instance.open
|
||||||
if self.instance.assigned_to:
|
if self.instance.assigned_to:
|
||||||
report.assigned_to = self.instance.assigned_to
|
report.assigned_to = self.instance.assigned_to
|
||||||
report.save()
|
if commit:
|
||||||
|
report.save()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ReportUpdate
|
model = ReportUpdate
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue