You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
5.1 KiB
142 lines
5.1 KiB
"""
|
|
URL configuration for backend project.
|
|
|
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
|
https://docs.djangoproject.com/en/5.0/topics/http/urls/
|
|
Examples:
|
|
Function views
|
|
1. Add an import: from my_app import views
|
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
|
Class-based views
|
|
1. Add an import: from other_app.views import Home
|
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
|
Including another URLconf
|
|
1. Import the include() function: from django.urls import include, path
|
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
|
"""
|
|
from django.contrib import admin
|
|
from django.urls import path, include, re_path
|
|
from django.conf import settings
|
|
from django.conf.urls.static import static
|
|
from django.conf.urls.i18n import i18n_patterns
|
|
from django.contrib.admin.views.decorators import staff_member_required
|
|
from utils import UploadTmpMedia, UploadChatMedia
|
|
from django.http import JsonResponse
|
|
from django.shortcuts import render
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from rest_framework.decorators import api_view
|
|
from rest_framework.response import Response
|
|
|
|
from utils import absolute_url
|
|
|
|
from utils.admin import dovoodi_admin_site
|
|
|
|
from drf_yasg.views import get_schema_view
|
|
from drf_yasg import openapi
|
|
from rest_framework import permissions
|
|
import requests
|
|
from filer import views
|
|
|
|
# Import custom API views
|
|
from apps.api.views import CustomAPIDocumentationView, CustomSwaggerView, SwaggerTokenAuthView, clear_swagger_auth
|
|
from apps.api.permissions import IsAdminOrSwaggerToken
|
|
from apps.api.decorators import swagger_auth_required
|
|
|
|
# Restricted schema view for admin users and authenticated swagger users
|
|
schema_view = get_schema_view(
|
|
openapi.Info(
|
|
title="Imam Javad API",
|
|
default_version='v1',
|
|
description="Comprehensive API documentation for the Imam Javad educational platform",
|
|
contact=openapi.Contact(email="contact@imamjavad.com"),
|
|
license=openapi.License(name="MIT License"),
|
|
),
|
|
public=False,
|
|
permission_classes=(IsAdminOrSwaggerToken,),
|
|
)
|
|
|
|
|
|
def oneapi_translate(request):
|
|
dist_lang = request.GET.get('dist_lang')
|
|
q = request.GET.get('q')
|
|
url = f"https://one-api.ir/translate/?token=169700:6485a38c34b00&action=google&lang={dist_lang}&q={q}"
|
|
try:
|
|
data = requests.get(url).json()
|
|
except Exception as e:
|
|
data = {}
|
|
|
|
return JsonResponse(data)
|
|
|
|
|
|
api_patterns = [
|
|
path('test/', include('apps.api.urls')),
|
|
|
|
path('account/', include('apps.account.urls')),
|
|
# FIXME: DEPENDENCY ON DELETED APPS (course, quiz, transaction, certificate, blog) — Commented out for Dovoodi project separation
|
|
# path('courses/', include('apps.course.urls')),
|
|
# path('quiz/', include('apps.quiz.urls')),
|
|
# path('transaction/', include('apps.transaction.urls')),
|
|
# path('certificates/', include('apps.certificate.urls')),
|
|
path('hadis/', include('apps.hadis.urls')),
|
|
path('library/', include('apps.library.urls')),
|
|
path('videos/', include('apps.video.urls')),
|
|
path('article/', include('apps.article.urls')),
|
|
path('podcast/', include('apps.podcast.urls')),
|
|
path('bookmarks/', include('apps.bookmark.urls')),
|
|
path('calendar/', include('apps.dobodbi_calendar.urls')),
|
|
# path('blog/', include('apps.blog.urls')),
|
|
|
|
path('settings/', include('dynamic_preferences.urls')),
|
|
|
|
path('upload-chat-media/', UploadChatMedia.as_view()), # دائمی در /media/chat/
|
|
path('upload-tmp-media/', UploadTmpMedia.as_view()), # موقت در /static/tmp/
|
|
|
|
]
|
|
|
|
|
|
# Base URL patterns (common to all domains)
|
|
# These patterns are shared by both Imam Javad and Dovoodi sites
|
|
|
|
def trigger_error(request):
|
|
division_by_zero = 1 / 0
|
|
|
|
# Protected swagger URL patterns (to be used in domain-specific configs)
|
|
swagger_urlpatterns = [
|
|
path('swagger-auth/', SwaggerTokenAuthView.as_view(), name='swagger-token-auth'),
|
|
path('swagger-auth/clear/', clear_swagger_auth, name='clear-swagger-auth'),
|
|
re_path(r'^swagger(?P<format>\.json|\.yaml)$',
|
|
swagger_auth_required(schema_view.without_ui(cache_timeout=0)),
|
|
name='schema-json'),
|
|
path('swagger/', CustomSwaggerView.as_view(), name='schema-swagger-ui'),
|
|
re_path(r'^redoc/$',
|
|
swagger_auth_required(schema_view.with_ui('redoc', cache_timeout=0)),
|
|
name='schema-redoc'),
|
|
]
|
|
|
|
urlpatterns = [
|
|
path("i18n/", include("django.conf.urls.i18n")),
|
|
path('api/', include(api_patterns)),
|
|
path('oneapi-translation/', oneapi_translate),
|
|
path('sentry-debug/', trigger_error),
|
|
] + i18n_patterns(
|
|
# Unified Admin panel accessible at /admin/ (Django will redirect to /en/admin/ or /fa/admin/)
|
|
path("admin/", dovoodi_admin_site.urls),
|
|
|
|
# API documentation
|
|
path('docs/', CustomAPIDocumentationView.as_view(), name='docs-index'),
|
|
|
|
# Swagger and API documentation
|
|
*swagger_urlpatterns,
|
|
|
|
# Filer (Django file manager)
|
|
path('admin/filer/', include('filer.urls')),
|
|
path('filer/', include('filer.urls')),
|
|
)
|
|
|
|
if settings.DEBUG:
|
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
|
|
|
|
|
|
|
|
|
|