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

Replace function _get_val_from_obj with value_from_object to work in Django 2+ #110

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
language: python
python:
- 2.7
- 3.4
- 3.5
- 3.6
env:
- DJANGO=1.8.14
- DJANGO=1.9.9
- DJANGO=1.10
- DJANGO=2.2.9
- DJANGO=3.0.1
install:
- pip install -q Django==$DJANGO
- pip install .
Expand Down
10 changes: 2 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ django-geoposition

A model field that can hold a geoposition (latitude/longitude), and corresponding admin/form widget.

.. image:: https://badge.fury.io/py/django-geoposition.svg
:target: https://badge.fury.io/py/django-geoposition
.. image:: https://travis-ci.org/starcross/django-geoposition.svg?branch=master
:target: https://travis-ci.org/starcross/django-geoposition

.. image:: https://travis-ci.org/philippbosch/django-geoposition.svg?branch=master
:target: https://travis-ci.org/philippbosch/django-geoposition

.. image:: https://badges.gitter.im/philippbosch/django-geoposition.svg
:alt: Join the chat at https://gitter.im/philippbosch/django-geoposition
:target: https://gitter.im/philippbosch/django-geoposition?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

Prerequisites
-------------
Expand Down
5 changes: 2 additions & 3 deletions geoposition/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import unicode_literals

from django.db import models
from django.utils.six import with_metaclass
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_text

Expand Down Expand Up @@ -40,14 +39,14 @@ def to_python(self, value):

return Geoposition(latitude, longitude)

def from_db_value(self, value, expression, connection, context):
def from_db_value(self, value, expression, connection):
return self.to_python(value)

def get_prep_value(self, value):
return str(value)

def value_to_string(self, obj):
value = self._get_val_from_obj(obj)
value = self.value_from_object(obj)
return smart_text(value)

def formfield(self, **kwargs):
Expand Down
18 changes: 17 additions & 1 deletion geoposition/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'example',
)

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand All @@ -38,6 +38,22 @@
}
}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
Expand Down
11 changes: 6 additions & 5 deletions geoposition/tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.conf.urls import patterns, include, url
from django.urls import path, include
from django.contrib import admin
from example.views import poi_list

admin.autodiscover()

urlpatterns = patterns('',
url(r'^$', 'example.views.poi_list'),
url(r'^admin/', include(admin.site.urls)),
)
urlpatterns = [
path('', poi_list),
path('admin/', admin.site.urls),
]
3 changes: 1 addition & 2 deletions geoposition/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
from django import forms
from django.template.loader import render_to_string
from django.utils import six
from django.utils.translation import ugettext_lazy as _
from .conf import settings

Expand All @@ -17,7 +16,7 @@ def __init__(self, attrs=None):
super(GeopositionWidget, self).__init__(widgets, attrs)

def decompress(self, value):
if isinstance(value, six.text_type):
if isinstance(value, str):
return value.rsplit(',')
if value:
return [value.latitude, value.longitude]
Expand Down
96 changes: 8 additions & 88 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,16 @@
# Then call "tox" from this directory to run the test suite for all configurations.

[tox]
envlist = py2.6_django1.4.13,
py2.6_django1.5,
py2.6_django1.5.8,
py2.6_django1.6,
py2.6_django1.6.5,
py2.7_django1.4.13,
py2.7_django1.5,
py2.7_django1.5.8,
py2.7_django1.6,
py2.7_django1.6.5,
py3.3_django1.5,
py3.3_django1.5.8,
py3.3_django1.6,
py3.3_django1.6.5,
py3.4_django1.5,
py3.4_django1.5.8,
py3.4_django1.6,
py3.4_django1.6.5
envlist = py3.6_django3.0.1,
py3.6_django2.2.9,

[testenv]
commands = {envpython} manage.py test geoposition

[testenv:py2.6_django1.4.13]
basepython = python2.6
deps = Django==1.4.13
[testenv:py3.6_django2.2.9]
basepython = python3.6
deps = Django==2.2.9

[testenv:py2.6_django1.5]
basepython = python2.6
deps = Django==1.5

[testenv:py2.6_django1.5.8]
basepython = python2.6
deps = Django==1.5.8

[testenv:py2.6_django1.6]
basepython = python2.6
deps = Django==1.6

[testenv:py2.6_django1.6.1]
basepython = python2.6
deps = Django==1.6.5

[testenv:py2.7_django1.4.13]
basepython = python2.7
deps = Django==1.4.13

[testenv:py2.7_django1.5]
basepython = python2.7
deps = Django==1.5

[testenv:py2.7_django1.5.8]
basepython = python2.7
deps = Django==1.5.8

[testenv:py2.7_django1.6]
basepython = python2.7
deps = Django==1.6

[testenv:py2.7_django1.6.1]
basepython = python2.7
deps = Django==1.6.5

[testenv:py3.3_django1.5]
basepython = python3.3
deps = Django==1.5

[testenv:py3.3_django1.5.8]
basepython = python3.3
deps = Django==1.5.8

[testenv:py3.3_django1.6]
basepython = python3.3
deps = Django==1.6

[testenv:py3.3_django1.6.1]
basepython = python3.3
deps = Django==1.6.5

[testenv:py3.4_django1.5]
basepython = python3.4
deps = Django==1.5

[testenv:py3.4_django1.5.8]
basepython = python3.4
deps = Django==1.5.8

[testenv:py3.4_django1.6]
basepython = python3.4
deps = Django==1.6

[testenv:py3.4_django1.6.1]
basepython = python3.4
deps = Django==1.6.5
[testenv:py3.6_django3.0.1]
basepython = python3.6
deps = Django==3.0.1