Skip to content

Commit

Permalink
Merge pull request #43 from mikeiken/django
Browse files Browse the repository at this point in the history
Added CORS, pagination and name in fertilizer
  • Loading branch information
Kseen715 authored Oct 17, 2024
2 parents aa30245 + 66f37a4 commit b466773
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 24 deletions.
Binary file modified django/requirements.txt
Binary file not shown.
19 changes: 19 additions & 0 deletions django/tamprog/garden/migrations/0003_fertilizer_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.16 on 2024-10-16 10:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('garden', '0002_remove_plant_fertilizer_id_order_fertilizer_id'),
]

operations = [
migrations.AddField(
model_name='fertilizer',
name='name',
field=models.CharField(default=1, max_length=1024),
preserve_default=False,
),
]
3 changes: 2 additions & 1 deletion django/tamprog/garden/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class GardenBed(models.Model):
size = models.FloatField()

class Fertilizer(models.Model):
#состав
#название,состав
name = models.CharField(max_length=1024)
compound = models.CharField(max_length=1024)

class User(models.Model):
Expand Down
23 changes: 21 additions & 2 deletions django/tamprog/garden/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
#from django.urls import path
from django.urls import path, include
from rest_framework import routers

from .views import *

from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from django.conf import settings
from django.conf.urls.static import static

schema_view = get_schema_view(
openapi.Info(
title="Your Project API",
default_version='v1',
description="Electronic agronomist",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="zarembiczkiy@mail.ru"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)

router_agronomist = routers.SimpleRouter()
router_agronomist.register(r'agronomist', AgronomistViewSet)
Expand Down Expand Up @@ -43,4 +60,6 @@
path('', include(router_plant.urls)),
path('', include(router_plot.urls)),
path('', include(router_order.urls)),
]
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'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
32 changes: 32 additions & 0 deletions django/tamprog/tamprog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
from pathlib import Path
from dotenv import load_dotenv
import re

# Load environment variables from .env file
load_dotenv()
Expand Down Expand Up @@ -45,9 +46,11 @@
'rest_framework',
'garden',
'drf_yasg',
'corsheaders',
]

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand All @@ -57,6 +60,30 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ORIGIN_ALLOW_ALL = True

CORS_ALLOW_ALL_ORIGINS = True

CORS_ALLOW_CREDENTIALS = True

CORS_ALLOW_HEADERS = \
['Access-Control-Allow-Origin',
'Access-Control-Allow-Credentials',
'headers',
'content-type',
'x-csrftoken',]

CORS_ALLOW_METHODS = ['GET', 'POST', 'PUT',
'DELETE', 'OPTIONS', 'PATCH', 'UPDATE', 'DESTROY']

#CORS_ALLOWED_ORIGIN_REGEXES = [
# r'^https?://homelab.kerasi.ru$', # основной фронт
# r'^https?://homelab.kerasi.ru/api/v1/.*$', # API
# r'^https?://homelab.kerasi.ru/api/swagger/.*$', # Swagger
# r'^https?://homelab.kerasi.ru/redis-commander/.*$', # Redis Commander
# r'^https?://homelab.kerasi.ru/rabbitmq/.*$', # RabbitMQ
#]

ROOT_URLCONF = 'tamprog.urls'

TEMPLATES = [
Expand Down Expand Up @@ -147,3 +174,8 @@
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 30
}
22 changes: 1 addition & 21 deletions django/tamprog/tamprog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,9 @@
from django.urls import path, include
from rest_framework import routers
from django.views.generic import RedirectView
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from django.conf import settings
from django.conf.urls.static import static

schema_view = get_schema_view(
openapi.Info(
title="Your Project API",
default_version='v1',
description="Electronic agronomist",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="zarembiczkiy@mail.ru"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)

urlpatterns = [
path('admin/', admin.site.urls),
path('log/', include('rest_framework.urls')),
path('api/v1/', include('garden.urls')),
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'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
]

0 comments on commit b466773

Please sign in to comment.