maposmatic-dev
[Top][All Lists]
Advanced

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

[Maposmatic-dev] [PATCH 04/13] Add layout, stylesheet and papersize to M


From: Thomas Petazzoni
Subject: [Maposmatic-dev] [PATCH 04/13] Add layout, stylesheet and papersize to MapRenderingForm
Date: Thu, 5 Aug 2010 16:56:17 +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 +++++++++++++++++++++++
 www/media/style.css     |    4 ++++
 2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/www/maposmatic/forms.py b/www/maposmatic/forms.py
index adcca19..8044db2 100644
--- a/www/maposmatic/forms.py
+++ b/www/maposmatic/forms.py
@@ -25,12 +25,22 @@
 # Forms for MapOSMatic
 
 from django import forms
+from django.utils.safestring import mark_safe
 from django.utils.translation import ugettext_lazy as _
 
 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 class=\"papersize\">(%.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
diff --git a/www/media/style.css b/www/media/style.css
index c1732ea..ce960d0 100644
--- a/www/media/style.css
+++ b/www/media/style.css
@@ -369,6 +369,10 @@ div.pagination {
   font-size: 13pt;
 }
 
+#mainfrm em.papersize {
+  font-style: italic;
+}
+
 /* Suggest */
 #suggest {
   margin: 0;
-- 
1.7.0.4




reply via email to

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