Skip to content

Commit

Permalink
feat(urls): dynamic registration from userflows
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Jan 28, 2025
1 parent 9222258 commit 5c92800
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
12 changes: 12 additions & 0 deletions web/core/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .models import UserFlow


def userflows(request):
flows = []
try:
for flow in UserFlow.objects.all():
flows.append({"label": flow.label, "index_url": flow.index_url})
except Exception:
pass

return {"userflows": flows}
8 changes: 5 additions & 3 deletions web/core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@
<li class="nav-item">
<a class="first-level-link" href="{% url 'core:index' %}">Home</a>
</li>
<li class="nav-item">
<a class="first-level-link" href="{% url 'vital_records:index' %}">Vital records</a>
</li>
{% for flow in userflows %}
<li class="nav-item">
<a class="first-level-link" href="{% url flow.index_url %}">{{ flow.label }}</a>
</li>
{% endfor %}
</ul>
</nav>
</div>
Expand Down
21 changes: 15 additions & 6 deletions web/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,27 @@ def RUNTIME_ENVIRONMENT():

ROOT_URLCONF = "web.urls"

template_ctx_processors = [
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"web.core.context_processors.userflows",
]

if DEBUG:
template_ctx_processors.extend(
[
"django.template.context_processors.debug",
]
)

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
"context_processors": template_ctx_processors,
},
},
]
Expand Down
3 changes: 1 addition & 2 deletions web/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django URL configuration for Digital Disaster Recovery Center (DDRC) project.
Django root URL configuration.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/http/urls/
Expand All @@ -12,5 +12,4 @@
path("", include("web.core.urls")),
path("admin/", admin.site.urls),
path("oauth/", include("web.oauth.urls")),
path("vital-records/", include("web.vital_records.urls")),
]
10 changes: 9 additions & 1 deletion web/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django WSGI config for Digital Disaster Recovery Center (DDRC) project.
Django WSGI config.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
Expand All @@ -8,7 +8,15 @@
import os

from django.core.wsgi import get_wsgi_application
from django.urls import include, path


from web.core.models import UserFlow
import web.urls

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "web.settings")

application = get_wsgi_application()

for flow in UserFlow.objects.all():
web.urls.urlpatterns.append(path(f"{flow.system_name}/", include(flow.urlconf_path)))

0 comments on commit 5c92800

Please sign in to comment.