UI error if buildgraph is not yet finished

This commit is contained in:
Laura Klünder 2016-12-21 11:55:04 +01:00
parent 1a86b826e6
commit d5a52bf9e3
4 changed files with 22 additions and 8 deletions

View file

@ -2,5 +2,9 @@ class NoRouteFound(Exception):
pass pass
class NotYetRoutable(Exception):
pass
class AlreadyThere(Exception): class AlreadyThere(Exception):
pass pass

View file

@ -12,7 +12,7 @@ from c3nav.mapdata.models import Elevator, Level
from c3nav.mapdata.models.geometry import LevelConnector from c3nav.mapdata.models.geometry import LevelConnector
from c3nav.mapdata.models.locations import AreaLocation, Location, LocationGroup, PointLocation from c3nav.mapdata.models.locations import AreaLocation, Location, LocationGroup, PointLocation
from c3nav.routing.connection import GraphConnection from c3nav.routing.connection import GraphConnection
from c3nav.routing.exceptions import AlreadyThere, NoRouteFound from c3nav.routing.exceptions import AlreadyThere, NoRouteFound, NotYetRoutable
from c3nav.routing.level import GraphLevel from c3nav.routing.level import GraphLevel
from c3nav.routing.point import GraphPoint from c3nav.routing.point import GraphPoint
from c3nav.routing.route import NoRoute, Route from c3nav.routing.route import NoRoute, Route
@ -252,12 +252,15 @@ class Graph:
points = np.array(points) points = np.array(points)
distances = np.array(distances) distances = np.array(distances)
return points, distances, ctypes return points, distances, ctypes
elif isinstance(location, AreaLocation): try:
points = self.levels[location.level.name].arealocation_points[location.name] if isinstance(location, AreaLocation):
return points, None, None points = self.levels[location.level.name].arealocation_points[location.name]
elif isinstance(location, LocationGroup): return points, None, None
points = set(np.hstack(tuple(self.get_location_points(area) for area in location.locationareas))) elif isinstance(location, LocationGroup):
return points, None, None points = set(np.hstack(tuple(self.get_location_points(area) for area in location.locationareas)))
return points, None, None
except KeyError:
raise NotYetRoutable
def _get_points_by_i(self, points): def _get_points_by_i(self, points):
return tuple(self.points[i] for i in points) return tuple(self.points[i] for i in points)

View file

@ -76,6 +76,11 @@
{% elif error == 'alreadythere' %} {% elif error == 'alreadythere' %}
<div class="alert alert-success"> <div class="alert alert-success">
<strong>{% trans 'Congratulations, you are already there!' %}</strong> <strong>{% trans 'Congratulations, you are already there!' %}</strong>
</div>
{% elif error == 'notyetroutable' %}
<div class="alert alert-danger">
<strong>{% trans 'One or both of your locations are not in the routing table yet.' %}</strong>
<p>{% trans 'Please try again in a few minutes.' %}</p>
</div> </div>
{% endif %} {% endif %}
{% if route %} {% if route %}

View file

@ -11,7 +11,7 @@ from c3nav.mapdata.permissions import get_excludables_includables
from c3nav.mapdata.render.compose import composer from c3nav.mapdata.render.compose import composer
from c3nav.mapdata.utils.cache import get_levels_cached from c3nav.mapdata.utils.cache import get_levels_cached
from c3nav.mapdata.utils.misc import get_dimensions from c3nav.mapdata.utils.misc import get_dimensions
from c3nav.routing.exceptions import AlreadyThere, NoRouteFound from c3nav.routing.exceptions import AlreadyThere, NoRouteFound, NotYetRoutable
from c3nav.routing.graph import Graph from c3nav.routing.graph import Graph
ctype_mapping = { ctype_mapping = {
@ -190,6 +190,8 @@ def main(request, location=None, origin=None, destination=None):
ctx.update({'error': 'noroutefound'}) ctx.update({'error': 'noroutefound'})
except AlreadyThere: except AlreadyThere:
ctx.update({'error': 'alreadythere'}) ctx.update({'error': 'alreadythere'})
except NotYetRoutable:
ctx.update({'error': 'notyetroutable'})
else: else:
ctx.update({'route': route}) ctx.update({'route': route})