-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapps.py
43 lines (34 loc) · 1.17 KB
/
apps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
from django.apps import AppConfig
from django.conf import settings
class CustomMetadataConfig(AppConfig):
name = "custom_metadata"
def ready(self):
# inject templates
if hasattr(settings, 'CUSTOM_METADATA_TEMPLATE_DIRECTORY'):
settings.TEMPLATES[0]["DIRS"].insert(0, os.path.join(settings.CUSTOM_METADATA_TEMPLATE_DIRECTORY))
else:
settings.TEMPLATES[0]["DIRS"].insert(0, os.path.join(self.path, "templates"))
run_setup_hooks()
def run_setup_hooks(*args, **kwargs):
"""
Run basic setup configuration for the custom_metadata app.
"""
# Add custom URLs
from django.conf.urls import include, url
from geonode.urls import urlpatterns
url_patterns = [
"datasets",
"maps",
"documents",
"apps",
]
for pattern in url_patterns:
urlpatterns.insert(
0,
url(f"^{pattern}/", include(f"custom_metadata.urls.{pattern}_urls")),
)
# Add middleware
middleware = list(settings.MIDDLEWARE)
middleware = ["custom_metadata.middleware.AppendMetadataMiddleware"] + middleware
settings.MIDDLEWARE = tuple(middleware)