Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add leaflet form widget and admin #28

Merged
merged 53 commits into from Sep 3, 2013

Conversation

leplatrem
Copy link
Collaborator

capture du 2013-08-29 12 19 03

Usage is very easy ( Requires Django 1.6 ) :

# admin.py

from django.contrib import admin
from leaflet.admin import LeafletGeoAdmin

from .models import Region


admin.site.register(Region, LeafletGeoAdmin)

Or in form :

    from django import forms
    from leaflet.forms.fields import PointField
    from .models import WeatherStation

    class WeatherStationForm(forms.ModelForm):
        geom = PointField()

        class Meta:
            model = WeatherStation
            fields = ('name', 'geom')

TODO

  • Check bidirectional text
  • Translate JS texts
  • Common form field (outside admin)
  • Prevent multiple geometries if field type is not multi
  • Bypass Wicket for Multi-geometry types
  • Fix CSS display of wkt in debug mode
  • Django <1.6 compat using Floppyforms ?
  • Option to remove edit/delete buttons
  • Write template tests
  • Write some JS tests
  • Generic geometry tests
  • Generic geometry collection support

@leplatrem leplatrem mentioned this pull request Aug 30, 2013
@coveralls
Copy link

Coverage Status

Coverage increased (+21.11%) when pulling 45b8ff5 on add_leaflet_form_widget_and_admin into 4389cd8 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+22.01%) when pulling 2b6d72a on add_leaflet_form_widget_and_admin into 4389cd8 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 17a04b3 on add_leaflet_form_widget_and_admin into 4389cd8 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+42.67%) when pulling fb054fd on add_leaflet_form_widget_and_admin into 4389cd8 on master.

leplatrem added a commit that referenced this pull request Sep 3, 2013
@leplatrem leplatrem merged commit 1fa80ac into master Sep 3, 2013
@geomajor56
Copy link

I'm having trouble enabling admin with this line, "from leaflet.admin import LeafletGeoAdmin" Error says "no module named admin".
I've loaded django-leaflet 0.74 into my virtualenv via PyCharm. Do i need to load a newer package?

@leplatrem
Copy link
Collaborator Author

Indeed, it was not released yet, you need to run the last development version (master) along with Django 1.6

@geomajor56
Copy link

I did that and got it running. Took me a while to figure it out. I'm new to
Python/Django.

The problem I now have is that it can't save the geometry. I'm using
PostGreSQL/PostGIS1.5. It's writing to the geom column in postgres but
doesnt show up on map. The error is "Calling transform() with no SRID set
is not supported".
Plus the version is Django 1.6b2, does that make a difference?

models.py
from django.db import models
from django.contrib.gis.db import models as gismodels

class Station(gismodels.Model):
TYPE_CHOICES = (
('Off Shore', 'Off Shore'),
('Near Shore', 'Near Shore'),
('Volunteer', 'Volunteer'),
('Wellfleet Oyster Project', 'Wellfleet Oyster Project'),
('Cedar Pond Project', 'Cedar Pond Project')
)
station_num = models.IntegerField("Station Number", max_length=4,
primary_key=True)
station_name = models.CharField("Station Name", max_length=50)
station_type = models.CharField("Station Type", max_length=40,
choices=TYPE_CHOICES)
geom = gismodels.PointField(srid=4326)
objects = gismodels.GeoManager()

def __unicode__(self):
    return unicode(self.station_name)

class Meta:
    verbose_name_plural = 'Monitoring Stations'

thanks in advance for any help you can provide,

Michael

On Thu, Sep 5, 2013 at 3:34 AM, Mathieu Leplatre
notifications@github.comwrote:

Indeed, it was not released yet, you need to run the last development
version (master) along with Django 1.6


Reply to this email directly or view it on GitHubhttps://github.com//pull/28#issuecomment-23848605
.

@leplatrem
Copy link
Collaborator Author

You model looks good, and it looks like you are facing a bug that was fixed very recently (don't forget that Django 1.6 is not yet released).

Upgrading your Django to the last version (branch 1.6.X) will solve this.

https://code.djangoproject.com/ticket/21003
django/django@0514fbb

@geomajor56
Copy link

That worked great, thank you so much. The django version reads 1.7

On Thu, Sep 5, 2013 at 9:02 AM, Mathieu Leplatre
notifications@github.comwrote:

You model looks good, and it looks like you are facing a bug that was
fixed very recently (don't forget that Django 1.6 is not yet released).

Upgrading your Django to the last version (branch 1.6.X) will solve this.

https://code.djangoproject.com/ticket/21003
django/django@0514fbbhttps://github.com/django/django/commit/0514fbb2f37b530e46f54e205cb8c9d722e142d6


Reply to this email directly or view it on GitHubhttps://github.com//pull/28#issuecomment-23865703
.

@geomajor56
Copy link

One more thing if you don't mind. How do I go about adjusting width and
height of admin map? Is there a list of options for the LEAFLET_CONFIG?

On Thu, Sep 5, 2013 at 4:53 PM, Michael Savarese geomajor56@gmail.comwrote:

That worked great, thank you so much. The django version reads 1.7

On Thu, Sep 5, 2013 at 9:02 AM, Mathieu Leplatre <notifications@github.com

wrote:

You model looks good, and it looks like you are facing a bug that was
fixed very recently (don't forget that Django 1.6 is not yet released).

Upgrading your Django to the last version (branch 1.6.X) will solve this.

https://code.djangoproject.com/ticket/21003
django/django@0514fbbhttps://github.com/django/django/commit/0514fbb2f37b530e46f54e205cb8c9d722e142d6


Reply to this email directly or view it on GitHubhttps://github.com//pull/28#issuecomment-23865703
.

@leplatrem
Copy link
Collaborator Author

In the Adminsite you can just override LeafletGeoAdmin :


class HighLeafletGeoAdmin(LeafletGeoAdmin):
    map_width = '100%'
    map_height = '800px'

@geomajor56
Copy link

is it possible to alter the max zoom within admin when selecting a feature?
Not sure where I'd put it

thanks in advance,

Michael

@leplatrem
Copy link
Collaborator Author

Hi Michael,
Sorry I didn't remember to give you an answer...
In the adminsite indeed, it is a good idea ! It's not supported easily so far (unless you have custom JS script where you can listen to event and setup option on the map object)
If you can contribute, it would be welcome !
Mathieu

@submarcos submarcos deleted the add_leaflet_form_widget_and_admin branch June 9, 2020 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants