From fee4daab6598a3d6e51a31e2e70e059fc5419908 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 21 Feb 2016 17:13:43 +0100 Subject: Basic integration of polygons --- chimere/widgets.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'chimere/widgets.py') diff --git a/chimere/widgets.py b/chimere/widgets.py index f8bb11b..bffd42f 100644 --- a/chimere/widgets.py +++ b/chimere/widgets.py @@ -600,6 +600,33 @@ class AreaWidget(forms.TextInput): values.append(value) return values + +class PolygonChooserWidget(forms.TextInput): + """ + Manage the edition of polygon on a map + """ + class Media: + 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] + + def render(self, name, value, attrs=None, area_name='', initialized=True): + # To be done + return super(PolygonChooserWidget, self).render(name, value, attrs) + + +class PolygonField(models.PolygonField): + ''' + Set the widget for the form field + ''' + def formfield(self, **keys): + defaults = {'widget': RouteChooserWidget} + keys.update(defaults) + return super(PolygonField, self).formfield(**keys) + RE_XAPI = re.compile( '(node|way)\[(.*=.*)\]\[bbox=' '(-*[0-9]*.[0-9]*,-*[0-9]*.[0-9]*,-*[0-9]*.[0-9]*,-*[0-9]*.[0-9]*)\]') @@ -754,3 +781,4 @@ from south.modelsinspector import add_introspection_rules add_introspection_rules([], ["^chimere\.widgets\.PointField"]) add_introspection_rules([], ["^chimere\.widgets\.SelectMultipleField"]) add_introspection_rules([], ["^chimere\.widgets\.RouteField"]) +add_introspection_rules([], ["^chimere\.widgets\.PolygonField"]) -- cgit v1.2.3