Skip to content

Commit 495d985

Browse files
authored
Mapbox point field widget (#131)
* Add Mapbox poing field widget * Fix undefined place object binding issue in javascript triggers * Update documentation for MapBox widget * Tidy up localization files
1 parent 2aaa088 commit 495d985

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+10807
-449
lines changed

README.md

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Configurable, pluggable and more user friendly map widgets for Django PostGIS fi
99
* **Project Home Page**: <a href="https://github.com/erdem/django-map-widgets">https://github.com/erdem/django-map-widgets/</a>
1010

1111
### Achievements
12-
The aim of the Django map widgets is to make all Geo Django widgets more user friendly and configurable. Map widgets are currently supporting only Google Map services, but we are planning to add other major map services.
12+
The aim of the Django map widgets is to make all Geo Django widgets more user-friendly and configurable.
13+
14+
Django map widgets package has support for Mapbox and Google Map services currently, if you want to see more widgets and think you can help, feel free to contribute to the project.
15+
We would be happy to review and merge your contributions. :)
1316

1417
### Installation
1518

@@ -94,63 +97,32 @@ This widget is working with <a href="http://dimsemenov.com/plugins/magnific-popu
9497

9598
### Release Notes
9699

97-
#### v0.3.3
100+
#### 0.4.0
101+
> - Supported MapBox Map for Django Geo Point Field.
102+
> - Fixed undefined place object binding issue in javascript triggers. (#125)
103+
> - Documented MapBox point field map widget features.
104+
> - Updated various localize files.
105+
106+
#### 0.3.3
98107

99108
> - Replaced [ugettext_lazy](https://github.com/erdem/django-map-widgets/pull/127) usages with [gettext_lazy](https://docs.djangoproject.com/en/4.0/releases/4.0/#features-removed-in-4-0) for Django 4.0. (#127)
100109
> - Updated [Travis CI file](https://github.com/erdem/django-map-widgets/pull/129). (#129)
101110
102-
103-
#### v0.3.2
111+
#### 0.3.2
104112

105113
> - Added [streetViewControl](https://developers.google.com/maps/documentation/javascript/streetview#StreetViewMapUsage) switch to GooglePointFieldWidget settings. (#124)
106114
107-
#### v0.3.1
115+
#### 0.3.1
108116

109117
> - Removed `six` package usages. (#117)
110118
> - Added a new general widget setting in order to specify Google JS libraries. (#119)
111119
> - Implemented some improvements for the demo project.
112120
113-
#### v0.3.0
121+
#### 0.3.0
114122

115123
> - Implemented a new demo project with Django 2.x.
116124
> - Fixed Django Admin jQuery conflicts. (#100)
117125
> - Fixed a new widget JS instance initialising issue for Django Admin Inlines. (#84)
118126
> - Added Python 3.8 env settings to TravisCI configuration.
119127
120-
121-
#### v0.2.3
122-
123-
> - Fixed python `six` module import issue.
124-
> - Fixed PostGIS setup errors in CI pipeline.
125-
> - Added Estonian language support.
126-
127-
#### v0.2.0
128-
129-
> - Fixed Python 3.6, Django 2.x compatible issues.
130-
> - Fixed SRID format converter issues.
131-
> - Removed `pyproj` package dependency.
132-
> - Various development infrastructure updates. (Docker, Fabric files etc.)
133-
> - Point map widget JS objects associated to the map HTML elements with jQuey `$.data` method.
134-
> - Passing Google Place AutoComplete full response object to jQuery triggers.
135-
136-
#### v0.1.9
137-
138-
> - Google Place Autocomplete object binding to jQuery triggers.
139-
> - Implemented Google Geocoding support for the marker coordinates.
140-
> - Added custom widget settings feature for each widget.
141-
> - Added Portuguese localisation support.
142-
> - Fixed Google Place Autocomplete widget bugs in Django Admin Inlines.
143-
> - Fixed Python 3.6 errors.
144-
> - Fixed Javascript bugs.
145-
> - The GitHub repository Integrated with Travis CI.
146-
> - Implemented unit tests for backend code. (%100 code coverage)
147-
> - Change development environment from Vagrant to Docker.
148-
149-
150-
#### v0.1.8
151-
152-
> - Full documentation integrated to readthedocs.org.
153-
> - Fixed Google Map static widget issues.
154-
> - Added Russian localisation support.
155-
> - Added [Google Places Autocomplete] options support.
156-
> - Fixed CSS issues.
128+
[See release notes](https://django-map-widgets.readthedocs.io/en/mapbox_widget_fixes/releases/index.html) for all versions.

README.rst

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ Django Map Widgets
1515

1616
Configurable, pluggable and more user friendly map widgets for Django PostGIS fields.
1717

18+
.. note::
19+
Check the `project home page <https://github.com/erdem/django-map-widgets/>`_ for latest updates.
20+
1821
* **Project Home Page** : `https://github.com/erdem/django-map-widgets <https://github.com/erdem/django-map-widgets/>`_.
1922
* **Documentation**: `http://django-map-widgets.readthedocs.io <http://django-map-widgets.readthedocs.io/>`_.
2023

2124
Achievements
2225
^^^^^^^^^^^^
2326

24-
The aim of the Django map widgets is to make all Geo Django widgets more user friendly and configurable. Map widgets are currently supporting only Google Map services, but we are planning to add other major map services.
25-
27+
| The aim of the Django map widgets is to make all Geo Django widgets more user-friendly and configurable.
28+
|
29+
| Django map widgets package has support for Mapbox and Google Map services currently, if you want to see more widgets and think you can help, feel free to contribute to the project.
30+
| We would be happy to review and merge your contributions. :)
2631
2732
Installation
2833
^^^^^^^^^^^^
@@ -100,6 +105,16 @@ Google Map Static Overlay Widget
100105
Release Notes
101106
^^^^^^^^^^^^^
102107

108+
=====
109+
0.4.0
110+
=====
111+
112+
* Supported MapBox Map for Geo Point Field
113+
* Fixed undefined place object binding issue in javascript triggers. (#125)
114+
* Documented MapBox point field map widget
115+
* Updated various localize files.
116+
117+
103118
======
104119
v0.3.2
105120
======
@@ -122,48 +137,3 @@ v0.3.0
122137
* Fixed Django Admin jQuery conflicts. (#100)
123138
* Fixed a new widget JS instance initialising issue for Django Admin Inlines. (#84)
124139
* Added Python 3.8 env settings to TravisCI configuration.
125-
126-
======
127-
v0.2.3
128-
======
129-
130-
* Fixed python `six` module import issue.
131-
* Fixed PostGIS setup errors in CI pipeline.
132-
* Added Estonian language support.
133-
134-
======
135-
v0.2.0
136-
======
137-
138-
* Fixed Python 3.6, Django 2.x compatible issues.
139-
* Fixed SRID format converter issues.
140-
* Removed pyproj package dependency.
141-
* Various development infrastructure updates. (Docker, Fabric files etc.)
142-
* Fixed Google Place Autocomplete widget bugs in Django Admin Inlines.
143-
* Point map widget JS objects associated to the map HTML elements with jQuey $.data method.
144-
* Passing Google Place AutoComplete full response object to jQuery triggers.
145-
146-
======
147-
v0.1.9
148-
======
149-
150-
* Google Place Autocomplete object binding to jQuery triggers.
151-
* Implemented Google Geocoding support for the marker coordinates.
152-
* Added custom widget settings feature for each widget.
153-
* Added Portuguese localisation support.
154-
* Fixed Google Place Autocomplete widget bugs in Django Admin Inlines.
155-
* Fixed Python 3.6 errors.
156-
* Fixed Javascript bugs.
157-
* The GitHub repository Integrated with Travis CI.
158-
* Implemented unit tests for backend code. (%100 code coverage)
159-
* Change development environment from Vagrant to Docker.
160-
161-
======
162-
v0.1.8
163-
======
164-
165-
* Full documentation integrated to readthedocs.org.
166-
* Fixed Google Map static widget issues.
167-
* Added Russian localisation support.
168-
* Added `Google Places Autocomplete <https://developers.google.com/maps/documentation/javascript/places-autocomplete>`_ options support.
169-
* Fixed CSS issues.

conf/requirements-dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Django
22
psycopg2==2.8.4
33
selenium==3.3.1
44
coverage==4.4
5-
Fabric==1.14.0
5+
Fabric<2.0
66
coveralls==1.3.0
77
backports.zoneinfo
8-
tzdata
8+
tzdata

demo/cities/admin.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .models import House, Neighbour
44
from django.contrib.gis.db import models
55
from mapwidgets.widgets import GooglePointFieldWidget, GooglePointFieldInlineWidget, GoogleStaticMapWidget, \
6-
GoogleStaticOverlayMapWidget
6+
GoogleStaticOverlayMapWidget, MapboxPointFieldWidget
77

88

99
class NeighbourAdminInline(admin.TabularInline):
@@ -14,35 +14,28 @@ class NeighbourAdminInline(admin.TabularInline):
1414
}
1515

1616

17-
class HouseAdminForm(forms.ModelForm):
18-
class Meta:
19-
model = House
20-
fields = "__all__"
21-
widgets = {
22-
'location': GooglePointFieldWidget(settings={"GooglePointFieldWidget": (("zoom", 1),)}),
23-
'location_has_default': GooglePointFieldWidget,
24-
}
25-
26-
2717
class HouseAdminStaticForm(forms.ModelForm):
2818

2919
class Meta:
3020
model = House
3121
fields = "__all__"
3222
widgets = {
33-
'location': GoogleStaticMapWidget,
34-
'location_has_default': GoogleStaticOverlayMapWidget,
23+
'location': GoogleStaticOverlayMapWidget,
24+
'location_has_default': GoogleStaticMapWidget,
3525
}
3626

3727

3828
class HouseAdmin(admin.ModelAdmin):
3929
search_fields = ('name', )
4030
list_display = ("name", "location")
4131
inlines = (NeighbourAdminInline,)
32+
form = HouseAdminStaticForm
4233

4334
def get_form(self, request, obj=None, **kwargs):
4435
form = super(HouseAdmin, self).get_form(request, obj, **kwargs)
45-
form.base_fields['location'].widget = GooglePointFieldWidget()
36+
if obj is None: # manipulate page form
37+
form.base_fields['location'].widget = MapboxPointFieldWidget()
38+
form.base_fields['location_has_default'].widget = GooglePointFieldWidget()
4639
return form
4740

4841
@property
@@ -57,7 +50,7 @@ def _changeform_view(self, request, object_id, form_url, extra_context):
5750
class NeighbourAdmin(admin.ModelAdmin):
5851
autocomplete_fields = ('neighbour_of_house',)
5952
formfield_overrides = {
60-
models.PointField: {"widget": GoogleStaticOverlayMapWidget}
53+
models.PointField: {"widget": MapboxPointFieldWidget}
6154
}
6255

6356

demo/cities/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django import forms
22

33
from cities.models import City
4-
from mapwidgets.widgets import GooglePointFieldWidget, GoogleStaticMapWidget, GoogleStaticOverlayMapWidget
4+
from mapwidgets.widgets import MapboxPointFieldWidget, GoogleStaticMapWidget, GoogleStaticOverlayMapWidget, GooglePointFieldWidget
55

66

77
class CityCreateForm(forms.ModelForm):

demo/cities/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
path('', CityListView.as_view(), name="list"),
88
re_path(r'^(?P<pk>\d+)/$', CityDetailView.as_view(), name="detail"),
99
re_path(r'^create/$', CityCreateView.as_view(), name="create"),
10-
]
10+
]

demo/demo/settings.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@
5959
'django.contrib.messages.middleware.MessageMiddleware',
6060
'django.middleware.clickjacking.XFrameOptionsMiddleware',
6161
]
62-
62+
STATIC_URL = 'static/'
63+
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
64+
STATICFILES_DIRS = [
65+
os.path.join(BASE_DIR, "static"),
66+
]
6367
ROOT_URLCONF = 'demo.urls'
64-
6568
TEMPLATES = [
6669
{
6770
'BACKEND': 'django.template.backends.django.DjangoTemplates',
@@ -130,12 +133,15 @@
130133

131134
USE_TZ = True
132135

136+
LOCALE_PATHS = (
137+
"/django-map-widgets/mapwidgets/locale",
138+
)
133139

134140
# Static files (CSS, JavaScript, Images)
135141
# https://docs.djangoproject.com/en/2.2/howto/static-files/
136142

137-
STATIC_URL = '/static/'
138143
GOOGLE_MAP_API_KEY = os.getenv('GOOGLE_MAP_API_KEY', None)
144+
MAPBOX_API_KEY = os.getenv('MAPBOX_API_KEY', None)
139145
MAP_WIDGETS = {
140146
"GooglePointFieldWidget": (
141147
("zoom", 15),
@@ -144,5 +150,13 @@
144150
("GooglePlaceAutocompleteOptions", {'componentRestrictions': {'country': 'uk'}}),
145151
("streetViewControl", False)
146152
),
147-
"GOOGLE_MAP_API_KEY": GOOGLE_MAP_API_KEY,
153+
"MapboxPointFieldWidget": {
154+
"access_token": MAPBOX_API_KEY,
155+
"mapOptions": {
156+
"zoom": 10,
157+
"center": (51.515618, -0.091998)
158+
}
159+
},
160+
"GOOGLE_MAP_API_KEY": GOOGLE_MAP_API_KEY
148161
}
162+

demo/demo/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
1. Import the include() function: from django.urls import include, path
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
16+
from django.conf import settings
1617
from django.contrib import admin
1718
from django.urls import path, include
19+
from django.conf.urls.static import static
1820

1921
urlpatterns = [
2022
path('admin/', admin.site.urls),
2123
path('cities/', include('cities.urls'))
22-
]
24+
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

0 commit comments

Comments
 (0)