Skip to content

Commit

Permalink
внесение изменений.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenia387 committed Feb 9, 2024
1 parent ead3635 commit 194e1ea
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 153 deletions.
14 changes: 7 additions & 7 deletions backend/foodgram_project/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.9
WORKDIR /app
RUN pip install gunicorn==20.0.4
COPY requirements.txt .
RUN pip install -r requirements.txt --no-cache-dir
COPY . .
CMD ["gunicorn", "--bind", "0.0.0.0:9000", "foodgram_project.wsgi"]
# FROM python:3.9
# WORKDIR /app
# RUN pip install gunicorn==20.0.4
# COPY requirements.txt .
# RUN pip install -r requirements.txt --no-cache-dir
# COPY . .
# CMD ["gunicorn", "--bind", "0.0.0.0:9000", "foodgram_project.wsgi"]
16 changes: 2 additions & 14 deletions backend/foodgram_project/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,13 @@ class RecipeFilter(FilterSet):
tags = filters.AllValuesMultipleFilter(
field_name='tags__slug',
)
is_favorited = filters.BooleanFilter(method='filter_is_favorited')
is_in_shopping_cart = filters.BooleanFilter(
method='filter_is_in_shopping_cart'
)

class Meta:
model = Recipe
fields = ('tags', 'author', 'is_favorited', 'is_in_shopping_cart')

def filter_is_favorited(self, queryset, name, value):
user = self.request.user
recipes = Recipe.objects.all()
if user.is_authenticated and value:
return Recipe.objects.filter(favorites__user=user)
return recipes
pass

def filter_is_in_shopping_cart(self, querysey, name, value):
user = self.request.user
recipes = Recipe.objects.all()
if user.is_authenticated and value:
return Recipe.objects.filter(shopping__user=user)
return recipes
pass
10 changes: 2 additions & 8 deletions backend/foodgram_project/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,10 @@ def get_is_subscribed(self, obj):
return True

def get_recipes(self, obj):
request = self.context.get('request')
recipes_limit = request.GET.get('recipes_limit')
recipes = Recipe.objects.filter(author=obj)
if recipes_limit:
recipes = recipes[:(int(recipes_limit))]
return RecipeInFavoriteAndShopList(recipes, many=True).data
pass

def get_recipes_count(self, obj):
count_recipes = Recipe.objects.filter(author=obj)
return len(count_recipes)
pass


class FollowSerializer(serializers.ModelSerializer):
Expand Down
21 changes: 10 additions & 11 deletions backend/foodgram_project/api/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from django.db.models import Sum
from django.http import HttpResponse
from django.http import HttpResponse, FileResponse
from django.shortcuts import get_object_or_404
from djoser.views import UserViewSet
from rest_framework import mixins, status, viewsets
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.response import Response
from rest_framework.viewsets import ReadOnlyModelViewSet
import reportlab
import io
from reportlab.pdfgen import canvas
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle


from api.filters import IngredientFilter, RecipeFilter
Expand Down Expand Up @@ -210,7 +218,6 @@ def download_shopping_cart(self, request):
f'{shopplist["amount"]} '
f'{shopplist["ingredient__measurement_unit"]}\n'
)
return HttpResponse(shopping_list_str, content_type='text/plain')


class CustomUserViewSet(UserViewSet,
Expand Down Expand Up @@ -306,12 +313,4 @@ def subscribe(self, request, id=None):
url_name='subscriptions',
)
def subscriptions(self, request):
user = request.user
queryset = User.objects.filter(following__user=user)
pages = self.paginate_queryset(queryset)
serializer = self.get_serializer(
pages,
many=True,
context={'request': request}
)
return self.get_paginated_response(serializer.data)
pass
34 changes: 18 additions & 16 deletions backend/foodgram_project/foodgram_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

SECRET_KEY = os.environ.get('SECRET_KEY')
# SECRET_KEY = os.environ.get('SECRET_KEY')
SECRET_KEY = 'django-insecure-3$_i)l+omymurayl5ayt7^d#hkb7m7g+7^&))9)t5v8u2lm^ctS'

DEBUG = config('DEBUG', default=True, cast=bool)

ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '').split(',')
# ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '').split(',')
ALLOWED_HOSTS = ['*']


# Application definition
Expand Down Expand Up @@ -82,25 +84,25 @@
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# 'NAME': '/data/db.sqlite3',
# }
# }

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv('POSTGRES_DB', 'postgres'),
'USER': os.getenv('POSTGRES_USER', 'postgres'),
'PASSWORD': os.getenv('POSTGRES_PASSWORD', ''),
'HOST': os.getenv('DB_HOST', ''),
'PORT': os.getenv('DB_PORT', 5432)
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
# 'NAME': '/data/db.sqlite3',
}
}

# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql',
# 'NAME': os.getenv('POSTGRES_DB', 'postgres'),
# 'USER': os.getenv('POSTGRES_USER', 'postgres'),
# 'PASSWORD': os.getenv('POSTGRES_PASSWORD', ''),
# 'HOST': os.getenv('DB_HOST', ''),
# 'PORT': os.getenv('DB_PORT', 5432)
# }
# }


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
Expand Down
3 changes: 2 additions & 1 deletion backend/foodgram_project/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ djoser==2.1.0
flake8==6.0.0
flake8-isort==6.0.0

python-decouple==3.8
python-decouple==3.8
reportlab==4.0.9
96 changes: 48 additions & 48 deletions infra/docker-compose.production.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
version: '3.3'

volumes:
pg_data:
static:
media:
static_frontend:

services:

foodgram_db:
image: postgres:13.13
env_file: .env
volumes:
- pg_data:/var/lib/postgresql/data

backend:
image: kseniaaa/foodgram_backend
env_file: .env
volumes:
- static:/app/static_django/
- media:/app/media/
depends_on:
- foodgram_db


frontend:
image: kseniaaa/foodgram_frontend
env_file: .env
command: cp -r /app/build/. /static/
volumes:
- ../frontend/:/app/result_build/


gateway:
# image: nginx:1.19.3
# build: ./
image: kseniaaa/foodgram_gateway
env_file: .env
ports:
- "9000:80"
volumes:
- static:/static_django/
- media:/media/
- static_frontend:/static_frontend/
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ../frontend/build:/usr/share/nginx/html/
- ../docs/:/usr/share/nginx/html/api/docs/
# version: '3.3'

# volumes:
# pg_data:
# static:
# media:
# static_frontend:

# services:

# foodgram_db:
# image: postgres:13.13
# env_file: .env
# volumes:
# - pg_data:/var/lib/postgresql/data

# backend:
# image: kseniaaa/foodgram_backend
# env_file: .env
# volumes:
# - static:/app/static_django/
# - media:/app/media/
# depends_on:
# - foodgram_db


# frontend:
# image: kseniaaa/foodgram_frontend
# env_file: .env
# command: cp -r /app/build/. /static/
# volumes:
# - ../frontend/:/app/result_build/


# gateway:
# # image: nginx:1.19.3
# # build: ./
# image: kseniaaa/foodgram_gateway
# env_file: .env
# ports:
# - "9000:80"
# volumes:
# - static:/static_django/
# - media:/media/
# - static_frontend:/static_frontend/
# - ./nginx.conf:/etc/nginx/conf.d/default.conf
# - ../frontend/build:/usr/share/nginx/html/
# - ../docs/:/usr/share/nginx/html/api/docs/
96 changes: 48 additions & 48 deletions infra/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
version: '3.3'

volumes:
pg_data:
static:
media:
static_frontend:

services:

foodgram_db:
image: postgres:13.13
env_file: .env
volumes:
- pg_data:/var/lib/postgresql/data

backend:
build: ../backend/foodgram_project
env_file: .env
volumes:
- static:/app/static_django/
- media:/app/media/
depends_on:
- foodgram_db


frontend:
build:
context: ../frontend
env_file: .env
command: cp -r /app/build/. /static/
volumes:
- ../frontend/:/app/result_build/


gateway:
image: nginx:1.19.3
build: ./
env_file: .env
ports:
- "9000:80"
volumes:
- static:/static_django/
- media:/media/
- static_frontend:/static_frontend/
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ../frontend/build:/usr/share/nginx/html/
- ../docs/:/usr/share/nginx/html/api/docs/
# version: '3.3'

# volumes:
# pg_data:
# static:
# media:
# static_frontend:

# services:

# foodgram_db:
# image: postgres:13.13
# env_file: .env
# volumes:
# - pg_data:/var/lib/postgresql/data

# backend:
# build: ../backend/foodgram_project
# env_file: .env
# volumes:
# - static:/app/static_django/
# - media:/app/media/
# depends_on:
# - foodgram_db


# frontend:
# build:
# context: ../frontend
# env_file: .env
# command: cp -r /app/build/. /static/
# volumes:
# - ../frontend/:/app/result_build/


# gateway:
# image: nginx:1.19.3
# build: ./
# env_file: .env
# ports:
# - "9000:80"
# volumes:
# - static:/static_django/
# - media:/media/
# - static_frontend:/static_frontend/
# - ./nginx.conf:/etc/nginx/conf.d/default.conf
# - ../frontend/build:/usr/share/nginx/html/
# - ../docs/:/usr/share/nginx/html/api/docs/

0 comments on commit 194e1ea

Please sign in to comment.