Skip to content

Commit 0074e46

Browse files
author
Colin Ross
authored
Merge pull request #5 from TwigWorld/py_upgrade
Py upgrade
2 parents 65cb290 + 4c14b89 commit 0074e46

File tree

9 files changed

+173
-130
lines changed

9 files changed

+173
-130
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
*.py[cod]
2-
.coverage
2+
.coverage
3+
4+
# pycharm
5+
.idea/
6+
7+
# pyenv
8+
.python-version

runtests.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import django
2+
13
from django.conf import settings
24
from django.core.management import call_command
35

@@ -16,18 +18,30 @@
1618
'django.contrib.sites',
1719
'urlmapper'
1820
),
21+
1922
STATIC_URL='/',
2023
MIDDLEWARE_CLASSES=(
2124
'django.contrib.sessions.middleware.SessionMiddleware',
2225
'django.middleware.common.CommonMiddleware',
2326
),
24-
ROOT_URLCONF=('urlmapper.tests.urls'),
27+
ROOT_URLCONF='urlmapper.tests.urls',
2528
SITE_ID=1,
26-
TEMPLATE_CONTEXT_PROCESSORS=(
27-
'django.contrib.auth.context_processors.auth',
28-
'django.core.context_processors.i18n',
29-
'django.core.context_processors.request',
30-
),
29+
30+
TEMPLATES=[
31+
{
32+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
33+
'APP_DIRS': True,
34+
'OPTIONS': {
35+
'context_processors': [
36+
'django.template.context_processors.debug',
37+
'django.template.context_processors.request',
38+
'django.contrib.auth.context_processors.auth',
39+
'django.contrib.messages.context_processors.messages',
40+
],
41+
},
42+
},
43+
],
44+
3145
URLMAPPER_KEYS=[
3246
'test_1',
3347
'test_2',
@@ -40,5 +54,6 @@
4054
'test_2': lambda request: 'test_2_success'
4155
},
4256
)
57+
django.setup()
4358

4459
call_command('test')

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from setuptools import setup, find_packages
22

3-
43
setup(
54
name='django-url-mapper',
6-
version='1.0.1',
5+
version='2.0.0',
76
author='Colin Barnwell',
87
scripts=[],
98
description='Use fixed keys in your Django template to refer to dynamic URLs',
109
long_description=open('README.md').read(),
10+
python_requires='>=3.7.0',
1111
install_requires=[
12-
"Django >= 1.6",
12+
"Django>=1.11.29, <2.0",
1313
],
1414
packages=find_packages(),
1515
include_package_data=True

urlmapper/admin.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
from django.contrib import admin
22
from django.utils.translation import ugettext_lazy as _
33

4-
from models import URLMap
4+
from .models import URLMap
55

6-
import settings
6+
from .settings import URLMAPPER_ALLOWED_MAPPINGS
77

88

99
class URLMapAdmin(admin.ModelAdmin):
10-
1110
list_display = ('key', 'mapping_type', 'get_url')
1211

1312
fieldsets = [(None, {'fields': ('key',)})]
14-
if 'url' in settings.URLMAPPER_ALLOWED_MAPPINGS:
13+
if 'url' in URLMAPPER_ALLOWED_MAPPINGS:
1514
fieldsets.append((_("URL mapping"), {'fields': ('url',)}))
16-
if 'object' in settings.URLMAPPER_ALLOWED_MAPPINGS:
15+
if 'object' in URLMAPPER_ALLOWED_MAPPINGS:
1716
fieldsets.append((_("Object mapping"), {'fields': ('content_type', 'object_id')}))
18-
if 'view_name' in settings.URLMAPPER_ALLOWED_MAPPINGS:
17+
if 'view_name' in URLMAPPER_ALLOWED_MAPPINGS:
1918
fieldsets.append((_("View mapping"), {'fields': ('view_name', 'view_keywords')}))
2019

2120

urlmapper/helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from models import URLMap
2-
from django.conf import settings
1+
from urlmapper import settings
2+
3+
from .models import URLMap
34

45

56
def get_mapped_url(key, request=None):
@@ -21,7 +22,7 @@ def get_mapped_url(key, request=None):
2122
return settings.URLMAPPER_FUNCTIONS[key](request)
2223
except TypeError:
2324
return settings.URLMAPPER_FUNCTIONS[key]()
24-
except Exception, e:
25+
except Exception as e:
2526
if settings.URLMAPPER_RAISE_EXCEPTION:
2627
raise e
2728
return ''
@@ -39,8 +40,8 @@ def check_mapped_url(key):
3940
return bool(
4041
key in settings.URLMAPPER_KEYS
4142
and (
42-
key in settings.URLMAPPER_FUNCTIONS
43-
or URLMap.objects.filter(key=key).exists()
43+
key in settings.URLMAPPER_FUNCTIONS
44+
or URLMap.objects.filter(key=key).exists()
4445
)
4546
and get_mapped_url(key)
4647
)

urlmapper/models.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
from django.contrib.contenttypes.generic import GenericForeignKey
1+
from __future__ import unicode_literals
2+
3+
from django.contrib.contenttypes.fields import GenericForeignKey
24
from django.core.exceptions import ValidationError
35
from django.core.urlresolvers import reverse, resolve, NoReverseMatch, Resolver404
46
from django.db import models
57
from django.utils.translation import ugettext_lazy as _, ugettext
8+
# django/py3
9+
from django.utils.encoding import python_2_unicode_compatible
610

7-
import settings
11+
from urlmapper import settings
812

913

1014
def _get_key_choices():
@@ -16,7 +20,8 @@ def _get_key_choices():
1620
)
1721
if not keys:
1822
return [('', ugettext("There are no defined keys"))]
19-
return zip(keys, keys)
23+
24+
return list(zip(keys, keys))
2025

2126

2227
def _get_content_type_choices():
@@ -38,6 +43,7 @@ def get_queryset(self):
3843
return queryset.exclude(key__in=settings.URLMAPPER_FUNCTIONS.keys())
3944

4045

46+
@python_2_unicode_compatible
4147
class URLMap(models.Model):
4248
"""
4349
Map a key to a URL in the database. This could be a straight-up URL, an
@@ -91,7 +97,7 @@ class URLMap(models.Model):
9197
objects = URLMapVisibleMananger()
9298
_objects = models.Manager()
9399

94-
def __unicode__(self):
100+
def __str__(self):
95101
return u"{key} --> {url}".format(
96102
key=self.key,
97103
url=self.get_url()
@@ -223,6 +229,7 @@ def get_url(self):
223229
if self.view_name:
224230
return self._get_view_url(raise_exception=False)
225231
return ''
232+
226233
get_url.short_description = _('URL')
227234

228235
def mapping_type(self):
@@ -232,6 +239,7 @@ def mapping_type(self):
232239
return _("Object")
233240
if self.view_name:
234241
return _("View")
242+
235243
mapping_type.short_description = _("Mapping type")
236244

237245
class Meta:

urlmapper/tests/test_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from importlib import reload
2+
13
from django.test import TestCase
24

35
from ..helpers import get_mapped_url, check_mapped_url

0 commit comments

Comments
 (0)