Revert "django4: fix default AppConfig deprecation warnings (#68576)"

This reverts commit fdfad9a78a.
This commit is contained in:
Agate 2022-09-05 16:34:13 +02:00
parent 918e46d99d
commit 73613d6cf9
6 changed files with 55 additions and 51 deletions

View File

@ -13,3 +13,5 @@
#
# 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,3 +13,18 @@
#
# 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

@ -1,11 +0,0 @@
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,6 +15,7 @@
# 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
@ -37,3 +38,37 @@ 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'

View File

@ -1,37 +0,0 @@
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.apps.AppConfig',
'passerelle.base',
'passerelle.address',
'passerelle.sms',
# connectors
@ -138,9 +138,9 @@ INSTALLED_APPS = (
'passerelle.apps.choosit',
'passerelle.apps.cityweb',
'passerelle.apps.clicrdv',
'passerelle.apps.cmis.apps.CmisAppConfig',
'passerelle.apps.cmis',
'passerelle.apps.cryptor',
'passerelle.apps.csvdatasource.apps.AppConfig',
'passerelle.apps.csvdatasource',
'passerelle.apps.esabora',
'passerelle.apps.esirius',
'passerelle.apps.family',