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

update urls.py - RemovedInDjango110Warning #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 22 additions & 6 deletions tastypie_swagger/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
from django import __version__ as django_version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably cleaner to call get_version

try:
from django.conf.urls import patterns, include, url
except ImportError:
from django.conf.urls.defaults import patterns, include, url
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not working in Django 1.10: first import ImportError: cannot import name patterns, second ImportError: No module named defaults.


from .views import SwaggerView, ResourcesView, SchemaView

urlpatterns = patterns('',
url(r'^$', SwaggerView.as_view(), name='index'),
url(r'^resources/$', ResourcesView.as_view(), name='resources'),
url(r'^schema/(?P<resource>\S+)$', SchemaView.as_view()),
url(r'^schema/$', SchemaView.as_view(), name='schema'),
)
django_version = django_version.split('.')
main_ver = int(django_version)[0]
secondary_ver = int(django_version)[1]

if main_ver == 1 and secondary_ver < 9:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something something use StrictVersion instead.

In [1]: from distutils.version import StrictVersion

In [2]: StrictVersion("1.9")
Out[2]: StrictVersion ('1.9')

In [3]: StrictVersion("1.9") > StrictVersion("1.8")
Out[3]: True

In [4]: StrictVersion("1.9") > StrictVersion("1.10")
Out[4]: False

urlpatterns = patterns('',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something something DRY. Declare urlpatterns as a list and then if the version check is earlier than 1.8 (which is when it was deprecated) wrap it in patterns('', *urlpatterns)

url(r'^$', SwaggerView.as_view(), name='index'),
url(r'^resources/$', ResourcesView.as_view(), name='resources'),
url(r'^schema/(?P<resource>\S+)$', SchemaView.as_view()),
url(r'^schema/$', SchemaView.as_view(), name='schema'),
)
else:
# RemovedInDjango110Warning:
# django.conf.urls.patterns() is deprecated and will be removed in Django 1.10.
# Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
urlpatterns = [
url(r'^$', SwaggerView.as_view(), name='index'),
url(r'^resources/$', ResourcesView.as_view(), name='resources'),
url(r'^schema/(?P<resource>\S+)$', SchemaView.as_view()),
url(r'^schema/$', SchemaView.as_view(), name='schema')
]