Skip to content

Commit 3cc442e

Browse files
committed
Upgrade code to Python 3.6+, Django 2.2 and remove deprecations
1 parent 08d3c0a commit 3cc442e

File tree

12 files changed

+10
-33
lines changed

12 files changed

+10
-33
lines changed

easy_maps/admin.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from django import forms
42
from django.contrib import admin
53
from django.utils.translation import gettext_lazy as _

easy_maps/conf.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from django.conf import settings # pylint: disable=W0611
42

53
from appconf import AppConf

easy_maps/geocode.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from django.utils.encoding import smart_str
42

53
from geopy import geocoders

easy_maps/migrations/0001_initial.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
41
from django.db import migrations, models
52

63

easy_maps/models.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import logging
42
import sys
53

@@ -79,7 +77,7 @@ def fetch(self):
7977
except Exception:
8078
logger.error("Geocoding error for address '%s'", address)
8179

82-
self.exception = "{0.__name__}: {1}".format(sys.exc_info()[0], sys.exc_info()[1])
80+
self.exception = f"{sys.exc_info()[0].__name__}: {sys.exc_info()[1]}"
8381

8482
def has_exception(self):
8583
return bool(self.exception)
@@ -94,4 +92,4 @@ def save(self, *args, **kwargs):
9492
if (self.longitude is None) or (self.latitude is None):
9593
self.fetch()
9694

97-
super(Address, self).save(*args, **kwargs)
95+
super().save(*args, **kwargs)

easy_maps/templatetags/easy_maps_tags.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from django import template
42
from django.core.exceptions import ImproperlyConfigured
53

@@ -50,7 +48,7 @@ class EasyMapTag(InclusionTag):
5048
)
5149

5250
def render_tag(self, context, **kwargs):
53-
params = dict((k, v) for k, v in kwargs.items() if v and k not in ["template_name"])
51+
params = {k: v for k, v in kwargs.items() if v and k not in ["template_name"]}
5452
if "address" in params and (len(params) == 2 or len(params) > 4):
5553
raise template.TemplateSyntaxError(
5654
"easy_map tag has the following syntax: "
@@ -62,7 +60,7 @@ def render_tag(self, context, **kwargs):
6260
"easy_map tag requires EASY_MAPS_GOOGLE_KEY to be set in global settings "
6361
"because of the restrictions introduced in Google Maps API v3 by Google, Inc."
6462
)
65-
return super(EasyMapTag, self).render_tag(context, **kwargs)
63+
return super().render_tag(context, **kwargs)
6664

6765
def get_template(self, context, **kwargs):
6866
return kwargs.get("template_name", None) or self.template

easy_maps/tests/conftest.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
Dummy conftest.py for easi_maps.
43
If you don't know what this is for, just leave it empty.
54
Read more about conftest.py under:
65
https://pytest.org/latest/plugins.html
76
"""
8-
from __future__ import print_function, absolute_import, division
97

108
import pytest

easy_maps/tests/settings.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
42
import os
53
import re

easy_maps/tests/test_templatetags.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
3-
import mock
1+
from unittest import mock
42

53
from django import template
64
from django.test import TestCase

easy_maps/utils.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from django.core.exceptions import ImproperlyConfigured
42

53

@@ -30,7 +28,7 @@ def importpath(path, error_text=None):
3028
result = getattr(result, attr)
3129
except (AttributeError, ValueError) as e:
3230
if error_text is not None:
33-
raise ImproperlyConfigured('Error: %s can import "%s"' % (error_text, path))
31+
raise ImproperlyConfigured(f'Error: {error_text} can import "{path}"')
3432
else:
3533
raise exception
3634
return result

easy_maps/widgets.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from django import template
42
from django.forms import TextInput
53

@@ -12,7 +10,7 @@ class AddressWithMapWidget(TextInput):
1210
tpl = "{{% load easy_maps_tags %}}{{% easy_map address {0.width} {0.height} {0.zoom} %}}"
1311

1412
def render(self, name, value, attrs=None, renderer=None):
15-
output = super(AddressWithMapWidget, self).render(name, value, attrs, renderer)
13+
output = super().render(name, value, attrs, renderer)
1614

1715
t = template.Template(self.tpl.format(self))
1816
context = template.Context(

example/urls.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from django.conf.urls import url
1+
from django.urls import path
22
from django.contrib import admin
33
from django.views.generic import TemplateView
44

55
admin.autodiscover()
66

77
urlpatterns = [
8-
url(r"^admin/", admin.site.urls),
8+
path('admin/', admin.site.urls),
99
]
1010

1111
urlpatterns += [
12-
url(r"^$", TemplateView.as_view(template_name="index.html")),
12+
path('', TemplateView.as_view(template_name="index.html")),
1313
]

0 commit comments

Comments
 (0)