To implement the /papersize/ service, we need to get the bbox associated to a given OSM id, so this commit adds a get_bbox_from_osm_id() helper.
In fact, the code for this helper already existed in check_osm_id(). So we've moved part of check_osm_id() into get_bbox_from_osm_id(), which is now used by check_osm_id(). Signed-off-by: Thomas Petazzoni <[email protected]> --- www/maposmatic/helpers.py | 25 +++++++++++++++---------- 1 files changed, 15 insertions(+), 10 deletions(-) diff --git a/www/maposmatic/helpers.py b/www/maposmatic/helpers.py index 060db7c..0f6fc04 100644 --- a/www/maposmatic/helpers.py +++ b/www/maposmatic/helpers.py @@ -31,11 +31,7 @@ from ocitysmap.coords import BoundingBox as OCMBoundingBox from www.maposmatic.models import MapRenderingJob import www.settings -def check_osm_id(osm_id, table='polygon'): - """Make sure that the supplied OSM Id is valid and can be accepted for - rendering (bounding box not too large, etc.). Raise an exception in - case of error.""" - +def get_bbox_from_osm_id(osm_id, table='polygon'): # If no GIS database is configured, bypass the city_exists check by # returning True. if not www.settings.has_gis_database(): @@ -63,14 +59,23 @@ def check_osm_id(osm_id, table='polygon'): # Check bbox size bbox = OCMBoundingBox.parse_wkt(envlp) - (metric_size_lat, metric_size_long) = bbox.spheric_sizes() - if metric_size_lat > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS or \ - metric_size_long > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS: - raise ValueError("Area too large") - finally: conn.close() + return bbox + +def check_osm_id(osm_id, table='polygon'): + """Make sure that the supplied OSM Id is valid and can be accepted for + rendering (bounding box not too large, etc.). Raise an exception in + case of error.""" + + bbox = get_bbox_from_osm_id(osm_id, table) + (metric_size_lat, metric_size_long) = bbox.spheric_sizes() + if metric_size_lat > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS or \ + metric_size_long > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS: + raise ValueError("Area too large") + + def rendering_already_exists_by_osmid(osmid): """Returns the ID of a rendering matching the given OpenStreetMap city ID from the last 24 hours, or None if no rendering can be found matching this -- 1.7.0.4
