Skip to content

Commit e8e7980

Browse files
committed
removed old compatibility code for django < 1.8
1 parent 63230fd commit e8e7980

24 files changed

+47
-88
lines changed

oauth2_provider/backends.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from .compat import get_user_model
1+
from django.contrib.auth import get_user_model
2+
23
from .oauth2_backends import get_oauthlib_core
34

5+
46
UserModel = get_user_model()
57
OAuthLibCore = get_oauthlib_core()
68

oauth2_provider/compat.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
"""
22
The `compat` module provides support for backwards compatibility with older
3-
versions of django and python..
3+
versions of django and python.
44
"""
55
# flake8: noqa
66
from __future__ import unicode_literals
77

8-
import django
9-
from django.conf import settings
10-
118
# urlparse in python3 has been renamed to urllib.parse
129
try:
1310
from urlparse import urlparse, parse_qs, parse_qsl, urlunparse
@@ -18,28 +15,3 @@
1815
from urllib import urlencode, unquote_plus
1916
except ImportError:
2017
from urllib.parse import urlencode, unquote_plus
21-
22-
# Django 1.5 add support for custom auth user model
23-
if django.VERSION >= (1, 5):
24-
AUTH_USER_MODEL = settings.AUTH_USER_MODEL
25-
else:
26-
AUTH_USER_MODEL = 'auth.User'
27-
28-
try:
29-
from django.contrib.auth import get_user_model
30-
except ImportError:
31-
from django.contrib.auth.models import User
32-
get_user_model = lambda: User
33-
34-
# Django's new application loading system
35-
try:
36-
from django.apps import apps
37-
get_model = apps.get_model
38-
except ImportError:
39-
from django.db.models import get_model
40-
41-
# Django 1.5 add the support of context variables for the url template tag
42-
if django.VERSION >= (1, 5):
43-
from django.template.defaulttags import url
44-
else:
45-
from django.templatetags.future import url

oauth2_provider/models.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from datetime import timedelta
44

5+
from django.apps import apps
6+
from django.conf import settings
57
from django.core.urlresolvers import reverse
68
from django.db import models, transaction
79
from django.utils import timezone
@@ -11,7 +13,7 @@
1113
from django.core.exceptions import ImproperlyConfigured
1214

1315
from .settings import oauth2_settings
14-
from .compat import AUTH_USER_MODEL, parse_qsl, urlparse, get_model
16+
from .compat import parse_qsl, urlparse
1517
from .generators import generate_client_secret, generate_client_id
1618
from .validators import validate_uris
1719

@@ -57,7 +59,7 @@ class AbstractApplication(models.Model):
5759

