This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
forked from rapidpro/rapidpro-docker
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathurls.py
113 lines (88 loc) · 4.13 KB
/
urls.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import importlib
import regex
from django.conf import settings
from django.conf.urls import url
from django.urls import path, include
from django.conf.urls.static import static
from django.contrib.auth.models import AnonymousUser, User
from django.views.generic import RedirectView
from django.views.i18n import JavaScriptCatalog
from regex import escape
from temba.triggers import views
from celery.signals import worker_process_init
from temba.channels.views import register, sync
from temba.utils.analytics import init_analytics
# javascript translation packages
js_info_dict = {"packages": ()} # this is empty due to the fact that all translation are in one folder
VHOST_NAME = ""
SUB_DIR = getattr(settings, 'SUB_DIR', None)
if SUB_DIR is not None and len(SUB_DIR) > 0:
if settings.SUB_DIR[-1:] == "/":
VHOST_NAME = SUB_DIR
else:
VHOST_NAME = SUB_DIR + "/"
urlpatterns = [
url(r"^{}".format(VHOST_NAME), include("temba.airtime.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.api.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.apks.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.archives.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.campaigns.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.channels.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.classifiers.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.contacts.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.dashboard.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.flows.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.globals.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.ivr.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.locations.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.msgs.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.orgs.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.policies.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.public.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.request_logs.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.schedules.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.tickets.urls")),
url(r"^{}".format(VHOST_NAME), include("temba.triggers.urls")),
url(r"^{}relayers/relayer/sync/(\d+)/$".format(VHOST_NAME), sync, {}, "sync"),
url(r"^{}relayers/relayer/register/$".format(VHOST_NAME), register, {}, "register"),
url(r"^{}users/".format(VHOST_NAME), include("smartmin.users.urls")),
url(r"^{}imports/".format(VHOST_NAME), include("smartmin.csv_imports.urls")),
url(r"^{}assets/".format(VHOST_NAME), include("temba.assets.urls")),
url(r"^{}jsi18n/$".format(VHOST_NAME), JavaScriptCatalog.as_view(), js_info_dict, name="django.views.i18n.javascript_catalog"),
]
# add a root url redirect when SUB_DIR not empty
if len(VHOST_NAME) > 1:
url(r'^$', RedirectView.as_view(url="/{}/".format(VHOST_NAME), permanent=True)),
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# import any additional urls
for app in settings.APP_URLS: # pragma: needs cover
importlib.import_module(app)
# initialize our analytics (the signal below will initialize each worker)
init_analytics()
@worker_process_init.connect
def configure_workers(sender=None, **kwargs):
init_analytics() # pragma: needs cover
def track_user(self): # pragma: no cover
"""
Should the current user be tracked
"""
# don't track unless we are on production
if not settings.IS_PROD:
return False
# nothing to report if they haven't logged in
if not self.is_authenticated or self.is_anonymous:
return False
return True
User.track_user = track_user
AnonymousUser.track_user = track_user
def handler500(request):
"""
500 error handler which includes ``request`` in the context.
Templates: `500.html`
Context: None
"""
from django.template import loader
from django.http import HttpResponseServerError
t = loader.get_template("500.html")
return HttpResponseServerError(t.render({"request": request})) # pragma: needs cover