maposmatic-dev
[Top][All Lists]
Advanced

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

[Maposmatic-dev] [PATCH 4/6] Add layout, stylesheet and papersize to Map


From: Thomas Petazzoni
Subject: [Maposmatic-dev] [PATCH 4/6] Add layout, stylesheet and papersize to MapRenderingForm
Date: Thu, 5 Aug 2010 00:54:25 +0200

The form used to ask the user for the various parameters of the map
needs to be extended with the new layout, stylesheet and papersize
parameters.

As OCitySMap doesn't yet implement the list of layouts, stylesheets
and paper sizes, so we use stub lists.

The ChoiceField choice lists are filled dynamically in the __init__
constructor instead of directly using the "choices" argument of the
ChoiceField constructor so that the result of a function call can be
used as the list of possible choices.

Signed-off-by: Thomas Petazzoni <address@hidden>
---
 www/maposmatic/forms.py |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/www/maposmatic/forms.py b/www/maposmatic/forms.py
index 88543fe..8b2a6d0 100644
--- a/www/maposmatic/forms.py
+++ b/www/maposmatic/forms.py
@@ -26,11 +26,21 @@
 
 from django import forms
 from django.utils.translation import ugettext_lazy as _
+from django.utils.safestring import mark_safe
 
 from ocitysmap.coords import BoundingBox as OCMBoundingBox
 from www.maposmatic import helpers, models, widgets
 import www.settings
 
+def get_layout_list():
+    return [("plain", "Sans index"), ("index", "With index"), ("booklet", 
"Booklet")]
+
+def get_stylesheet_list():
+    return [("default", "Mapnik par défaut"), ("nobuildings", "Mapnik no 
buildings")]
+
+def get_papersize_list():
+    return [("A4", 210, 297), ("A3", 297, 420), ("A2", 420, 594), ("US 
Letter", 216, 279)]
+
 class MapSearchForm(forms.Form):
     """
     The map search form, allowing search through the rendered maps.
@@ -55,6 +65,9 @@ class MapRenderingJobForm(forms.ModelForm):
 
     mode = forms.ChoiceField(choices=MODES, initial='admin',
                              widget=forms.RadioSelect)
+    layout = forms.ChoiceField(choices=(), widget=forms.RadioSelect)
+    stylesheet = forms.ChoiceField(choices=(), widget=forms.RadioSelect)
+    papersize = forms.ChoiceField(choices=(), widget=forms.RadioSelect)
     maptitle = forms.CharField(max_length=256, required=False)
     bbox = widgets.AreaField(label=_("Area"),
                              fields=(forms.FloatField(), forms.FloatField(),
@@ -65,6 +78,16 @@ class MapRenderingJobForm(forms.ModelForm):
     administrative_osmid = forms.IntegerField(widget=forms.HiddenInput,
                                               required=False)
 
+    def __init__(self, *args, **kwargs):
+        super(MapRenderingJobForm, self).__init__(*args, **kwargs)
+        self.fields['layout'].choices = get_layout_list()
+        self.fields['layout'].initial = 'index'
+        self.fields['stylesheet'].choices = get_stylesheet_list()
+        self.fields['stylesheet'].initial = 'default'
+        self.fields['papersize'].choices = \
+            [(p[0], mark_safe("%s <em style=\"color: grey;\">(%.1f &times; 
%.1f cm²)</em>" % \
+                                  (p[0], p[1] / 10., p[2] / 10.))) for p in 
get_papersize_list()]
+
     def clean(self):
         """Cleanup function for the map query form. Different checks are
         required depending on the selected mode (by admininstrative city, or by
-- 
1.7.0.4




reply via email to

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