django4: fix default AppConfig deprecation warnings (#68576)

This commit is contained in:
Agate 2022-08-31 10:40:03 +02:00
parent ff6c68b21c
commit fdfad9a78a
6 changed files with 51 additions and 55 deletions

View File

@ -13,5 +13,3 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
default_app_config = 'passerelle.apps.cmis.apps.CmisAppConfig'

View File

@ -13,18 +13,3 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
class AppConfig(django.apps.AppConfig):
name = 'passerelle.apps.csvdatasource'
label = 'csvdatasource'
def get_connector_model(self):
from . import models
return models.CsvDataSource
default_app_config = 'passerelle.apps.csvdatasource.AppConfig'

View File

@ -0,0 +1,11 @@
import django.apps
class AppConfig(django.apps.AppConfig):
name = 'passerelle.apps.csvdatasource'
label = 'csvdatasource'
def get_connector_model(self):
from . import models
return models.CsvDataSource

View File

@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.apps import apps
from django.utils.module_loading import import_string
@ -38,37 +37,3 @@ class ConnectorAppMixin:
class ConnectorAppConfig(ConnectorAppMixin, django.apps.AppConfig):
pass
class AppConfig(django.apps.AppConfig):
name = 'passerelle.base'
def ready(self):
# once all applications are ready, go through them and mark them as
# connectors if they have a get_connector_model() method or a model
# that inherits from BaseResource.
from .models import BaseResource
for app in apps.get_app_configs():
connector_model = None
if hasattr(app, 'get_connector_model'):
connector_model = app.get_connector_model()
else:
for model in app.get_models():
if issubclass(model, BaseResource):
connector_model = model
app._connector_model = model
break
if not connector_model:
continue
if app.__class__ is django.apps.AppConfig:
# switch class if it's an application without a custom
# appconfig.
app.__class__ = ConnectorAppConfig
else:
# add mixin to base classes if it's an application with a
# custom appconfig.
app.__class__.__bases__ = (ConnectorAppMixin,) + app.__class__.__bases__
default_app_config = 'passerelle.base.AppConfig'

37
passerelle/base/apps.py Normal file
View File

@ -0,0 +1,37 @@
import django.apps
from . import ConnectorAppConfig, ConnectorAppMixin
class AppConfig(django.apps.AppConfig):
name = 'passerelle.base'
def ready(self):
# once all applications are ready, go through them and mark them as
# connectors if they have a get_connector_model() method or a model
# that inherits from BaseResource.
from .models import BaseResource
for app in django.apps.apps.get_app_configs():
connector_model = None
if hasattr(app, 'get_connector_model'):
connector_model = app.get_connector_model()
else:
for model in app.get_models():
if issubclass(model, BaseResource):
connector_model = model
app._connector_model = model
break
if not connector_model:
continue
if app.__class__ is django.apps.AppConfig:
# switch class if it's an application without a custom
# appconfig.
app.__class__ = ConnectorAppConfig
else:
# add mixin to base classes if it's an application with a
# custom appconfig.
app.__class__.__bases__ = (ConnectorAppMixin,) + app.__class__.__bases__
default_app_config = 'passerelle.base.AppConfig'

View File

@ -116,7 +116,7 @@ INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.postgres',
# base app
'passerelle.base',
'passerelle.base.apps.AppConfig',
'passerelle.address',
'passerelle.sms',
# connectors
@ -138,9 +138,9 @@ INSTALLED_APPS = (
'passerelle.apps.choosit',
'passerelle.apps.cityweb',
'passerelle.apps.clicrdv',
'passerelle.apps.cmis',
'passerelle.apps.cmis.apps.CmisAppConfig',
'passerelle.apps.cryptor',
'passerelle.apps.csvdatasource',
'passerelle.apps.csvdatasource.apps.AppConfig',
'passerelle.apps.esabora',
'passerelle.apps.esirius',
'passerelle.apps.family',