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

Fix/django version #4

Closed
wants to merge 5 commits into from
Closed
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
Binary file removed .DS_Store
Binary file not shown.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

.idea/

*.pyc

.tox/

build/*

dist/*

env/*

.DS_Store
21 changes: 15 additions & 6 deletions django2_url_robots/utils.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import sre_parse
from django import get_version
from distutils.version import StrictVersion
from sre_constants import LITERAL, AT, AT_END

_NEWEST_DJANGO = StrictVersion(get_version()) >= StrictVersion('2.0')

try:
# Python 3
from urllib.parse import quote, unquote

unichr = chr
except ImportError:
# Python 2
from urllib import quote, unquote

from django.conf.urls import url

try:
from django.core.urlresolvers import get_urlconf, get_resolver, RegexURLResolver
from django.conf.urls import url
except ImportError:
from django.urls import get_urlconf, get_resolver
from django.urls import URLResolver
from django.urls import get_urlconf, get_resolver, URLResolver
from django.urls import path, re_path


def robots_decorator(url_function):
"""
Decorator for django.conf.urls.url
"""

def url_extended(regex, view, kwargs=None, name=None, robots_allow=None):
resolver_or_pattern = url_function(regex, view, kwargs=kwargs, name=name)

Expand All @@ -31,7 +36,11 @@ def url_extended(regex, view, kwargs=None, name=None, robots_allow=None):
return url_extended


url = robots_decorator(url)
if _NEWEST_DJANGO is True:
path = robots_decorator(path)
re_path = robots_decorator(re_path)
else:
url = robots_decorator(url)


def create_rules(urlconf=None):
Expand Down Expand Up @@ -132,4 +141,4 @@ def clean_pattern(pattern):
else:
rule += star

return rule
return rule