From fdfad9a78ace19f752f5e090efd30fc04ed4cf3f Mon Sep 17 00:00:00 2001 From: Agate Berriot Date: Wed, 31 Aug 2022 10:40:03 +0200 Subject: [PATCH 4/5] django4: fix default AppConfig deprecation warnings (#68576) --- passerelle/apps/cmis/__init__.py | 2 -- passerelle/apps/csvdatasource/__init__.py | 15 --------- passerelle/apps/csvdatasource/apps.py | 11 +++++++ passerelle/base/__init__.py | 35 --------------------- passerelle/base/apps.py | 37 +++++++++++++++++++++++ passerelle/settings.py | 6 ++-- 6 files changed, 51 insertions(+), 55 deletions(-) create mode 100644 passerelle/apps/csvdatasource/apps.py create mode 100644 passerelle/base/apps.py diff --git a/passerelle/apps/cmis/__init__.py b/passerelle/apps/cmis/__init__.py index 5b4cbaca..ce658276 100644 --- a/passerelle/apps/cmis/__init__.py +++ b/passerelle/apps/cmis/__init__.py @@ -13,5 +13,3 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - -default_app_config = 'passerelle.apps.cmis.apps.CmisAppConfig' diff --git a/passerelle/apps/csvdatasource/__init__.py b/passerelle/apps/csvdatasource/__init__.py index 43e955d4..9c7b4d7a 100644 --- a/passerelle/apps/csvdatasource/__init__.py +++ b/passerelle/apps/csvdatasource/__init__.py @@ -13,18 +13,3 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - -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' diff --git a/passerelle/apps/csvdatasource/apps.py b/passerelle/apps/csvdatasource/apps.py new file mode 100644 index 00000000..0e4f3803 --- /dev/null +++ b/passerelle/apps/csvdatasource/apps.py @@ -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 diff --git a/passerelle/base/__init__.py b/passerelle/base/__init__.py index 831ed4e2..e03121e6 100644 --- a/passerelle/base/__init__.py +++ b/passerelle/base/__init__.py @@ -15,7 +15,6 @@ # along with this program. If not, see . 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' diff --git a/passerelle/base/apps.py b/passerelle/base/apps.py new file mode 100644 index 00000000..0013d6af --- /dev/null +++ b/passerelle/base/apps.py @@ -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' diff --git a/passerelle/settings.py b/passerelle/settings.py index 1c385137..41e32178 100644 --- a/passerelle/settings.py +++ b/passerelle/settings.py @@ -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', -- 2.37.2