diff --git a/backend/api/urls.py b/backend/api/urls.py index 87cccd7..700fcad 100644 --- a/backend/api/urls.py +++ b/backend/api/urls.py @@ -24,7 +24,7 @@ urlpatterns = [ path('', include(router.urls)), - path('', include('djoser.urls')), # это вроде можно убрать + # path('', include('djoser.urls')), # это вроде можно убрать path('auth/', include('djoser.urls.authtoken')), path('platform_about/', PlatformAboutView.as_view()), path('feedback/', FeedbackCreateView.as_view()), diff --git a/backend/backend/settings.py b/backend/backend/settings.py index fc10d99..fb8cb30 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -37,7 +37,8 @@ 'djoser', 'rest_framework', 'rest_framework.authtoken', - 'rest_framework_swagger', + # 'rest_framework_swagger', # убираем + 'drf_yasg', 'taggit', 'api.apps.ApiConfig', 'content.apps.ContentConfig', @@ -88,24 +89,24 @@ # Database # https://docs.djangoproject.com/en/4.2/ref/settings/#databases -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } -} - # DATABASES = { # 'default': { -# 'ENGINE': 'django.db.backends.postgresql', -# 'NAME': os.getenv('POSTGRES_DB', 'volunteers'), -# 'USER': os.getenv('POSTGRES_USER', 'volunteers_user'), -# 'PASSWORD': os.getenv('POSTGRES_PASSWORD', ''), -# 'HOST': os.getenv('DB_HOST', 'localhost'), -# 'PORT': os.getenv('DB_PORT', 5432), +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': BASE_DIR / 'db.sqlite3', # } # } +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': os.getenv('POSTGRES_DB', 'volunteers'), + 'USER': os.getenv('POSTGRES_USER', 'volunteers_user'), + 'PASSWORD': os.getenv('POSTGRES_PASSWORD', ''), + 'HOST': os.getenv('DB_HOST', 'localhost'), + 'PORT': os.getenv('DB_PORT', 5432), + } +} + # Password validation # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators @@ -162,7 +163,7 @@ 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', 'PAGE_SIZE': 10, 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend',], - 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema', + # 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema', } DJOSER = { @@ -188,6 +189,22 @@ AUTH_USER_MODEL = 'users.User' +SWAGGER_SETTINGS = { + 'SECURITY_DEFINITIONS': { + 'Token': { # авторизация в джанго по токену + 'type': 'apiKey', + 'name': 'Authorization', + 'in': 'header' + }, + 'Basic': { # базова авторизация + 'type': 'basic' + } + }, + 'USE_SESSION_AUTH': True, # кнопка джанго логин можно отключить поменяв False + 'JSON_EDITOR': True, + 'SHOW_REQUEST_HEADERS': True, +} + # Constants MAX_LENGTH_NAME = 50 MAX_LENGTH_SLUG = 50 @@ -219,9 +236,9 @@ MAX_LEN_NAME_USER = 40 MESSAGE_NAME_USER_VALID = f'Длина поля от {MIN_LEN_NAME_USER} до {MAX_LEN_NAME_USER} символов' MESSAGE_NAME_USER_CYRILLIC = 'Введите имя кириллицей' -MAX_LENGTH_ROLE = 50 -OGRN_ERROR_MESSAGE = 'ОГРН должен состоять из 13 цифр.' +OGRN_ERROR_MESSAGE = 'ОГРН должен состоять из 13 цифр.' +MAX_LENGTH_ROLE = 50 MIN_LEN_TELEGRAM = 5 MAX_LEN_TELEGRAM = 32 TELEGRAM_ERROR_MESSAGE = 'Ник в Telegram должен начинаться с @ и содержать только буквы, цифры и знаки подчеркивания. От {} до {} символов.' diff --git a/backend/backend/urls.py b/backend/backend/urls.py index 465b4a4..71bf402 100644 --- a/backend/backend/urls.py +++ b/backend/backend/urls.py @@ -1,17 +1,30 @@ from django.conf import settings from django.conf.urls.static import static from django.contrib import admin +from django.contrib.auth.views import LoginView, LogoutView from django.urls import include, path -from rest_framework_swagger.views import get_swagger_view +# from rest_framework_swagger.views import get_swagger_view +# schema_view = get_swagger_view(title='BETTER-TOGETHER Documentation API') +from .yasg import urlpatterns as doc_urls + -schema_view = get_swagger_view(title='BETTER-TOGETHER Documentation API') urlpatterns = [ path('api/', include('api.urls')), path('admin/', admin.site.urls), - path('swagger/', schema_view), + # логин в джанго свагер Проверить никому не помешает ли!!! + path('accounts/login/', LoginView.as_view( + template_name='admin/login.html', + )), + # логаут в джанго свагер. Проверить никому не помешает ли!!! + path('accounts/logout/', LogoutView.as_view( + template_name='admin/logout.html', + )), + # path('swagger/', schema_view), ] +urlpatterns += doc_urls + if settings.DEBUG: urlpatterns += static( settings.MEDIA_URL, document_root=settings.MEDIA_ROOT diff --git a/backend/backend/yasg.py b/backend/backend/yasg.py new file mode 100644 index 0000000..c467e69 --- /dev/null +++ b/backend/backend/yasg.py @@ -0,0 +1,43 @@ +from django.urls import path, re_path +from drf_yasg import openapi +from drf_yasg.views import get_schema_view +from rest_framework import permissions + + +schema_view = get_schema_view( + openapi.Info( + title='BETTER-TOGETHER', + default_version='v1', + description="""API documentation for Task BETTER-TOGETHER project. + Contact us. + Yurij Pomazkin,\ + Ruzal Zakirov,\ + Artem Kozin,\ + Olga Komleva,\ + \ + and Irina Yablokova + """, + contact=openapi.Contact(email="info@bettertogether.ru"), + license=openapi.License(name='BSD License'), + ), + public=True, + permission_classes=[permissions.AllowAny], +) + + +urlpatterns = [ + re_path( + r'swagger(?P\.json|\.yaml)', + schema_view.without_ui(cache_timeout=0), + name='schema-json' + ), + path( + 'swagger/', + schema_view.with_ui('swagger', cache_timeout=0), + name='schema-swagger-ui' + ), + path( + 'redoc/', + schema_view.with_ui('redoc', cache_timeout=0), + name='schema-redoc'), +] diff --git a/backend/notifications/admin.py b/backend/notifications/admin.py index 8c38f3f..4185d36 100644 --- a/backend/notifications/admin.py +++ b/backend/notifications/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +# from django.contrib import admin # Register your models here. diff --git a/backend/notifications/models.py b/backend/notifications/models.py index 71a8362..8b13789 100644 --- a/backend/notifications/models.py +++ b/backend/notifications/models.py @@ -1,3 +1 @@ -from django.db import models -# Create your models here. diff --git a/backend/notifications/tests.py b/backend/notifications/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/backend/notifications/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/backend/notifications/views.py b/backend/notifications/views.py index 91ea44a..8b13789 100644 --- a/backend/notifications/views.py +++ b/backend/notifications/views.py @@ -1,3 +1 @@ -from django.shortcuts import render -# Create your views here. diff --git a/backend/projects/tests.py b/backend/projects/tests.py deleted file mode 100644 index e69de29..0000000 diff --git a/backend/projects/views.py b/backend/projects/views.py deleted file mode 100644 index e69de29..0000000 diff --git a/backend/requirements.txt b/backend/requirements.txt index e954137..5fe3f7a 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -9,15 +9,16 @@ defusedxml==0.8.0rc2 Django==4.2.6 django-cors-headers==4.3.0 django-filter==23.3 -django-rest-swagger==2.2.0 django-taggit==4.0.0 django-taggit-serializer==0.1.7 django-templated-mail==1.1.1 djangorestframework==3.14.0 djangorestframework-simplejwt==5.3.0 djoser==2.2.0 +drf-yasg==1.21.7 gunicorn==21.2.0 idna==3.4 +inflection==0.5.1 itypes==1.2.0 Jinja2==3.1.2 MarkupSafe==2.1.3 @@ -31,6 +32,7 @@ PyJWT==2.8.0 python-dotenv==1.0.0 python3-openid==3.2.0 pytz==2023.3.post1 +PyYAML==6.0.1 requests==2.31.0 requests-oauthlib==1.3.1 simplejson==3.19.2 diff --git a/backend/users/tests.py b/backend/users/tests.py deleted file mode 100644 index e69de29..0000000 diff --git a/backend/users/views.py b/backend/users/views.py deleted file mode 100644 index e69de29..0000000