create_news

This commit is contained in:
cja committed 2025-06-02 11:38:19 +03:00
1 parent e2446d3dee
commit 362a9e877c
1 file changed
+19 -5
+19 -5
View File
@@ -24,6 +24,7 @@ from django.db.models import F
from drf_yasg import openapi from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema from drf_yasg.utils import swagger_auto_schema
from vote.views import make_clickable from vote.views import make_clickable
import pytz
class GetTests(generics.ListAPIView): class GetTests(generics.ListAPIView):
queryset = Test.objects.all() queryset = Test.objects.all()
@@ -294,6 +295,9 @@ class TestingView(generics.ListCreateAPIView):
testing = Testing.objects.get(id=testing_id) testing = Testing.objects.get(id=testing_id)
testing.is_active = False testing.is_active = False
testing.save() testing.save()
if testing.news is not None:
Testing.objects.filter(news=testing.news).delete()
testing.news.delete()
return Response({"status": "success", "message": "Testing is not active."}, return Response({"status": "success", "message": "Testing is not active."},
status=200) status=200)
except DatabaseError as e: except DatabaseError as e:
@@ -315,18 +319,28 @@ class TestingView(generics.ListCreateAPIView):
""" """
Комментарий Комментарий
""" """
# formatted_date = datetime.strptime(
# request.data["completion_date"][:-1], "%Y-%m-%dT%H:%M:%S.%f"
# ).strftime("%d.%m.%Y %H:%M")
date_str = request.data["completion_date"]
if date_str.endswith('Z'):
date_str = date_str[:-1] + '+0000' # pytz требует формат +HHMM
formatted_date = datetime.strptime( dt_utc = datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S.%f%z")
request.data["completion_date"][:-1], "%Y-%m-%dT%H:%M:%S.%f" msk_tz = pytz.timezone("Europe/Moscow")
).strftime("%d.%m.%Y %H:%M") dt_msk = dt_utc.astimezone(msk_tz)
testing_url = make_clickable("Пройдите тестирование!", f"/tests/testing/{testing.test.id}") formatted_date = dt_msk.strftime("%d.%m.%Y %H:%M")
testing_url = make_clickable(testing.test.name,
f"/test/testdetail/{testing.test.id}?mode=exam")
news = News( news = News(
title="Пройдите тестирование!", title="Пройдите тестирование!",
text=f'Пройдите тестирование "{testing_url}" до {formatted_date}', text=f'Пройдите тестирование "{testing_url}" до {formatted_date}',
cdate=request.data["datestart"], cdate=request.data["datestart"],
author=request.user, author=request.user,
link=os.path.join("defaultimg", "testing.png"), link=testing.test.file,
# link=os.path.join("defaultimg", "testing.png"),
) )
news.save() news.save()
testing.news = news testing.news = news