From d5a52bf9e3b5986645b81ed9b2c9492788bdd80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Wed, 21 Dec 2016 11:55:04 +0100 Subject: [PATCH] UI error if buildgraph is not yet finished --- src/c3nav/routing/exceptions.py | 4 ++++ src/c3nav/routing/graph.py | 17 ++++++++++------- src/c3nav/site/templates/site/main.html | 5 +++++ src/c3nav/site/views.py | 4 +++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/c3nav/routing/exceptions.py b/src/c3nav/routing/exceptions.py index 30b23b65..f887754b 100644 --- a/src/c3nav/routing/exceptions.py +++ b/src/c3nav/routing/exceptions.py @@ -2,5 +2,9 @@ class NoRouteFound(Exception): pass +class NotYetRoutable(Exception): + pass + + class AlreadyThere(Exception): pass diff --git a/src/c3nav/routing/graph.py b/src/c3nav/routing/graph.py index 034b63bb..fe0ab05e 100644 --- a/src/c3nav/routing/graph.py +++ b/src/c3nav/routing/graph.py @@ -12,7 +12,7 @@ from c3nav.mapdata.models import Elevator, Level from c3nav.mapdata.models.geometry import LevelConnector from c3nav.mapdata.models.locations import AreaLocation, Location, LocationGroup, PointLocation 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.point import GraphPoint from c3nav.routing.route import NoRoute, Route @@ -252,12 +252,15 @@ class Graph: points = np.array(points) distances = np.array(distances) return points, distances, ctypes - elif isinstance(location, AreaLocation): - points = self.levels[location.level.name].arealocation_points[location.name] - return points, None, None - elif isinstance(location, LocationGroup): - points = set(np.hstack(tuple(self.get_location_points(area) for area in location.locationareas))) - return points, None, None + try: + if isinstance(location, AreaLocation): + points = self.levels[location.level.name].arealocation_points[location.name] + return points, None, None + elif isinstance(location, LocationGroup): + 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): return tuple(self.points[i] for i in points) diff --git a/src/c3nav/site/templates/site/main.html b/src/c3nav/site/templates/site/main.html index 24565ab0..69af835f 100644 --- a/src/c3nav/site/templates/site/main.html +++ b/src/c3nav/site/templates/site/main.html @@ -76,6 +76,11 @@ {% elif error == 'alreadythere' %}
{% trans 'Congratulations, you are already there!' %} +
+ {% elif error == 'notyetroutable' %} +
+ {% trans 'One or both of your locations are not in the routing table yet.' %} +

{% trans 'Please try again in a few minutes.' %}

{% endif %} {% if route %} diff --git a/src/c3nav/site/views.py b/src/c3nav/site/views.py index 802588c1..966d9f16 100644 --- a/src/c3nav/site/views.py +++ b/src/c3nav/site/views.py @@ -11,7 +11,7 @@ from c3nav.mapdata.permissions import get_excludables_includables from c3nav.mapdata.render.compose import composer from c3nav.mapdata.utils.cache import get_levels_cached 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 ctype_mapping = { @@ -190,6 +190,8 @@ def main(request, location=None, origin=None, destination=None): ctx.update({'error': 'noroutefound'}) except AlreadyThere: ctx.update({'error': 'alreadythere'}) + except NotYetRoutable: + ctx.update({'error': 'notyetroutable'}) else: ctx.update({'route': route})