From 6fa825e372942dbc9f3733ffdac888d44f862ec5 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 20 Jul 2020 16:03:55 +0200 Subject: [PATCH] providers/*: remove path-based import from all providers --- passbook/core/models.py | 4 ++++ passbook/providers/app_gw/models.py | 8 ++++++-- passbook/providers/oauth/models.py | 8 ++++++-- passbook/providers/oidc/models.py | 8 ++++++-- passbook/providers/saml/models.py | 8 ++++++-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/passbook/core/models.py b/passbook/core/models.py index ad91b616c..fb29c1c64 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -93,6 +93,10 @@ class Provider(models.Model): objects = InheritanceManager() + def form(self) -> Type[ModelForm]: + """Return Form class used to edit this object""" + raise NotImplementedError + # This class defines no field for easier inheritance def __str__(self): if hasattr(self, "name"): diff --git a/passbook/providers/app_gw/models.py b/passbook/providers/app_gw/models.py index efacbafb9..88771ae7c 100644 --- a/passbook/providers/app_gw/models.py +++ b/passbook/providers/app_gw/models.py @@ -1,9 +1,10 @@ """passbook app_gw models""" import string from random import SystemRandom -from typing import Optional +from typing import Optional, Type from django.db import models +from django.forms import ModelForm from django.http import HttpRequest from django.utils.translation import gettext as _ from oidc_provider.models import Client @@ -23,7 +24,10 @@ class ApplicationGatewayProvider(Provider): client = models.ForeignKey(Client, on_delete=models.CASCADE) - form = "passbook.providers.app_gw.forms.ApplicationGatewayProviderForm" + def form(self) -> Type[ModelForm]: + from passbook.providers.app_gw.forms import ApplicationGatewayProviderForm + + return ApplicationGatewayProviderForm def html_setup_urls(self, request: HttpRequest) -> Optional[str]: """return template and context modal with URLs for authorize, token, openid-config, etc""" diff --git a/passbook/providers/oauth/models.py b/passbook/providers/oauth/models.py index fe0167d98..f1a9ad522 100644 --- a/passbook/providers/oauth/models.py +++ b/passbook/providers/oauth/models.py @@ -1,7 +1,8 @@ """Oauth2 provider product extension""" -from typing import Optional +from typing import Optional, Type +from django.forms import ModelForm from django.http import HttpRequest from django.shortcuts import reverse from django.utils.translation import gettext as _ @@ -16,7 +17,10 @@ class OAuth2Provider(Provider, AbstractApplication): This Provider also supports the GitHub-pretend mode for Applications that don't support generic OAuth.""" - form = "passbook.providers.oauth.forms.OAuth2ProviderForm" + def form(self) -> Type[ModelForm]: + from passbook.providers.oauth.forms import OAuth2ProviderForm + + return OAuth2ProviderForm def __str__(self): return self.name diff --git a/passbook/providers/oidc/models.py b/passbook/providers/oidc/models.py index 5774d7201..6f74ccb53 100644 --- a/passbook/providers/oidc/models.py +++ b/passbook/providers/oidc/models.py @@ -1,7 +1,8 @@ """oidc models""" -from typing import Optional +from typing import Optional, Type from django.db import models +from django.forms import ModelForm from django.http import HttpRequest from django.shortcuts import reverse from django.utils.translation import gettext as _ @@ -20,7 +21,10 @@ class OpenIDProvider(Provider): oidc_client = models.OneToOneField(Client, on_delete=models.CASCADE) - form = "passbook.providers.oidc.forms.OIDCProviderForm" + def form(self) -> Type[ModelForm]: + from passbook.providers.oidc.forms import OIDCProviderForm + + return OIDCProviderForm @property def name(self): diff --git a/passbook/providers/saml/models.py b/passbook/providers/saml/models.py index 56b6a8c74..2e7bd68f4 100644 --- a/passbook/providers/saml/models.py +++ b/passbook/providers/saml/models.py @@ -1,7 +1,8 @@ """passbook saml_idp Models""" -from typing import Optional +from typing import Optional, Type from django.db import models +from django.forms import ModelForm from django.http import HttpRequest from django.shortcuts import reverse from django.utils.translation import ugettext_lazy as _ @@ -101,7 +102,10 @@ class SAMLProvider(Provider): ), ) - form = "passbook.providers.saml.forms.SAMLProviderForm" + def form(self) -> Type[ModelForm]: + from passbook.providers.saml.forms import SAMLProviderForm + + return SAMLProviderForm def __str__(self): return self.name