maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH 02/13] Implement a skeleton /papersize/ service


From: Thomas Petazzoni
Subject: [Maposmatic-dev] [PATCH 02/13] Implement a skeleton /papersize/ service
Date: Thu, 5 Aug 2010 16:56:15 +0200

This service receives by post either a (osmid, layout) or a (bbox,
layout) and is responsible for asking OCitySMap what are the possible
paper size for the given geographic area. As OCitySMap doesn't
implement this feature yet, it is only a skeleton that returns a fixed
set of paper sizes.

Signed-off-by: Thomas Petazzoni <address@hidden>
---
 www/maposmatic/forms.py |   12 ++++++++++++
 www/maposmatic/views.py |   27 +++++++++++++++++++++++++++
 www/urls.py             |    2 ++
 3 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/www/maposmatic/forms.py b/www/maposmatic/forms.py
index 88543fe..adcca19 100644
--- a/www/maposmatic/forms.py
+++ b/www/maposmatic/forms.py
@@ -139,6 +139,18 @@ class MapRenderingJobForm(forms.ModelForm):
 
         return cleaned_data
 
+class MapPaperSizeForm(forms.Form):
+    """
+    The map paper size form, which is only used to analyze the
+    arguments of the POST request to /apis/papersize/
+    """
+    osmid = forms.IntegerField(required=False)
+    layout = forms.CharField(max_length=256)
+    lat_upper_left = forms.FloatField(required=False)
+    lon_upper_left = forms.FloatField(required=False)
+    lat_bottom_right = forms.FloatField(required=False)
+    lon_bottom_right = forms.FloatField(required=False)
+
 class MapRecreateForm(forms.Form):
     """
     The map recreate form, to reschedule an already processed job on the queue.
diff --git a/www/maposmatic/views.py b/www/maposmatic/views.py
index af6020d..3077932 100644
--- a/www/maposmatic/views.py
+++ b/www/maposmatic/views.py
@@ -32,6 +32,7 @@ from django.http import HttpResponseRedirect, 
HttpResponseBadRequest, HttpRespon
 from django.shortcuts import get_object_or_404, render_to_response
 from django.template import RequestContext
 from django.utils.translation import ugettext_lazy as _
+import ocitysmap.coords
 
 from www.maposmatic import helpers, forms, nominatim, models
 import www.settings
@@ -197,6 +198,32 @@ def query_nominatim(request, format, squery):
                             mimetype='text/json')
     # Support other formats here.
 
+def query_papersize(request):
+    """Papersize selection Ajax request handler"""
+    if request.method == 'POST':
+        f = forms.MapPaperSizeForm(request.POST)
+        if f.is_valid():
+            osmid = f.cleaned_data.get('osmid')
+            layout = f.cleaned_data.get('layout')
+            if osmid is not None:
+                bbox = helpers.get_bbox_from_osm_id(osmid)
+            else:
+                lat_upper_left = f.cleaned_data.get("lat_upper_left")
+                lon_upper_left = f.cleaned_data.get("lon_upper_left")
+                lat_bottom_right = f.cleaned_data.get("lat_bottom_right")
+                lon_bottom_right = f.cleaned_data.get("lon_bottom_right")
+                bbox = coords.BoundingBox(lat_upper_left, lon_upper_left,
+                                          lat_bottom_right, lon_bottom_right)
+
+            # Do something with bbox, layout
+            print bbox, layout
+
+            contents = [ "US Letter", "A3", "A2" ]
+
+            return HttpResponse(content=json_encode(contents),
+                                mimetype='text/json')
+    return HttpResponseBadRequest("ERROR: Invalid arguments")
+
 def recreate(request):
     if request.method == 'POST':
         form = forms.MapRecreateForm(request.POST)
diff --git a/www/urls.py b/www/urls.py
index 9dd5da2..b60783d 100644
--- a/www/urls.py
+++ b/www/urls.py
@@ -64,6 +64,8 @@ urlpatterns = patterns('',
 
     (r'^nominatim/([^/]*/)?(.*)$', maposmatic.views.query_nominatim),
 
+    (r'^papersize', maposmatic.views.query_papersize),
+
     # Internationalization
     (r'^i18n/', include('django.conf.urls.i18n')),
 
-- 
1.7.0.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]