Tuesday, 15 January 2013

python - Django floppyforms OSMPointWidget does not display a map -



python - Django floppyforms OSMPointWidget does not display a map -

i trying set osm-map, similar 1 in geodjango-admin, form on main site.

i decided utilize floppyforms, set in documentation , seems recognized, strangely map not appear. firebug shows there empty <div id="id_coord_map"></div> instead of map, has right dimensions. debug-textbox , "delete features"-link there should be. but, when open site, firebug not show javascript requests in 'network'-tab, maybe hint.

i guess missed or isn't correctly included, tried hours , don't know anymore. amongst other things set paths static files , run manage.py collectstatic, tried not utilize generic edit views, came out same.

here relevant parts in code:

#views.py import floppyforms forms ... class osmpointwidget(forms.gis.pointwidget, forms.gis.baseosmwidget): pass class locationcreateview(createview): model = location fields = ['name', 'zip', 'coord'] form_class = modelform_factory(location, widgets={"coord": forms.gis.pointwidget(attrs = { 'display_wkt': true, 'map_srid': 4326, 'map_width': 700, 'map_height': 500,})}) #models.py class location(models.model): name = models.charfield(max_length=200) slug = models.slugfield(max_length=255, blank=true, default='', unique=true) coord = models.pointfield() zip = models.charfield(max_length=5, default='12345') objects = models.geomanager() def __unicode__(self): homecoming self.name def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.name) super(location, self).save(*args, **kwargs) #urls.py urlpatterns = patterns('', ... url(r"location/$", views.locationcreateview.as_view(), name = "locationcreate"), ... ) #location_form.html {% extends "_layouts/base.html" %} {% block page_title %}enter location | {% endblock %} {% block page_content %} <form action="" method="post"> {% csrf_token %} {{ form.as_p }} <input type="submit" value="submit" /> </form> {% endblock %} #base.html <!doctype html> <html> <head> <title>{% block page_title %}{% endblock %}calendar</title> <link rel="stylesheet" href="{{ static_url }}css/bootstrap.css"> <link rel="stylesheet" href="{{ static_url }}css/bootstrap-theme.css" > </head> <body> <div class="container theme-showcase" role="main"> <div class="jumbotron"> <h1>eventcalendar</h1> </div> <div class="container"> {% block page_content %}{% endblock %} </div> </div> </body> </html>

i had similar issue , realised needed include {{ form.media }} tag in header , django-floppyforms supplies relevant javascript files create map magically appear.

somewhere in head of base.html include block javascript

{% block extra_js %}{% endblock %}

then fill in block in location_form.html

{% block extra_js %} {{ form.media }} {% endblock %}

python django openstreetmap geodjango django-floppyforms

No comments:

Post a Comment