Skip to content

Commit

Permalink
Merge pull request #277 from ZUS666/develop
Browse files Browse the repository at this point in the history
deploy
  • Loading branch information
ZUS666 authored Nov 17, 2023
2 parents 7a8710e + 26fe732 commit a0d3f5c
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ repos:
rev: v0.991
hooks:
- id: mypy
exclude: 'migrations'
exclude: 'migrations'
4 changes: 1 addition & 3 deletions api_spot/api/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ def me(self, request, *args, **kwargs):
"""
Получение пользователем информации информацию о себе.
"""
email = request.user.email
user = User.objects.get(email=email)
serializer = self.get_serializer(user)
serializer = self.get_serializer(request.user)
return Response(serializer.data, status=status.HTTP_200_OK)

@me.mapping.patch
Expand Down
6 changes: 1 addition & 5 deletions api_spot/api_spot/settings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import os
from pathlib import Path

from dotenv import load_dotenv


load_dotenv()

BASE_DIR = Path(__file__).resolve().parent.parent

Expand Down Expand Up @@ -129,7 +125,7 @@

CSRF_TRUSTED_ORIGINS = (
'http://localhost',
'https://' + os.getenv('ALLOWED_HOSTS')
'https://' + os.getenv('ALLOWED_HOSTS', 'host')
)

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Expand Down
10 changes: 2 additions & 8 deletions api_spot/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ boto3==1.28.66
celery[redis]==5.3.4
Django==4.2.7
django-celery-beat==2.5.0
django-celery-results==2.5.1
django-cors-headers==3.8.0
django-filter==23.2
django-gmailapi-backend==0.3.2
django-phonenumber-field[phonenumberslite]==7.1.0
django-cleanup==8.0.0
django-ckeditor==6.7.0
djangorestframework==3.14.0
django-storages==1.14.2
django-storages[s3]==1.14.2
djoser==2.2.0
drf-api-logger==1.1.14
drf-spectacular==0.26.4
Expand All @@ -18,10 +19,3 @@ gunicorn==21.2.0
phonenumbers==8.13.20
Pillow==10.0.1
psycopg2-binary==2.9.7
pytest==7.4.3
pytest-django==4.7.0
pytest-drf==1.1.3
pytest-redis==3.0.2
pytest-celery==0.0.0
python-dotenv==1.0.0
django-celery-results==2.5.1
12 changes: 6 additions & 6 deletions api_spot/spots/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
FINISH: str = 'Завершен'
CANCEL: str = 'Отменен'
NOT_PAID: str = 'Не оплачено'
ORDER_STATUS_CHOICES: tuple[str, str] = (
ORDER_STATUS_CHOICES: tuple[tuple[str, str], ...] = (
(WAIT_PAY, WAIT_PAY),
(NOT_PAID, NOT_PAID),
(PAID, PAID),
(FINISH, FINISH),
(CANCEL, CANCEL)
)
MINUTES: str = 'minutes'
START_CHOICES: tuple[datetime.time, datetime.time] = tuple([
START_CHOICES: tuple[tuple[datetime.time, str], ...] = tuple(
(
datetime.time(x),
datetime.time(x).isoformat(MINUTES)
)
for x in range(0, 24)
])
END_CHOICES: tuple[datetime.time, datetime.time] = tuple([
)
END_CHOICES: tuple[tuple[datetime.time, str], ...] = tuple(
(
datetime.time(x),
datetime.time(x - 1, 55).isoformat(MINUTES)
Expand All @@ -42,7 +42,7 @@
datetime.time(23, 55).isoformat(MINUTES)
)
for x in range(1, 25)
])
)
MAX_COUNT_DAYS: int = 60
# Price
MIN_VALUE = 1
Expand All @@ -59,7 +59,7 @@
LONG_MSG_ERROR = 'Долгота должна быть в диапазоне от -180 до 180'
NAME_CACHE_WORKSPACE = 'workspace'
NAME_CACHE_MEETING_ROOM = 'meeting_room'
DAYS_CHOICES: tuple[str, str] = (
DAYS_CHOICES: tuple[tuple[str, str], ...] = (
('Пн-Вс', 'Пн-Вс'),
('Пн-Сб', 'Пн-Сб'),
('Пн-Пт', 'Пн-Пт'),
Expand Down
4 changes: 2 additions & 2 deletions api_spot/spots/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def get_bill(self) -> Decimal:
return self.bill

@property
def date_finish(self) -> datetime:
def date_finish(self) -> datetime.datetime:
"""Свойство , возращает datetime конца брони."""
return datetime.datetime.strptime(
f'{self.date} {self.end_time}', '%Y-%m-%d %H:%M:%S'
)

def validate_unique(self, *args, **kwargs):
super(Order, self).validate_unique(*args, **kwargs)
super().validate_unique(*args, **kwargs)
check_spot_order(self)

def clean(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions api_spot/users/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
from django.utils.safestring import mark_safe
from django.utils.safestring import SafeString, mark_safe
from django.utils.translation import gettext_lazy as _

from users.models import Avatar
Expand Down Expand Up @@ -63,7 +63,7 @@ class AvatarAdmin(admin.ModelAdmin):
list_per_page = 15
list_max_show_all = 30

def preview(self, obj):
def preview(self, obj: Avatar) -> SafeString:
if obj.image:
return mark_safe(
f'<img src="{obj.image.url}" style="max-height: 300px;">'
Expand Down
29 changes: 23 additions & 6 deletions api_spot/users/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import PermissionsMixin
Expand All @@ -13,7 +15,13 @@ class MyUserManager(BaseUserManager):
"""
Кастомный менеджер для модели User
"""
def _create_user(self, email, password, **extra_fields):

def _create_user(
self,
email: str,
password: str,
**extra_fields: Any
) -> AbstractBaseUser:
"""
Создает и сохраняет юзера с почтой, телефоном, и паролем
"""
Expand All @@ -25,7 +33,12 @@ def _create_user(self, email, password, **extra_fields):
user.save(using=self._db)
return user

def create_user(self, email, password, **extra_fields):
def create_user(
self,
email: str,
password: str,
**extra_fields: Any
) -> AbstractBaseUser:
"""
Создает юзера
"""
Expand All @@ -37,7 +50,12 @@ def create_user(self, email, password, **extra_fields):
**extra_fields
)

def create_superuser(self, email, password, **extra_fields):
def create_superuser(
self,
email: str,
password: str,
**extra_fields: Any
) -> AbstractBaseUser:
"""
Создает суперюзера
"""
Expand Down Expand Up @@ -111,18 +129,17 @@ class User(AbstractBaseUser, PermissionsMixin):

EMAIL_FIELD = 'email'
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []

objects = MyUserManager()

def __str__(self):
def __str__(self) -> str:
return self.email

class Meta:
verbose_name = 'Пользователь'
verbose_name_plural = 'Пользователи'

def clean(self):
def clean(self) -> None:
super().clean()
self.email = self.__class__.objects.normalize_email(self.email)

Expand Down
8 changes: 5 additions & 3 deletions api_spot/users/service.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import uuid

from django.db.models import Model

def get_avatar_path(instance, filename):

def get_avatar_path(instance: Model, filename: str) -> str:
"""Загрузка с уникальным именем."""
ext = filename.split('.')[-1]
filename = "%s.%s" % (uuid.uuid4(), ext)
ext: str = filename.split('.')[-1]
filename = f'{uuid.uuid4()}.{ext}'
return os.path.join('images/users', filename)
9 changes: 5 additions & 4 deletions api_spot/users/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
from django.utils.deconstruct import deconstructible


def validate_birth_day(value):
def validate_birth_day(value: date) -> None:
if date.today() < value:
raise ValidationError('Не валидная дата рождения')


@deconstructible
class NamesValidator(RegexValidator):
regex = r'^[\bА-яа-яёЁA-Za-z][А-яа-яёЁA-Za-z .\'-]*[\bА-яа-яёЁA-Za-z]$'
message = (
regex: str = (
r'^[\bА-яа-яёЁA-Za-z][А-яа-яёЁA-Za-z .\'-]*[\bА-яа-яёЁA-Za-z]$'
)
message: str = (
'Может содержать только буквы, дефисы, точки.'
)
flags = 0
37 changes: 37 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
boto3==1.28.66
celery[redis]==5.3.4
Django==4.2.7
django-celery-beat==2.5.0
django-celery-results==2.5.1
django-cors-headers==3.8.0
django-filter==23.2
django-gmailapi-backend==0.3.2
django-phonenumber-field[phonenumberslite]==7.1.0
django-cleanup==8.0.0
django-ckeditor==6.7.0
djangorestframework==3.14.0
django-storages[s3]==1.14.2
djoser==2.2.0
drf-api-logger==1.1.14
drf-spectacular==0.26.4
flower==2.0.1
gunicorn==21.2.0
phonenumbers==8.13.20
Pillow==10.0.1
psycopg2-binary==2.9.7
# tests
pytest==7.4.3
pytest-django==4.7.0
pytest-drf==1.1.3
pytest-redis==3.0.2
pytest-celery==0.0.0
python-dotenv==1.0.0
model-bakery==1.17.0
# pre-commit
pre-commit==3.5.0
# api analyze
kolo==2.15.1
# codestyle
flake8==6.1.0
flake8-isort==6.1.0
isort==5.12.0
10 changes: 9 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ sections =
STDLIB,
THIRDPARTY,
FIRSTPARTY,
LOCALFOLDER
LOCALFOLDER

[mypy]
disallow_untyped_defs = True
ignore_missing_imports = True
check_untyped_defs = True
show_error_codes = True
# warn_unused_ignores = True
exclude = ['venv', '*/migrations/',]

0 comments on commit a0d3f5c

Please sign in to comment.