Skip to content

Commit

Permalink
Rewrite django-places lib
Browse files Browse the repository at this point in the history
- Create a simple API for Place field
- Create a demo project
- Add support for Django 1.10
  • Loading branch information
oscarmcm committed Jan 9, 2017
1 parent f1eca5c commit 2d2fef9
Show file tree
Hide file tree
Showing 38 changed files with 682 additions and 149 deletions.
12 changes: 5 additions & 7 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
Copyright (c) 2016, Oscar Cortez
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
MIT License

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Copyright (c) 2017, Oscar Cortez

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

* Neither the name of dj-places nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ include AUTHORS.md
include CHANGELOG.md
include LICENSE
include README.md
recursive-include djplaces *.html *js *.css *py
recursive-include places/templates *.html
recursive-include places/static *.js *.css
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ help:
@echo "test-all - run tests on every Python version with tox"
@echo "coverage - check code coverage quickly with the default Python"
@echo "docs - generate Sphinx HTML documentation, including API docs"
@echo "demo - run the demo project"
@echo "release - package and upload a release"
@echo "sdist - package"

Expand Down Expand Up @@ -46,6 +47,9 @@ docs:
$(MAKE) -C docs html
open docs/_build/html/index.html

run:
python example/manage.py runserver

release: clean
python setup.py sdist upload
python setup.py bdist_wheel upload
Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,29 @@ Install dj-places and add it to your installed apps:

INSTALLED_APPS = (
...
'djplaces',
'places',
...
)

Add your maps api key in your settings ( [read more here](https://developers.google.com/maps/documentation/javascript/3.exp/reference) ):

MAPS_API_KEY='YourAwesomeUltraSecretKey'
PLACES_MAPS_API_KEY='YourAwesomeUltraSecretKey'

Then use it in a project:

from djplaces.fields import LocationField
place = models.CharField(max_length=250)
location = LocationField(base_field='place')
from places.fields import PlacesField
location = PlacesField()

Demo
------

![](http://g.recordit.co/hZabhhYLHS.gif)
![](http://g.recordit.co/LheQH0HDMR.gif)

TODO-LIST
--------

* [ ] Write some test ASAP!
* [ ] Support Inline Admin
* [ ] Set custom zoom map value
* [ ] Custom property for lat and lng values

Running Tests
--------------
Expand All @@ -59,8 +56,6 @@ Does the code actually work?
Credits
---------

Special thanks to [Helmy Giacoman](https://github.com/eos87) for motivating me to make this package.

Tools used in rendering this package:

* [Cookiecutter](https://github.com/audreyr/cookiecutter)
Expand All @@ -71,4 +66,4 @@ Similar Projects
------------

* [Django Location Field](https://github.com/caioariede/django-location-field)
* [Django Geoposition](https://github.com/philippbosch/django-geoposition)
* [Django GeoPosition](https://github.com/philippbosch/django-geoposition)
1 change: 0 additions & 1 deletion djplaces/__init__.py

This file was deleted.

32 changes: 0 additions & 32 deletions djplaces/fields.py

This file was deleted.

7 changes: 0 additions & 7 deletions djplaces/static/css/djplaces.css

This file was deleted.

32 changes: 0 additions & 32 deletions djplaces/static/js/djplaces.js

This file was deleted.

5 changes: 0 additions & 5 deletions djplaces/templates/djplaces/map_widget.html

This file was deleted.

30 changes: 0 additions & 30 deletions djplaces/widgets.py

This file was deleted.

24 changes: 24 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
##Example Project for django-places

This example is provided as a convenience feature to allow potential users to try the app straight from the app repo without having to create a django project.

It can also be used to develop the app in place.

To run this example, follow these instructions:

1. Navigate to the `example` directory
2. Install the requirements for the package:

pip install -r requirements.txt

3. Make and apply migrations

python manage.py makemigrations

python manage.py migrate

4. Run the server

python manage.py runserver

5. Access from the browser at `http://127.0.0.1:8000`
Empty file added example/example/__init__.py
Empty file.
116 changes: 116 additions & 0 deletions example/example/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
"""
Django settings for example project.
Generated by Cookiecutter Django Package
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '%b&p!s^@301dc=@y^*x92ff*hzelqm0)m0vy29-dwexs=e1w+t'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'places',
'geoposition',
'points',
]

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'example.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'), ],
'OPTIONS': {
'debug': True,
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'example.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = []

# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

STATIC_URL = '/static/'

PLACES_MAPS_API_KEY = 'AIzaSyBS2jGczsTKS9oMjcr_OS4BV3nRcp8EgHw'
22 changes: 22 additions & 0 deletions example/example/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""example URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin


urlpatterns = [
url(r'^admin/', admin.site.urls),
]
16 changes: 16 additions & 0 deletions example/example/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for example project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")

application = get_wsgi_application()
Loading

0 comments on commit 2d2fef9

Please sign in to comment.