возврат каталога(все тесты)
This commit is contained in:
1 parent
97c877473e
commit
5bb55627f0
2 files changed
+2
-35
No files matched your search
@@ -4,7 +4,7 @@ from .views import *
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('testdetail/<int:id>/', TestDetail.as_view(),name='TestDetail'),
|
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('gettesting/', GetTesting.as_view(), name="GetTesting"),
|
||||||
path('testresultcreate/', TestResultCreate.as_view(), name="TestResultCreate"),
|
path('testresultcreate/', TestResultCreate.as_view(), name="TestResultCreate"),
|
||||||
]
|
]
|
||||||
|
|||||||
+1
-34
@@ -20,43 +20,10 @@ import hashlib
|
|||||||
from cryptography.fernet import Fernet
|
from cryptography.fernet import Fernet
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
|
|
||||||
class TestListCreate(generics.ListCreateAPIView):
|
class GetTests(generics.ListAPIView):
|
||||||
queryset = Test.objects.all()
|
queryset = Test.objects.all()
|
||||||
serializer_class = TestsSerializer
|
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):
|
class TestDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
queryset = Test.objects.all()
|
queryset = Test.objects.all()
|
||||||
serializer_class = TestSerializer
|
serializer_class = TestSerializer
|
||||||
|
|||||||
Reference in new issue
Block a user