5860
client_id = models.CharField(max_length=100, unique=True,
5961
default=generate_client_id, db_index=True)
60-
user = models.ForeignKey(AUTH_USER_MODEL, related_name="%(app_label)s_%(class)s")
62+
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="%(app_label)s_%(class)s")
6163
help_text = _("Allowed URIs list, space separated")
6264
redirect_uris = models.TextField(help_text=help_text,
6365
validators=[validate_uris], blank=True)
@@ -146,7 +148,7 @@ class Grant(models.Model):
146148
* :attr:`redirect_uri` Self explained
147149
* :attr:`scope` Required scopes, optional
148150
"""
149-
user = models.ForeignKey(AUTH_USER_MODEL)
151+
user = models.ForeignKey(settings.AUTH_USER_MODEL)
150152
code = models.CharField(max_length=255, db_index=True) # code comes from oauthlib
151153
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL)
152154
expires = models.DateTimeField()
@@ -183,7 +185,7 @@ class AccessToken(models.Model):
183185
* :attr:`expires` Date and time of token expiration, in DateTime format
184186
* :attr:`scope` Allowed scopes
185187
"""
186-
user = models.ForeignKey(AUTH_USER_MODEL, blank=True, null=True)
188+
user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True)
187189
token = models.CharField(max_length=255, db_index=True)
188190
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL)
189191
expires = models.DateTimeField()
@@ -252,7 +254,7 @@ class RefreshToken(models.Model):
252254
* :attr:`access_token` AccessToken instance this refresh token is
253255
bounded to
254256
"""
255-
user = models.ForeignKey(AUTH_USER_MODEL)
257+
user = models.ForeignKey(settings.AUTH_USER_MODEL)
256258
token = models.CharField(max_length=255, db_index=True)
257259
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL)
258260
access_token = models.OneToOneField(AccessToken,
@@ -276,7 +278,7 @@ def get_application_model():
276278
except ValueError:
277279
e = "APPLICATION_MODEL must be of the form 'app_label.model_name'"
278280
raise ImproperlyConfigured(e)
279-
app_model = get_model(app_label, model_name)
281+
app_model = apps.get_model(app_label, model_name)
280282
if app_model is None:
281283
e = "APPLICATION_MODEL refers to model {0} that has not been installed"
282284
raise ImproperlyConfigured(e.format(oauth2_settings.APPLICATION_MODEL))

oauth2_provider/templates/oauth2_provider/application_confirm_delete.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{% extends "oauth2_provider/base.html" %}
22

33
{% load i18n %}
4-
{% load url from compat %}
54
{% block content %}
65
<div class="block-center">
76
<h3 class="block-center-heading">{% trans "Are you sure to delete the application" %} {{ application.name }}?</h3>
@@ -16,4 +15,4 @@ <h3 class="block-center-heading">{% trans "Are you sure to delete the applicatio
1615
</div>
1716
</form>
1817
</div>
19-
{% endblock content %}
18+
{% endblock content %}

oauth2_provider/templates/oauth2_provider/application_detail.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{% extends "oauth2_provider/base.html" %}
22

33
{% load i18n %}
4-
{% load url from compat %}
54
{% block content %}
65
<div class="block-center">
76
<h3 class="block-center-heading">{{ application.name }}</h3>
@@ -39,4 +38,4 @@ <h3 class="block-center-heading">{{ application.name }}</h3>
3938
<a class="btn btn-danger" href="{% url "oauth2_provider:delete" application.id %}">{% trans "Delete" %}</a>
4039
</div>
4140
</div>
42-
{% endblock content %}
41+
{% endblock content %}

oauth2_provider/templates/oauth2_provider/application_form.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{% extends "oauth2_provider/base.html" %}
22

33
{% load i18n %}
4-
{% load url from compat %}
54
{% block content %}
65
<div class="block-center">
76
<form class="form-horizontal" method="post" action="{% block app-form-action-url %}{% url 'oauth2_provider:update' application.id %}{% endblock app-form-action-url %}">
@@ -40,4 +39,4 @@ <h3 class="block-center-heading">
4039
</div>
4140
</form>
4241
</div>
43-
{% endblock %}
42+
{% endblock %}

oauth2_provider/templates/oauth2_provider/application_list.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{% extends "oauth2_provider/base.html" %}
22

33
{% load i18n %}
4-
{% load url from compat %}
54
{% block content %}
65
<div class="block-center">
76
<h3 class="block-center-heading">{% trans "Your applications" %}</h3>
@@ -17,4 +16,4 @@ <h3 class="block-center-heading">{% trans "Your applications" %}</h3>
1716
<p>{% trans "No applications defined" %}. <a href="{% url 'oauth2_provider:register' %}">{% trans "Click here" %}</a> {% trans "if you want to register a new one" %}</p>
1817
{% endif %}
1918
</div>
20-
{% endblock content %}
19+
{% endblock content %}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{% extends "oauth2_provider/application_form.html" %}
22

33
{% load i18n %}
4-
{% load url from compat %}
54

65
{% block app-form-title %}{% trans "Register a new application" %}{% endblock app-form-title %}
76

87
{% block app-form-action-url %}{% url 'oauth2_provider:register' %}{% endblock app-form-action-url %}
98

10-
{% block app-form-back-url %}{% url "oauth2_provider:list" %}"{% endblock app-form-back-url %}
9+
{% block app-form-back-url %}{% url "oauth2_provider:list" %}"{% endblock app-form-back-url %}

oauth2_provider/templates/oauth2_provider/authorized-tokens.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{% extends "oauth2_provider/base.html" %}
22

33
{% load i18n %}
4-
{% load url from compat %}
54
{% block content %}
65
<div class="block-center">
76
<h1>{% trans "Tokens" %}</h1>

oauth2_provider/templatetags/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)