[Top][All Lists]
[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
- [Maposmatic-dev] [PATCH 01/13] Extend MapRenderingJob with stylesheet, papersize and layout, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 03/13] Add a get_bbox_from_osm_id() helper, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 11/13] Fix language selector to work on Chrome, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 07/13] Fix maptitle handling in MapRenderingJobForm, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 04/13] Add layout, stylesheet and papersize to MapRenderingForm, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 13/13] Improve the slippy map notifier usage to show when the area is too big, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 12/13] Move Ajax service to the /apis/ directory, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 10/13] Update licence years, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 02/13] Implement a skeleton /papersize/ service,
Thomas Petazzoni <=
- [Maposmatic-dev] [PATCH 06/13] Implement a brand new wizard for map creation, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 08/13] Add link and form to search maps on the front page, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 09/13] Add licence boilerplate in map_rendering_form.css, Thomas Petazzoni, 2010/08/05
- [Maposmatic-dev] [PATCH 05/13] Upgrade jquery to 1.4.2, Thomas Petazzoni, 2010/08/05