Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:mails #242

Merged
merged 6 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions api_spot/api/views/avatar.py

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions api_spot/api/views/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from api.serializers.order import (
OrderGetSerializer, OrderSerializer, OrderUpdateSerializer,
)
from api.services.orders import order_cancel_email, order_confirmation_email
from api.services.orders import order_cancel_email
from spots.constants import CANCEL, PAID, WAIT_PAY
from spots.models import Order

Expand All @@ -34,10 +34,6 @@ def get_serializer_class(self):
return OrderUpdateSerializer
return super().get_serializer_class()

def perform_create(self, serializer):
instance = serializer.save()
order_confirmation_email(instance)

def update(self, request, location_id, spot_id, pk, *args, **kwargs):
instance = get_object_or_404(
Order, pk=pk,
Expand Down
4 changes: 2 additions & 2 deletions api_spot/api/views/pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from api.exceptions import OrderStatusError
from api.permissions import IsOwnerOrReadOnly
# from api.serializers.pay import PaySerializer
from api.services.orders import order_finished_email
from api.services.orders import order_confirmation_email
from spots.constants import PAID, WAIT_PAY
from spots.models import Order

Expand Down Expand Up @@ -47,7 +47,7 @@ def patch(
raise OrderStatusError
order.status = PAID
order.save()
order_finished_email(order)
order_confirmation_email(order)
return Response(
# serializer.data,
{'message': 'Заказ оплачен'},
Expand Down
17 changes: 17 additions & 0 deletions api_spot/spots/migrations/0014_alter_order_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.5 on 2023-10-27 14:16

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('spots', '0013_alter_location_days_open'),
]

operations = [
migrations.AlterModelOptions(
name='order',
options={'ordering': ('-date', 'start_time'), 'verbose_name': 'Заказ', 'verbose_name_plural': 'Заказы'},
),
]
2 changes: 1 addition & 1 deletion api_spot/spots/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Meta:
"""Класс Meta для Order описание метаданных."""
verbose_name = 'Заказ'
verbose_name_plural = 'Заказы'
ordering = ('date', 'start_time')
ordering = ('-date', 'start_time')

def __str__(self) -> str:
return f'Локация id = {self.spot.location.id}, спот={self.spot.id}'
9 changes: 7 additions & 2 deletions api_spot/spots/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from celery import shared_task
from django.shortcuts import get_object_or_404

from api.services.orders import order_finished_email
from api_spot.celery import app
from spots.constants import FINISH, NOT_PAID, PAID, WAIT_PAY

Expand All @@ -24,9 +25,13 @@ def change_status_task(order_id: int) -> str:
def repeat_orders_finish() -> str:
"""Периодичная задача, которая завершает заказы, которые закончились."""
hour = int(datetime.datetime.now().time().isoformat('hours'))
Order.objects.filter(
orders = Order.objects.filter(
date__lte=datetime.datetime.now().date(),
end_time=datetime.time(hour),
status=PAID
).update(status=FINISH)
)
for order in orders:
order.status = FINISH
order.save()
order_finished_email(order)
return "Статусы заказов, которые закончились изменены"
2 changes: 1 addition & 1 deletion api_spot/users/service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
import os
import uuid


def get_avatar_path(instance, filename):
Expand Down
Loading