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.
 
 

129 lines
4.4 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
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 project_admin_site, HomeView
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
# Restricted schema view for admin users only
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=(permissions.IsAdminUser,),
)
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')),
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('settings/', include('dynamic_preferences.urls')),
path('upload-tmp-media/', UploadTmpMedia.as_view()),
]
urlpatterns = [
path("admin/", HomeView.as_view(), name="home"),
path("i18n/", include("django.conf.urls.i18n")),
# path('admin/', admin.site.urls),
path('api/', include(api_patterns)),
# path('test/', include('apps.api.urls'))
path('oneapi-translation/', oneapi_translate),
path('admin/filer/', include('filer.urls')),
]
# Protected swagger URL patterns
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)$',
staff_member_required(schema_view.without_ui(cache_timeout=0)),
name='schema-json'),
path('swagger/', CustomSwaggerView.as_view(), name='schema-swagger-ui'),
re_path(r'^redoc/$',
staff_member_required(schema_view.with_ui('redoc', cache_timeout=0)),
name='schema-redoc'),
]
urlpatterns+= i18n_patterns(
path("admin/", project_admin_site.urls),
path('docs/', CustomAPIDocumentationView.as_view(), name='docs-index'),
*swagger_urlpatterns,
path('admin/filer/', include('filer.urls')),
)
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)