fix highlight logic
This commit is contained in:
@@ -130,7 +130,11 @@ class Route(models.Model):
|
||||
"""Проверяем, выделено ли объявление на текущий момент"""
|
||||
if not self.highlight_end_DT:
|
||||
return False
|
||||
return timezone.now() <= self.highlight_end_DT
|
||||
|
||||
now = timezone.now()
|
||||
result = now <= self.highlight_end_DT
|
||||
|
||||
return result
|
||||
|
||||
class Meta:
|
||||
verbose_name = (u'Маршрут')
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from rest_framework.decorators import api_view, permission_classes
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from .models import Route
|
||||
|
||||
@api_view(['PATCH'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def highlight_route(request):
|
||||
try:
|
||||
route_id = request.data.get('route_id')
|
||||
route = Route.objects.get(id=route_id, owner=request.user)
|
||||
|
||||
# подсвечиваем объявление на 24 часа
|
||||
route.highlight_end_DT = timezone.now() + timedelta(days=1)
|
||||
route.is_highlighted = True
|
||||
route.save()
|
||||
|
||||
return Response({'status': 'success'})
|
||||
except Route.DoesNotExist:
|
||||
return Response(
|
||||
{'error': 'Маршрут не найден или у вас нет прав для его изменения'},
|
||||
status=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
except Exception as e:
|
||||
return Response(
|
||||
{'error': str(e)},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
)
|
||||
Reference in New Issue
Block a user