34 |
34 |
except ImportError:
|
35 |
35 |
return None
|
36 |
36 |
|
37 |
37 |
|
38 |
38 |
class ConnectorAppConfig(ConnectorAppMixin, django.apps.AppConfig):
|
39 |
39 |
pass
|
40 |
40 |
|
41 |
41 |
|
|
42 |
class ConnectorSMSMixin(ConnectorAppMixin):
|
|
43 |
def get_management_urls(self):
|
|
44 |
urlpatterns = super(ConnectorSMSMixin, self).get_management_urls() or []
|
|
45 |
urlpatterns += import_string('passerelle.sms.urls.management_urlpatterns')
|
|
46 |
return urlpatterns
|
|
47 |
|
|
48 |
class ConnectorSMSConfig(ConnectorSMSMixin, django.apps.AppConfig):
|
|
49 |
pass
|
|
50 |
|
|
51 |
|
42 |
52 |
class AppConfig(django.apps.AppConfig):
|
43 |
53 |
name = 'passerelle.base'
|
44 |
54 |
|
45 |
55 |
def ready(self):
|
46 |
56 |
# once all applications are ready, go through them and mark them as
|
47 |
57 |
# connectors if they have a get_connector_model() method or a model
|
48 |
58 |
# that inherits from BaseResource.
|
49 |
59 |
from .models import BaseResource
|
|
60 |
from passerelle.sms.models import SMSResource
|
50 |
61 |
for app in apps.get_app_configs():
|
51 |
62 |
connector_model = None
|
52 |
63 |
if hasattr(app, 'get_connector_model'):
|
53 |
64 |
connector_model = app.get_connector_model()
|
54 |
65 |
else:
|
55 |
66 |
for model in app.get_models():
|
56 |
67 |
if issubclass(model, BaseResource):
|
57 |
68 |
connector_model = model
|
58 |
69 |
app._connector_model = model
|
|
70 |
if issubclass(model, SMSResource):
|
|
71 |
app._is_sms_connector = True
|
59 |
72 |
break
|
|
73 |
|
60 |
74 |
if not connector_model:
|
61 |
75 |
continue
|
62 |
76 |
if app.__class__ is django.apps.AppConfig:
|
63 |
77 |
# switch class if it's an application without a custom
|
64 |
78 |
# appconfig.
|
65 |
|
app.__class__ = ConnectorAppConfig
|
|
79 |
if getattr(app, "_is_sms_connector", False):
|
|
80 |
app.__class__ = ConnectorSMSConfig
|
|
81 |
else:
|
|
82 |
app.__class__ = ConnectorAppConfig
|
66 |
83 |
else:
|
67 |
84 |
# add mixin to base classes if it's an application with a
|
68 |
85 |
# custom appconfig.
|
69 |
86 |
app.__class__.__bases__ = (ConnectorAppMixin,) + app.__class__.__bases__
|
70 |
87 |
|
71 |
88 |
default_app_config = 'passerelle.base.AppConfig'
|
72 |
|
-
|