0001-base-load-urls.py-from-generic-connectors-apps-46611.patch
passerelle/base/__init__.py | ||
---|---|---|
11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | 12 |
# GNU Affero General Public License for more details. |
13 | 13 |
# |
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import django.apps |
18 | 18 |
from django.apps import apps |
19 |
from django.utils.module_loading import import_string |
|
20 | 19 | |
21 |
class ConnectorAppMixin(object): |
|
22 |
def get_connector_model(self): |
|
23 |
return self._connector_model |
|
24 | ||
25 |
def get_urls(self): |
|
26 |
try: |
|
27 |
return import_string('%s.urls.urlpatterns' % self.name) |
|
28 |
except ImportError: |
|
29 |
return None |
|
30 | ||
31 |
def get_management_urls(self): |
|
32 |
try: |
|
33 |
return import_string('%s.urls.management_urlpatterns' % self.name) |
|
34 |
except ImportError: |
|
35 |
return None |
|
20 |
from .mixins import ConnectorAppMixin |
|
36 | 21 | |
37 | 22 | |
38 | 23 |
class ConnectorAppConfig(ConnectorAppMixin, django.apps.AppConfig): |
39 | 24 |
pass |
40 | 25 | |
41 | 26 | |
42 | 27 |
class AppConfig(django.apps.AppConfig): |
43 | 28 |
name = 'passerelle.base' |
... | ... | |
57 | 42 |
connector_model = model |
58 | 43 |
app._connector_model = model |
59 | 44 |
break |
60 | 45 |
if not connector_model: |
61 | 46 |
continue |
62 | 47 |
if app.__class__ is django.apps.AppConfig: |
63 | 48 |
# switch class if it's an application without a custom |
64 | 49 |
# appconfig. |
65 |
app.__class__ = ConnectorAppConfig |
|
50 |
if hasattr(app._connector_model, 'app_class_replacement'): |
|
51 |
app.__class__ = app._connector_model.app_class_replacement |
|
52 |
else: |
|
53 |
app.__class__ = ConnectorAppConfig |
|
66 | 54 |
else: |
67 | 55 |
# add mixin to base classes if it's an application with a |
68 | 56 |
# custom appconfig. |
69 | 57 |
app.__class__.__bases__ = (ConnectorAppMixin,) + app.__class__.__bases__ |
70 | 58 | |
59 | ||
71 | 60 |
default_app_config = 'passerelle.base.AppConfig' |
passerelle/base/mixins.py | ||
---|---|---|
10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | 12 |
# GNU Affero General Public License for more details. |
13 | 13 |
# |
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
from django.utils import functional |
18 |
from django.utils.module_loading import import_string |
|
18 | 19 | |
19 | 20 | |
20 | 21 |
class ResourceChildViewMixin(object): |
21 | 22 |
'''Mixin to help implementing view for child objects of resource objets.''' |
22 | 23 | |
23 | 24 |
@property |
24 | 25 |
def resource_class(self): |
25 | 26 |
field = self.model._meta.get_field('resource') |
... | ... | |
40 | 41 |
def get_queryset(self): |
41 | 42 |
qs = super(ResourceChildViewMixin, self).get_queryset() |
42 | 43 |
return qs.filter(resource=self.resource) |
43 | 44 | |
44 | 45 |
def get_success_url(self): |
45 | 46 |
return self.resource.get_absolute_url() |
46 | 47 | |
47 | 48 | |
49 |
class ConnectorAppMixin(object): |
|
50 |
def get_connector_model(self): |
|
51 |
return self._connector_model |
|
52 | ||
53 |
def get_urls(self): |
|
54 |
try: |
|
55 |
return import_string('%s.urls.urlpatterns' % self.name) |
|
56 |
except ImportError: |
|
57 |
return None |
|
58 | ||
59 |
def get_management_urls(self): |
|
60 |
try: |
|
61 |
return import_string('%s.urls.management_urlpatterns' % self.name) |
|
62 |
except ImportError: |
|
63 |
return None |
|
48 |
- |