Merge remote-tracking branch 'origin/сja' into Alex

This commit is contained in:
Alex committed 2025-01-29 15:33:35 +03:00
commit 8ff5d93cb1
2 files changed
+2 -35

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ from .views import *
urlpatterns = [
path('testdetail/<int:id>/', TestDetail.as_view(),name='TestDetail'),
path('testlistcreate/', TestListCreate.as_view(), name="TestListCreate"),
path('gettests/', GetTests.as_view(), name="GetTests"),
path('gettesting/', GetTesting.as_view(), name="GetTesting"),
path('testresultcreate/', TestResultCreate.as_view(), name="TestResultCreate"),
]
+1 -34
View File
@@ -20,42 +20,9 @@ import hashlib
from cryptography.fernet import Fernet
from django.db.models import F
class TestListCreate(generics.ListCreateAPIView):
class GetTests(generics.ListAPIView):
queryset = Test.objects.all()
serializer_class = TestsSerializer
def post(self, request, *args, **kwargs):
# user = request.user
# user = User.objects.get(username="9966-00-125")
test = self.create(request, *args, **kwargs)
test_obj = Test.objects.get(id=test.data['id'])
# test = Test.objects.create(data=request.data, author=user)
questions_files = {file.name: file for file in request.FILES.getlist('questionsfiles')}
answers_files = {file.name: file for file in request.FILES.getlist('answersfiles')}
questions = json.loads(request.data['questions'])
for count, question_data in enumerate(questions, start=1):
question_image = questions_files.get(question_data['file']['name']) if 'file' in question_data and question_data['file'] is not None else None
question = TestQuestion.objects.create(
name=question_data['text'],
test=test_obj,
file=question_image,
numb=count,
settings=question_data.get('settings', {}),
)
for answer in question_data['answers']:
answer_image = answers_files.get(answer['file']['name']) if 'file' in answer and answer['file'] is not None else None
TestAnswer.objects.create(
name=answer['text'],
file=answer_image,
question=question
)
return test_obj
class TestDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Test.objects.all()