create_news
This commit is contained in:
1 parent
e2446d3dee
commit
362a9e877c
1 file changed
+19
-5
+19
-5
@@ -24,6 +24,7 @@ from django.db.models import F
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
from vote.views import make_clickable
|
||||
import pytz
|
||||
|
||||
class GetTests(generics.ListAPIView):
|
||||
queryset = Test.objects.all()
|
||||
@@ -294,6 +295,9 @@ class TestingView(generics.ListCreateAPIView):
|
||||
testing = Testing.objects.get(id=testing_id)
|
||||
testing.is_active = False
|
||||
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."},
|
||||
status=200)
|
||||
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(
|
||||
request.data["completion_date"][:-1], "%Y-%m-%dT%H:%M:%S.%f"
|
||||
).strftime("%d.%m.%Y %H:%M")
|
||||
testing_url = make_clickable("Пройдите тестирование!", f"/tests/testing/{testing.test.id}")
|
||||
dt_utc = datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S.%f%z")
|
||||
msk_tz = pytz.timezone("Europe/Moscow")
|
||||
dt_msk = dt_utc.astimezone(msk_tz)
|
||||
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(
|
||||
title="Пройдите тестирование!",
|
||||
text=f'Пройдите тестирование "{testing_url}" до {formatted_date}',
|
||||
cdate=request.data["datestart"],
|
||||
author=request.user,
|
||||
link=os.path.join("defaultimg", "testing.png"),
|
||||
link=testing.test.file,
|
||||
# link=os.path.join("defaultimg", "testing.png"),
|
||||
)
|
||||
news.save()
|
||||
testing.news = news
|
||||
|
||||
Reference in new issue
Block a user