Files
customerTicket/config/urls.py
T

78 lines
3.1 KiB
Python

from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from django.db import connection
from django.http import JsonResponse
from django.shortcuts import render
from django.templatetags.static import static as static_url
from django.urls import include, path
from django.views.static import serve
from apps.core.models import SiteBranding
from apps.payments import link_views as payment_link_views
def healthz(request):
with connection.cursor() as cursor:
cursor.execute("SELECT 1")
cursor.fetchone()
response = JsonResponse({"status": "ok"})
response["Cache-Control"] = "no-store"
return response
def public_branding(request, path):
"""Serve only public branding uploads; all ticket files use authorized views."""
return serve(request, path, document_root=settings.MEDIA_ROOT / "branding")
def service_worker(request):
response = render(request, "pwa/service-worker.js", content_type="application/javascript")
response["Cache-Control"] = "no-cache, no-store, must-revalidate"
response["Service-Worker-Allowed"] = "/"
return response
def web_manifest(request):
branding = SiteBranding.load()
try:
icon_url = branding.pwa_icon.url if branding.pwa_icon else static_url("images/pwa-icon.png")
except (ValueError, OSError):
icon_url = static_url("images/pwa-icon.png")
response = JsonResponse({
"id": "/", "name": branding.pwa_name, "short_name": branding.pwa_title,
"description": branding.pwa_description, "start_url": "/", "scope": "/",
"display": "standalone", "background_color": "#eeeeee", "theme_color": "#08376b",
"lang": "fa", "dir": "rtl",
"icons": [{"src": icon_url, "sizes": "1024x1024", "type": "image/png", "purpose": "any maskable"}],
}, json_dumps_params={"ensure_ascii": False})
response["Cache-Control"] = "no-cache, no-store, must-revalidate"
return response
urlpatterns = [
path("p/<str:token>/", payment_link_views.open_link, name="payment_short_link"),
path("healthz/", healthz, name="healthz"),
path("media/branding/<path:path>", public_branding, name="public_branding"),
path("service-worker.js", service_worker, name="service_worker"),
path("manifest.webmanifest", web_manifest, name="web_manifest"),
path("x5admin/", admin.site.urls),
path("", include("apps.accounts.urls")),
path("tickets/", include("apps.tickets.customer_urls")),
path("chaharsu/", include("apps.payments.urls")),
path("staff/payments/", include("apps.payments.staff_urls")),
path("staff/", include("apps.tickets.staff_urls")),
path("messages/", include("apps.messaging.urls")),
path("files/", include("apps.attachments.urls")),
path("api/phone-contacts", include("apps.phone_contacts_api.urls")),
]
def debug_media(request, path):
import posixpath
if posixpath.normpath(path.replace("\\", "/")).lstrip("/").startswith("payments/"):
from django.http import Http404
raise Http404
return serve(request, path, document_root=settings.MEDIA_ROOT)
if settings.DEBUG:
urlpatterns += [path("media/<path:path>", debug_media)]