Skip to content

Commit bc763ed

Browse files
author
Massimiliano
committed
using get_application_model
1 parent 1a06c74 commit bc763ed

File tree

11 files changed

+42
-18
lines changed

11 files changed

+42
-18
lines changed

oauth2_provider/forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django import forms
22

3-
from .models import Application
3+
from .models import get_application_model
44

55

66
class AllowForm(forms.Form):
@@ -17,5 +17,5 @@ class RegistrationForm(forms.ModelForm):
1717
TODO: add docstring
1818
"""
1919
class Meta:
20-
model = Application
20+
model = get_application_model()
2121
fields = ('name', 'client_id', 'client_secret', 'client_type', 'authorization_grant_type', 'redirect_uris')

oauth2_provider/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def clean(self):
9696
from django.core.exceptions import ValidationError
9797
if not self.redirect_uris \
9898
and self.authorization_grant_type \
99-
in (Application.GRANT_ALLINONE,
100-
Application.GRANT_AUTHORIZATION_CODE,
101-
Application.GRANT_IMPLICIT):
99+
in (AbstractApplication.GRANT_ALLINONE,
100+
AbstractApplication.GRANT_AUTHORIZATION_CODE,
101+
AbstractApplication.GRANT_IMPLICIT):
102102
error = _('Redirect_uris could not be empty with {} grant_type')
103103
raise ValidationError(error.format(self.authorization_grant_type))
104104

@@ -131,7 +131,7 @@ class Grant(models.Model):
131131
"""
132132
user = models.ForeignKey(User)
133133
code = models.CharField(max_length=255) # code comes from oauthlib
134-
application = models.ForeignKey(Application)
134+
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL)
135135
expires = models.DateTimeField()
136136
redirect_uri = models.CharField(max_length=255)
137137
scope = models.TextField(blank=True)
@@ -166,7 +166,7 @@ class AccessToken(models.Model):
166166
"""
167167
user = models.ForeignKey(User)
168168
token = models.CharField(max_length=255)
169-
application = models.ForeignKey(Application)
169+
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL)
170170
expires = models.DateTimeField()
171171
scope = models.TextField(blank=True)
172172

@@ -218,7 +218,7 @@ class RefreshToken(models.Model):
218218
"""
219219
user = models.ForeignKey(User)
220220
token = models.CharField(max_length=255)
221-
application = models.ForeignKey(Application)
221+
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL)
222222
access_token = models.OneToOneField(AccessToken,
223223
related_name='refresh_token')
224224

oauth2_provider/tests/test_application_views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
from django.test import TestCase
55

66
from ..compat import get_user_model
7-
from ..models import Application
7+
from ..models import get_application_model
8+
9+
10+
Application = get_application_model()
811

912

1013
class BaseTest(TestCase):

oauth2_provider/tests/test_authorization_code.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
from django.utils import timezone
88

99
from ..compat import urlparse, parse_qs, urlencode, get_user_model
10-
from ..models import Application, Grant
10+
from ..models import get_application_model, Grant
1111
from ..settings import oauth2_settings
1212
from ..views import ProtectedResourceView
1313

1414
from .test_utils import TestCaseUtils
1515

1616

17+
Application = get_application_model()
18+
19+
1720
# mocking a protected resource view
1821
class ResourceView(ProtectedResourceView):
1922
def get(self, request, *args, **kwargs):

oauth2_provider/tests/test_client_credential.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
from oauthlib.oauth2 import BackendApplicationServer
1010

1111
from ..compat import get_user_model
12-
from ..models import Application
12+
from ..models import get_application_model
1313
from ..oauth2_validators import OAuth2Validator
1414
from ..settings import oauth2_settings
1515
from ..views import ProtectedResourceView
1616
from ..views.mixins import OAuthLibMixin
1717
from .test_utils import TestCaseUtils
1818

1919

20+
Application = get_application_model()
21+
22+
2023
# mocking a protected resource view
2124
class ResourceView(ProtectedResourceView):
2225
def get(self, request, *args, **kwargs):

oauth2_provider/tests/test_implicit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
from django.core.urlresolvers import reverse
55

66
from ..compat import urlparse, parse_qs, urlencode, get_user_model
7-
from ..models import Application
7+
from ..models import get_application_model
88
from ..settings import oauth2_settings
99
from ..views import ProtectedResourceView
1010

1111

12+
Application = get_application_model()
13+
14+
1215
# mocking a protected resource view
1316
class ResourceView(ProtectedResourceView):
1417
def get(self, request, *args, **kwargs):

oauth2_provider/tests/test_models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
from django.core.exceptions import ValidationError
55

66
from ..compat import get_user_model
7-
from ..models import AccessToken, Application
7+
from ..models import AccessToken, get_application_model
8+
9+
10+
Application = get_application_model()
811

912

1013
class TestModels(TestCase):

oauth2_provider/tests/test_password.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
from django.core.urlresolvers import reverse
77

88
from ..compat import get_user_model
9-
from ..models import Application
9+
from ..models import get_application_model
1010
from ..settings import oauth2_settings
1111
from ..views import ProtectedResourceView
1212

1313
from .test_utils import TestCaseUtils
1414

1515

16+
Application = get_application_model()
17+
18+
1619
# mocking a protected resource view
1720
class ResourceView(ProtectedResourceView):
1821
def get(self, request, *args, **kwargs):

oauth2_provider/tests/test_rest_framework.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88

99
from .test_utils import TestCaseUtils
1010
from ..compat import get_user_model
11-
from ..models import AccessToken, Application
11+
from ..models import AccessToken, get_application_model
1212
from ..settings import oauth2_settings
1313

1414

15+
Application = get_application_model()
16+
17+
1518
try:
1619
from rest_framework import permissions
1720
from rest_framework.views import APIView

oauth2_provider/tests/test_scopes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
from django.core.urlresolvers import reverse
88

99
from ..compat import urlparse, parse_qs, get_user_model
10-
from ..models import Application, Grant, AccessToken
10+
from ..models import get_application_model, Grant, AccessToken
1111
from ..settings import oauth2_settings
1212
from ..views import ScopedProtectedResourceView, ReadWriteScopedResourceView
1313

1414
from .test_utils import TestCaseUtils
1515

1616

17+
Application = get_application_model()
18+
19+
1720
# mocking a protected resource view
1821
class ScopeResourceView(ScopedProtectedResourceView):
1922
required_scopes = ['scope1']

0 commit comments

Comments
 (0)