testingview post
This commit is contained in:
1 parent
f9f6d72f93
commit
49bebfef13
1 file changed
+23
-1
+23
-1
@@ -23,6 +23,7 @@ from cryptography.fernet import Fernet
|
||||
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
|
||||
|
||||
class GetTests(generics.ListAPIView):
|
||||
queryset = Test.objects.all()
|
||||
@@ -273,7 +274,7 @@ class TestingView(generics.ListCreateAPIView):
|
||||
completion_date=request.data["completion_date"],
|
||||
test_passed=False,
|
||||
)
|
||||
|
||||
self.create_news(request, testing)
|
||||
return Response(
|
||||
{"status": "success", "message": "Testing created successfully."},
|
||||
status=200,
|
||||
@@ -310,6 +311,27 @@ class TestingView(generics.ListCreateAPIView):
|
||||
print(e)
|
||||
return Response({"status": "error", "message": str(e)}, status=400)
|
||||
|
||||
def create_news(self, request, testing):
|
||||
"""
|
||||
Комментарий
|
||||
"""
|
||||
|
||||
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}")
|
||||
|
||||
news = News(
|
||||
title="Пройдите тестирование!",
|
||||
text=f'Пройдите тестирование "{testing_url}" до {formatted_date}',
|
||||
cdate=request.data["datestart"],
|
||||
author=request.user,
|
||||
link=os.path.join("defaultimg", "testing.png"),
|
||||
)
|
||||
news.save()
|
||||
testing.news = news
|
||||
testing.save()
|
||||
|
||||
class TestResultView(generics.ListCreateAPIView):
|
||||
"""API for getting and saving user test results."""
|
||||
queryset = TestResult.objects.all()
|
||||
|
||||
Reference in new issue
Block a user