summaryrefslogtreecommitdiff
path: root/chimere/widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/widgets.py')
-rw-r--r--chimere/widgets.py340
1 files changed, 195 insertions, 145 deletions
diff --git a/chimere/widgets.py b/chimere/widgets.py
index ea3fe16..f8bb11b 100644
--- a/chimere/widgets.py
+++ b/chimere/widgets.py
@@ -20,7 +20,6 @@
"""
Extra widgets and fields
"""
-from django import conf
from django import forms
from django.conf import settings
from django.contrib.gis.db import models
@@ -36,6 +35,7 @@ from django.template.loader import render_to_string
import re
+
def getMapJS(area_name=''):
'''Variable initialization for drawing the map
'''
@@ -44,10 +44,10 @@ def getMapJS(area_name=''):
u";\n" % settings.CHIMERE_EPSG_DISPLAY_PROJECTION
js += u"OpenLayers.ImgPath = '%schimere/img/';\n" % settings.STATIC_URL
js += u"var epsg_projection = new OpenLayers.Projection('EPSG:%d');\n" % \
- settings.CHIMERE_EPSG_PROJECTION
+ settings.CHIMERE_EPSG_PROJECTION
js += u"var centerLonLat = new OpenLayers.LonLat(%f,"\
u"%f).transform(epsg_display_projection, epsg_projection);\n" % \
- settings.CHIMERE_DEFAULT_CENTER
+ settings.CHIMERE_DEFAULT_CENTER
js += u"var media_path = '%s';\n" % settings.MEDIA_URL
js += u"var static_path = '%s';\n" % settings.STATIC_URL
js += u"var map_layer = %s;\n" % settings.CHIMERE_DEFAULT_MAP_LAYER
@@ -59,6 +59,7 @@ def getMapJS(area_name=''):
u"%s// !--></script>\n" % js
return js
+
def get_map_layers(area_name=''):
from chimere.models import Area
area = None
@@ -74,8 +75,9 @@ def get_map_layers(area_name=''):
pass
map_layers, default = [], None
if area and area.layers.count():
- map_layers = [[layer.name, layer.layer_code, False]
- for layer in area.layers.order_by('arealayers__order').all()]
+ map_layers = [
+ [layer.name, layer.layer_code, False]
+ for layer in area.layers.order_by('arealayers__order').all()]
def_layer = area.layers.filter(arealayers__default=True)
if def_layer.count():
def_layer = def_layer.all()[0]
@@ -93,28 +95,33 @@ def get_map_layers(area_name=''):
True)]
return map_layers, default
+
class ChosenSelectWidget(forms.Select):
"""
Chosen select widget.
"""
class Media:
- js = ["%schosen/chosen/chosen.jquery.min.js" % settings.STATIC_URL,]
- css = {'all':
- ["%schosen/chosen/chosen.css" % settings.STATIC_URL,]
- }
+ js = ["%schosen/chosen/chosen.jquery.min.js" % settings.STATIC_URL]
+ css = {
+ 'all':
+ ["%schosen/chosen/chosen.css" % settings.STATIC_URL]
+ }
+
def render(self, *args, **kwargs):
if 'attrs' not in kwargs:
kwargs['attrs'] = {}
kwargs['attrs'].update({'class': 'chzn-select'})
rendered = super(ChosenSelectWidget, self).render(*args, **kwargs)
rendered += u"\n<script type='text/javascript'>\n"\
- u" $('#%s').chosen();\n"\
- u"</script>\n" % kwargs['attrs']['id']
+ u" $('#%s').chosen();\n"\
+ u"</script>\n" % kwargs['attrs']['id']
return mark_safe(rendered)
"""
JQuery UI button select widget.
"""
+
+
class ButtonRadioInput(RadioInput):
def render(self, name=None, value=None, attrs=None, choices=()):
name = name or self.name
@@ -127,13 +134,18 @@ class ButtonRadioInput(RadioInput):
choice_label = conditional_escape(force_unicode(self.choice_label))
return mark_safe(u'%s <label%s>%s</label>' % (self.tag(), label_for,
choice_label))
+
+
class ButtonRadioFieldRenderer(RadioFieldRenderer):
def __iter__(self):
for i, choice in enumerate(self.choices):
yield ButtonRadioInput(self.name, self.value, self.attrs.copy(),
choice, i)
+
def render(self):
return mark_safe(u'\n'.join([force_unicode(w) for w in self]))
+
+
class ButtonSelectWidget(forms.RadioSelect):
def __init__(self, *args, **kwargs):
self.renderer = ButtonRadioFieldRenderer
@@ -143,16 +155,18 @@ class ButtonSelectWidget(forms.RadioSelect):
rendered = "<div id='%s'>\n" % kwargs['attrs']['id']
rendered += super(ButtonSelectWidget, self).render(*args, **kwargs)
rendered += u"\n<script type='text/javascript'>\n"\
- u" $('#%s').buttonset();\n"\
- u"</script>\n</div>\n" % kwargs['attrs']['id']
+ u" $('#%s').buttonset();\n"\
+ u"</script>\n</div>\n" % kwargs['attrs']['id']
return mark_safe(rendered)
+
class ImporterChoicesWidget(forms.Select):
'''
Importer select widget.
'''
class Media:
- js = ["%schimere/js/importer_interface.js" % settings.STATIC_URL,]
+ js = ["%schimere/js/importer_interface.js" % settings.STATIC_URL]
+
class TextareaWidgetBase(forms.Textarea):
"""
@@ -169,6 +183,7 @@ class TextareaWidgetBase(forms.Textarea):
rendered = super(TextareaWidgetBase, self).render(*args, **kwargs)
return mark_safe(rendered)
+
class FullTextareaWidget(TextareaWidgetBase):
"""
Manage the edition of a text using TinyMCE
@@ -196,18 +211,21 @@ tinyMCE.init({
"""
return mark_safe(rendered)
+
class TextareaWidget(TextareaWidgetBase):
"""
Manage the edition of a text using TinyMCE
"""
class Media:
js = ["%stiny_mce.js" % settings.TINYMCE_URL,
- "%schimere/js/textareas.js" % settings.STATIC_URL,]
+ "%schimere/js/textareas.js" % settings.STATIC_URL]
+
class TextareaAdminWidget(TextareaWidgetBase):
class Media:
js = ["%stiny_mce.js" % settings.TINYMCE_URL,
- "%schimere/js/textareas_admin.js" % settings.STATIC_URL,]
+ "%schimere/js/textareas_admin.js" % settings.STATIC_URL]
+
class DatePickerWidget(forms.TextInput):
"""
@@ -218,18 +236,25 @@ class DatePickerWidget(forms.TextInput):
def render(self, *args, **kwargs):
rendered = super(DatePickerWidget, self).render(*args, **kwargs)
rendered += u"\n<script type='text/javascript'>\n"\
- u" $(function() {$('#%s').datepicker({ dateFormat: 'yy-mm-dd' });});\n"\
- u"</script>\n" % kwargs['attrs']['id']
+ u" $(function() {$('#%s').datepicker("\
+ u"{ dateFormat: 'yy-mm-dd' });});\n"\
+ u"</script>\n" % kwargs['attrs']['id']
return mark_safe(rendered)
+
class NominatimWidget(forms.TextInput):
class Media:
js = ["%schimere/js/nominatim-widget.js" % settings.STATIC_URL]
+
def render(self, name, value, attrs=None, area_name=''):
+ dct = {'id': name, 'nominatim_url': settings.NOMINATIM_URL,
+ 'label': _(u"Street, City, Country")}
+
tpl = u"""
<input type='hidden' name='nominatim_%(id)s_lat' id='nominatim_%(id)s_lat'/>
<input type='hidden' name='nominatim_%(id)s_lon' id='nominatim_%(id)s_lon'/>
-<input type='text' class='nominatim-widget' name='nominatim_%(id)s' id='nominatim_%(id)s' value=""/>
+<input type='text' class='nominatim-widget' name='nominatim_%(id)s'
+ id='nominatim_%(id)s' value=""/>
<label class='nominatim-label' id='nominatim_%(id)s_label'>&nbsp;</label>
<script type='text/javascript'>
var default_nominatim_lbl = "%(label)s";
@@ -239,21 +264,21 @@ $("#nominatim_%(id)s").click(function(){
$("#nominatim_%(id)s").val('');
});
</script>
-""" % {'id':name, 'nominatim_url':settings.NOMINATIM_URL,
- 'label':_(u"Street, City, Country")}
+""" % dct
return mark_safe(tpl)
+
class PointChooserWidget(forms.TextInput):
"""
Manage the edition of point on a map
"""
class Media:
css = {
- "all": settings.MAP_CSS_URLS + \
- ["%schimere/css/forms.css" % settings.STATIC_URL,]
+ "all": settings.MAP_CSS_URLS +
+ ["%schimere/css/forms.css" % settings.STATIC_URL]
}
js = settings.MAP_JS_URLS + list(settings.JQUERY_JS_URLS) + \
- ["%schimere/js/jquery.chimere.js" % settings.STATIC_URL]
+ ["%schimere/js/jquery.chimere.js" % settings.STATIC_URL]
def render(self, name, value, attrs=None, area_name='', initialized=True):
'''
@@ -275,7 +300,7 @@ class PointChooserWidget(forms.TextInput):
value = None
map_layers, default_area = get_map_layers(area_name)
map_layers = [js for n, js, default in map_layers]
- #TODO: manage area
+ # TODO: manage area
return mark_safe(
render_to_string('chimere/blocks/live_coordinates.html',
{'lat': _("Latitude"),
@@ -286,8 +311,9 @@ class PointChooserWidget(forms.TextInput):
'val': val,
'initialized': initialized,
'isvalue': bool(value),
- 'default_area': "true" if default_area else "false",
- }) % \
+ 'default_area': "true" if default_area
+ else "false",
+ }) %
(settings.STATIC_URL,
settings.CHIMERE_EPSG_DISPLAY_PROJECTION,
settings.CHIMERE_EPSG_PROJECTION,
@@ -296,7 +322,8 @@ class PointChooserWidget(forms.TextInput):
settings.STATIC_URL,
", ".join(map_layers)
)
- )
+ )
+
class HiddenPointChooserWidget(PointChooserWidget):
"""
@@ -307,13 +334,14 @@ class HiddenPointChooserWidget(PointChooserWidget):
kwargs['initialized'] = False
return super(HiddenPointChooserWidget, self).render(*args, **kwargs)
+
class PointField(models.PointField):
'''
Set the widget for the form field
'''
def __init__(self, *args, **kwargs):
self.widget = kwargs.pop('widget') if 'widget' in kwargs \
- else PointChooserWidget
+ else PointChooserWidget
return super(PointField, self).__init__(*args, **kwargs)
def formfield(self, **keys):
@@ -323,21 +351,23 @@ class PointField(models.PointField):
def clean(self, value, instance=None):
if len(value) != 2 and self.required:
- raise ValidationError(_("Invalid point"))
+ raise forms.ValidationError(_("Invalid point"))
return value
+
class RouteChooserWidget(forms.TextInput):
"""
Manage the edition of route on a map
"""
class Media:
- css = {"all": settings.MAP_CSS_URLS + \
- ["%schimere/css/forms.css" % settings.STATIC_URL,]
+ css = {
+ "all": settings.MAP_CSS_URLS +
+ ["%schimere/css/forms.css" % settings.STATIC_URL]
}
js = settings.MAP_JS_URLS + list(settings.JQUERY_JS_URLS) + \
- ["%schimere/js/jquery.chimere.js" % settings.STATIC_URL,
- "%schimere/js/edit_route_map.js" % settings.STATIC_URL,
- "%schimere/js/base.js" % settings.STATIC_URL,]
+ ["%schimere/js/jquery.chimere.js" % settings.STATIC_URL,
+ "%schimere/js/edit_route_map.js" % settings.STATIC_URL,
+ "%schimere/js/base.js" % settings.STATIC_URL]
def render(self, name, value, attrs=None, area_name='', routefile_id=None):
'''
@@ -352,9 +382,13 @@ class RouteChooserWidget(forms.TextInput):
var extra_url = "%s";
OpenLayers.ImgPath = '%schimere/img/';
- var EPSG_DISPLAY_PROJECTION = epsg_display_projection = new OpenLayers.Projection('EPSG:%s');
- var EPSG_PROJECTION = epsg_projection = new OpenLayers.Projection('EPSG:%s');
- var CENTER_LONLAT = centerLonLat = new OpenLayers.LonLat%s.transform(epsg_display_projection, epsg_projection);
+ epsg_display_projection = new OpenLayers.Projection('EPSG:%s');
+ var EPSG_DISPLAY_PROJECTION = epsg_display_projection;
+ epsg_projection = new OpenLayers.Projection('EPSG:%s');
+ var EPSG_PROJECTION = epsg_projection;
+ centerLonLat = new OpenLayers.LonLat%s.transform(
+ epsg_display_projection, epsg_projection);
+ var CENTER_LONLAT = centerLonLat;
var DEFAULT_ZOOM = %s;
var chimere_init_options = {};
chimere_init_options["map_layers"] = [%s];
@@ -363,49 +397,53 @@ class RouteChooserWidget(forms.TextInput):
chimere_init_options['edition_type_is_route'] = true;
chimere_init_options["checked_categories"] = [];
""" % (reverse("chimere:index"), settings.STATIC_URL,
- settings.CHIMERE_EPSG_DISPLAY_PROJECTION,
- settings.CHIMERE_EPSG_PROJECTION, settings.CHIMERE_DEFAULT_CENTER,
- settings.CHIMERE_DEFAULT_ZOOM, ", ".join(map_layers))
+ settings.CHIMERE_EPSG_DISPLAY_PROJECTION,
+ settings.CHIMERE_EPSG_PROJECTION,
+ settings.CHIMERE_DEFAULT_CENTER,
+ settings.CHIMERE_DEFAULT_ZOOM, ", ".join(map_layers))
if default_area:
js += "chimere_init_options['selected_map_layer'] = %d;\n" % \
default_area
tpl = u"<script type='text/javascript'><!--\n"\
u"%s// !--></script>\n" % js
- #TODO: manage area
+ # TODO: manage area
help_create = ''
if not value:
help_create = u"<h3>%s</h3>\n"\
+ u"<p>%s</p>\n"\
+ u"<p>%s</p>\n"\
+ u"<p>%s</p>\n"\
+ u"<p>%s</p>\n"\
+ u"<p>%s</p>\n" % (
+ _(u"Creation mode"),
+ _(u"To start drawing the route click on the toggle "
+ u"button: \"Draw\"."),
+ _(u"Then click on the map to begin the drawing."),
+ _(u"You can add points by clicking again."),
+ _(u"To finish the drawing double click. When the drawing "
+ u"is finished you can edit it."),
+ _(u"While creating to undo a drawing click again on the "
+ u"toggle button \"Stop drawing\"."))
+ help_modify = u"<h3>%s</h3>\n"\
u"<p>%s</p>\n"\
u"<p>%s</p>\n"\
- u"<p>%s</p>\n"\
- u"<p>%s</p>\n"\
- u"<p>%s</p>\n" % (_(u"Creation mode"),
- _(u"To start drawing the route click on the toggle button: "\
- u"\"Draw\"."),
- _(u"Then click on the map to begin the drawing."),
- _(u"You can add points by clicking again."),
- _(u"To finish the drawing double click. When the drawing is "\
- u"finished you can edit it."),
- _(u"While creating to undo a drawing click again on the toggle "\
- u"button \"Stop drawing\"."))
- help_modify = u"<h3>%s</h3>\n"\
- u"<p>%s</p>\n"\
- u"<p>%s</p>\n"\
- u"<p>%s</p>\n" % (_(u"Modification mode"),
- _(u"To move a point click on it and drag it to the desired position."),
- _(u"To delete a point move the mouse cursor over it and press the "\
- u"\"d\" or \"Del\" key."),
- _(u"To add a point click in the middle of a segment and drag the new "\
- u"point to the desired position"))
+ u"<p>%s</p>\n" % (
+ _(u"Modification mode"),
+ _(u"To move a point click on it and drag it to the desired "
+ u"position."),
+ _(u"To delete a point move the mouse cursor over it and press "
+ u"the \"d\" or \"Del\" key."),
+ _(u"To add a point click in the middle of a segment and drag "
+ u"the new point to the desired position"))
if not value:
# upload a file
tpl += u"<script type='text/javascript'><!--\n"\
u" var error_msg = \"%s\";"\
- u"// --></script>" % (
- _(u"Give a name and set category before uploading a file."))
+ u"// --></script>" % \
+ _(u"Give a name and set category before uploading a file.")
tpl += u'<div id="upload"><a href="#" class="upload-button" '\
- u'onclick="uploadFile(error_msg);return false;">%s</a></div>' % (
- _(u"Upload a route file (GPX or KML)"))
+ u'onclick="uploadFile(error_msg);return false;">%s</a></div>' \
+ % (_(u"Upload a route file (GPX or KML)"))
tpl += u"\n<p id='draw-or'>%s</p>\n" % _(u"or")
tpl += u"<div id='draw-label'><div id='draw-toggle-off' "\
u"onclick='toggleDraw();'>\n"\
@@ -416,25 +454,26 @@ class RouteChooserWidget(forms.TextInput):
if value:
style = " style='display:block'"
tpl += u"\n<div class='help-route' id='help-route-modify'%s>%s</div>"\
- u"\n<hr class='spacer'/>\n"\
- u"<input type='hidden' name='%s' id='id_%s' value=\"%s\"/>\n"\
- u"<input type='hidden' name='associated_file_id' "\
- u"id='id_associated_file_id' value=\"%s\"/>\n" % (
- style, help_modify, name, name, value, routefile_id)
+ u"\n<hr class='spacer'/>\n"\
+ u"<input type='hidden' name='%s' id='id_%s' value=\"%s\"/>\n"\
+ u"<input type='hidden' name='associated_file_id' "\
+ u"id='id_associated_file_id' value=\"%s\"/>\n" % (
+ style, help_modify, name, name, value, routefile_id)
if value:
tpl += u"\n<div id='map_edit'></div>"
else:
tpl += "\n<div class='help-route' id='help-route-create'>%s</div>"\
% help_create
- tpl += u"\n<div id='map_edit'>\n"\
- u" <div class='map_button'>\n"\
- u" <a href='#' id='button-move-map' class='toggle-button "\
- u"toggle-button-active' onclick='toggleDrawOff();return false;'>%s"\
- u"</a>\n"\
- u"<a href='#' id='button-draw-map' class='toggle-button "\
- u"toggle-button-inactive' onclick='toggleDrawOn();return false;'>"\
- u"%s</a></div>\n"\
- u" </div>" % (_(u"Move on the map"), _(u"Draw"))
+ tpl += \
+ u"\n<div id='map_edit'>\n"\
+ u" <div class='map_button'>\n"\
+ u" <a href='#' id='button-move-map' class='toggle-button "\
+ u"toggle-button-active' "\
+ u"onclick='toggleDrawOff();return false;'>%s</a>\n"\
+ u"<a href='#' id='button-draw-map' class='toggle-button "\
+ u"toggle-button-inactive' "\
+ u"onclick='toggleDrawOn();return false;'>%s</a></div>\n"\
+ u" </div>" % (_(u"Move on the map"), _(u"Draw"))
tpl += u"<script type='text/javascript'><!--\n"
if not value:
tpl += u"jQuery('#map_edit').hide();"
@@ -453,6 +492,7 @@ class RouteChooserWidget(forms.TextInput):
tpl += u"\n// --></script>\n"
return mark_safe(tpl)
+
class RouteField(models.LineStringField):
'''
Set the widget for the form field
@@ -462,18 +502,19 @@ class RouteField(models.LineStringField):
keys.update(defaults)
return super(RouteField, self).formfield(**keys)
+
class AreaWidget(forms.TextInput):
"""
Manage the edition of an area on the map
"""
class Media:
css = {
- "all": settings.MAP_CSS_URLS + \
- ["%schimere/css/forms.css" % settings.STATIC_URL,]
+ "all": settings.MAP_CSS_URLS +
+ ["%schimere/css/forms.css" % settings.STATIC_URL]
}
js = settings.MAP_JS_URLS + [
- "%schimere/js/edit_area.js" % settings.STATIC_URL,
- "%schimere/js/base.js" % settings.STATIC_URL,]
+ "%schimere/js/edit_area.js" % settings.STATIC_URL,
+ "%schimere/js/base.js" % settings.STATIC_URL]
def get_bounding_box_from_value(self, value):
'''
@@ -483,7 +524,7 @@ class AreaWidget(forms.TextInput):
lower_right_lat, lower_right_lon = 0, 0
if not value:
return upper_left_lat, upper_left_lon, lower_right_lat, \
- lower_right_lon
+ lower_right_lon
if len(value) == 2:
upper_left = value[0]
lower_right = value[1]
@@ -497,7 +538,7 @@ class AreaWidget(forms.TextInput):
pass
if hasattr(lower_right, 'x') and hasattr(lower_right, 'y'):
lower_right_lon, lower_right_lat = lower_right.x, \
- lower_right.y
+ lower_right.y
elif len(lower_right) == 2:
lower_right_lon, lower_right_lat = lower_right
try:
@@ -512,29 +553,30 @@ class AreaWidget(forms.TextInput):
Render a map
"""
upper_left_lat, upper_left_lon, lower_right_lat, lower_right_lon = \
- self.get_bounding_box_from_value(value)
+ self.get_bounding_box_from_value(value)
tpl = getMapJS()
tpl += u"</div>\n"\
- u"<input type='hidden' name='upper_left_lat' id='upper_left_lat' "\
- u"value='%f'/>\n"\
- u"<input type='hidden' name='upper_left_lon' id='upper_left_lon' "\
- u"value='%f'/>\n"\
- u"<input type='hidden' name='lower_right_lat' id='lower_right_lat' "\
- u"value='%f'/>\n"\
- u"<input type='hidden' name='lower_right_lon' id='lower_right_lon' "\
- u"value='%f'/>\n" % (
- upper_left_lat, upper_left_lon, lower_right_lat, lower_right_lon)
+ u"<input type='hidden' name='upper_left_lat' id='upper_left_lat' "\
+ u"value='%f'/>\n"\
+ u"<input type='hidden' name='upper_left_lon' id='upper_left_lon' "\
+ u"value='%f'/>\n"\
+ u"<input type='hidden' name='lower_right_lat' id='lower_right_lat'"\
+ u" value='%f'/>\n"\
+ u"<input type='hidden' name='lower_right_lon' id='lower_right_lon'"\
+ u" value='%f'/>\n" % (
+ upper_left_lat, upper_left_lon, lower_right_lat,
+ lower_right_lon)
help_msg = _(u"Hold CTRL, click and drag to select area on the map")
tpl += u"<p class='help-osm'>%s</p>\n" % help_msg
tpl += u"<script type='text/javascript'>\n"
tpl += u"function init_map_form (){\ninit('map_edit_area');\n"
if value:
tpl += u"var extent = new OpenLayers.Bounds(%f, %f, %f, %f);\n"\
- u"extent.transform(epsg_display_projection, epsg_projection);\n"\
- u"updateForm(extent);\n"\
- u"area_map.zoomToExtent(extent, true);\n"\
- u"area_map.zoomOut();" % (upper_left_lon, upper_left_lat,
- lower_right_lon, lower_right_lat)
+ u"extent.transform(epsg_display_projection, epsg_projection);\n"\
+ u"updateForm(extent);\n"\
+ u"area_map.zoomToExtent(extent, true);\n"\
+ u"area_map.zoomOut();" % (upper_left_lon, upper_left_lat,
+ lower_right_lon, lower_right_lat)
tpl += u"}\n"
if initialized:
tpl += u"$(document).ready(function($) {init_map_form()});\n"
@@ -558,8 +600,10 @@ class AreaWidget(forms.TextInput):
values.append(value)
return values
-RE_XAPI = re.compile('(node|way)\[(.*=.*)\]\[bbox='\
- '(-*[0-9]*.[0-9]*,-*[0-9]*.[0-9]*,-*[0-9]*.[0-9]*,-*[0-9]*.[0-9]*)\]')
+RE_XAPI = re.compile(
+ '(node|way)\[(.*=.*)\]\[bbox='
+ '(-*[0-9]*.[0-9]*,-*[0-9]*.[0-9]*,-*[0-9]*.[0-9]*,-*[0-9]*.[0-9]*)\]')
+
class ImportFiltrWidget(AreaWidget):
"""
@@ -567,53 +611,55 @@ class ImportFiltrWidget(AreaWidget):
"""
class Media:
css = {
- "all": settings.MAP_CSS_URLS + \
- ["%schimere/css/forms.css" % settings.STATIC_URL,]
+ "all": settings.MAP_CSS_URLS +
+ ["%schimere/css/forms.css" % settings.STATIC_URL]
}
js = settings.MAP_JS_URLS + [
- "%schimere/js/edit_area.js" % settings.STATIC_URL,
- "%schimere/js/base.js" % settings.STATIC_URL,]
+ "%schimere/js/edit_area.js" % settings.STATIC_URL,
+ "%schimere/js/base.js" % settings.STATIC_URL]
def render(self, name, value, attrs=None):
"""
Render a map
"""
tpl = super(ImportFiltrWidget, self).render(name, value, attrs,
- initialized=False)
+ initialized=False)
tpl += u"</div><hr class='spacer'/>"
- vals = {'lbl':_(u"Type:"), 'name':name, 'node':_(u"Node"),
- 'way':_(u"Way")}
+ vals = {'lbl': _(u"Type:"), 'name': name, 'node': _(u"Node"),
+ 'way': _(u"Way")}
vals['way_selected'] = ' checked="checked"'\
- if self.xapi_type == 'way' else ''
+ if self.xapi_type == 'way' else ''
vals['node_selected'] = ' checked="checked"'\
- if self.xapi_type == 'node' else ''
+ if self.xapi_type == 'node' else ''
tpl += u"<div class='input-osm'><label>%(lbl)s</label>"\
- u"<input type='radio' name='id_%(name)s_type' id='id_%(name)s_node'"\
- u" value='node'%(node_selected)s/> <label for='id_%(name)s_node'>"\
- u"%(node)s</label> <input type='radio' name='id_%(name)s_type' "\
- u"id='id_%(name)s_way' value='way'%(way_selected)s/> <label "\
- u"for='id_%(name)s_way'>%(way)s</label></div>" % vals
- help_msg = _(u"Enter an OSM \"tag=value\" string such as "\
- u"\"amenity=pub\". A list of common tag is available "\
- u"<a href='https://wiki.openstreetmap.org/wiki/Map_Features' "\
- u" target='_blank'>here</a>.")
+ u"<input type='radio' name='id_%(name)s_type' "\
+ u"id='id_%(name)s_node' value='node'%(node_selected)s/> "\
+ u"<label for='id_%(name)s_node'>"\
+ u"%(node)s</label> <input type='radio' name='id_%(name)s_type' "\
+ u"id='id_%(name)s_way' value='way'%(way_selected)s/> <label "\
+ u"for='id_%(name)s_way'>%(way)s</label></div>" % vals
+ help_msg = _(
+ u"Enter an OSM \"tag=value\" string such as "
+ u"\"amenity=pub\". A list of common tag is available "
+ u"<a href='https://wiki.openstreetmap.org/wiki/Map_Features' "
+ u" target='_blank'>here</a>.")
tpl += u"<p class='help-osm'>%s</p>\n" % help_msg
tpl += u"<div class='input-osm'><label for='id_%s_tag'>%s</label>"\
u"<input type='text' id='id_%s_tag' value=\"%s\"/></div>" % (
- name, _(u"Tag:"), name, self.xapi_tag)
+ name, _(u"Tag:"), name, self.xapi_tag)
tpl += u"<script type='text/javascript'>\n"
tpl += u"var default_xapi='%s';" % settings.CHIMERE_XAPI_URL
tpl += u'var msg_missing_area = "%s";' % \
- _(u"You have to select an area.")
+ _(u"You have to select an area.")
tpl += u'var msg_missing_type = "%s";' % \
- _(u"You have to select a type.")
+ _(u"You have to select a type.")
tpl += u'var msg_missing_filtr = "%s";' % \
- _(u"You have to insert a filter tag.")
+ _(u"You have to insert a filter tag.")
tpl += u"</script>\n"
- help_msg = _(u"If you change the above form don't forget to refresh "\
+ help_msg = _(u"If you change the above form don't forget to refresh "
u"before submit!")
tpl += u"<p class='help-osm errornote'>%s</p>\n" % help_msg
- help_msg = _(u"You can put a Folder name of the KML file to filter on "\
+ help_msg = _(u"You can put a Folder name of the KML file to filter on "
u"it.")
tpl += u"<p class='help-kml'>%s</p>\n" % help_msg
if not value:
@@ -628,7 +674,7 @@ class ImportFiltrWidget(AreaWidget):
"""
Return the appropriate values
"""
- return data.get('id_'+name, None)
+ return data.get('id_' + name, None)
def get_bounding_box_from_value(self, value):
'''
@@ -640,17 +686,18 @@ class ImportFiltrWidget(AreaWidget):
self.xapi_type, self.xapi_tag, self.bounding_box = None, '', None
if not value:
return upper_left_lat, upper_left_lon, lower_right_lat, \
- lower_right_lon
+ lower_right_lon
xapi_m = RE_XAPI.match(value)
if not xapi_m:
return upper_left_lat, upper_left_lon, lower_right_lat, \
- lower_right_lon
+ lower_right_lon
# as the regexp pass, we could be pretty confident
self.xapi_type, self.xapi_tag, self.bounding_box = xapi_m.groups()
upper_left_lon, lower_right_lat, lower_right_lon, upper_left_lat = \
- self.bounding_box.split(',')
+ self.bounding_box.split(',')
return float(upper_left_lat), float(upper_left_lon), \
- float(lower_right_lat), float(lower_right_lon)
+ float(lower_right_lat), float(lower_right_lon)
+
class AreaField(forms.MultiValueField):
'''
@@ -663,33 +710,36 @@ class AreaField(forms.MultiValueField):
return None
return data_list
+
class MultiSelectWidget(forms.SelectMultiple):
class Media:
css = {'all': list(settings.JQUERY_CSS_URLS) + [
settings.STATIC_URL + 'bsmSelect/css/jquery.bsmselect.css',
settings.STATIC_URL + 'bsmSelect/css/jquery.bsmselect.custom.css',
- ]
+ ]
}
js = list(settings.JQUERY_JS_URLS) + [
settings.STATIC_URL + 'bsmSelect/js/jquery.bsmselect.js',
- settings.STATIC_URL + 'bsmSelect/js/jquery.bsmselect.compatibility.js',
- ]
+ settings.STATIC_URL +
+ 'bsmSelect/js/jquery.bsmselect.compatibility.js',
+ ]
def render(self, name, value, attrs=None):
rendered = super(MultiSelectWidget, self).render(name, value, attrs)
rendered += u"<hr class='spacer'/><script type='text/javascript'>\n"\
- u"$.bsmSelect.conf['title'] = \"%(title)s\";\n"\
- u"$(\"#id_%(name)s\").bsmSelect({\n"\
- u" removeLabel: '<strong>X</strong>',\n"\
- u" containerClass: 'bsmContainer',\n"\
- u" listClass: 'bsmList-custom',\n"\
- u" listItemClass: 'bsmListItem-custom',\n"\
- u" listItemLabelClass: 'bsmListItemLabel-custom',\n"\
- u" removeClass: 'bsmListItemRemove-custom'\n"\
- u"});\n"\
- u"</script>\n" % {'name':name, 'title':_("Select...")}
+ u"$.bsmSelect.conf['title'] = \"%(title)s\";\n"\
+ u"$(\"#id_%(name)s\").bsmSelect({\n"\
+ u" removeLabel: '<strong>X</strong>',\n"\
+ u" containerClass: 'bsmContainer',\n"\
+ u" listClass: 'bsmList-custom',\n"\
+ u" listItemClass: 'bsmListItem-custom',\n"\
+ u" listItemLabelClass: 'bsmListItemLabel-custom',\n"\
+ u" removeClass: 'bsmListItemRemove-custom'\n"\
+ u"});\n"\
+ u"</script>\n" % {'name': name, 'title': _("Select...")}
return mark_safe(rendered)
+
class SelectMultipleField(models.ManyToManyField):
'''
Set the widget for the category field