Merge branch 'сja' into develop
This commit is contained in:
commit
05763b620d
5 files changed
+38
-17
No files matched your search
@@ -65,7 +65,7 @@ class TestResult(models.Model):
|
||||
|
||||
class Testing(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
tests = models.ForeignKey(Test, on_delete=models.PROTECT, blank=False, verbose_name="Тест")
|
||||
test = models.ForeignKey(Test, on_delete=models.PROTECT, blank=False, verbose_name="Тест")
|
||||
completion_date = models.DateField(blank=True, null=True, verbose_name="Дата прохождения теста")
|
||||
test_passed = models.BooleanField(blank=False, verbose_name="Тест пройден")
|
||||
|
||||
|
||||
@@ -23,4 +23,10 @@ class TestQuestionSerializer(serializers.ModelSerializer):
|
||||
answers = TestAnswerSerializer(many=True, read_only=True)
|
||||
class Meta:
|
||||
model = TestQuestion
|
||||
fields = '__all__'
|
||||
|
||||
class TestingSeriaizer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Testing
|
||||
fields = '__all__'
|
||||
@@ -4,7 +4,7 @@ from .views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('testdetail/<int:id>/', TestDetail.as_view(),name='TestDetail'),
|
||||
# path('appointmentusers/', GetAppointmentsUsers.as_view(), name="getappointmentusers"),
|
||||
# path('accomplished/', GetAccompishedTests.as_view(), name="getaccomplished"),
|
||||
path('testlist/', TestList.as_view(), name="TestList"),
|
||||
path('gettesting/', GetTesting.as_view(), name="GetTesting"),
|
||||
]
|
||||
|
||||
+18
-1
@@ -14,9 +14,26 @@ import os
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
import html
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
class TestDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
queryset = Test.objects.all()
|
||||
serializer_class = TestSerializer
|
||||
lookup_url_kwarg = 'id'
|
||||
lookup_field = 'id'
|
||||
lookup_field = 'id'
|
||||
|
||||
class TestList(generics.ListAPIView):
|
||||
queryset = Test.objects.all()
|
||||
serializer_class = TestSerializer
|
||||
|
||||
class GetTesting(APIView):
|
||||
|
||||
def get(self, request):
|
||||
user = request.user
|
||||
tests = Testing.objects.filter(user=user)
|
||||
test_names = {test.id: test.test.name for test in tests}
|
||||
serializer = TestingSeriaizer(tests, many=True).data
|
||||
for test in serializer:
|
||||
if test['id'] in test_names:
|
||||
test['test_name'] = test_names[test['id']]
|
||||
return Response(serializer)
|
||||
+11
-13
@@ -202,18 +202,14 @@ class GetResults(APIView):
|
||||
|
||||
return Response(serialized_data)
|
||||
|
||||
from rest_framework.views import exception_handler
|
||||
class VoteResultCreate(APIView):
|
||||
class VoteResultCreate(generics.ListCreateAPIView):
|
||||
queryset = Result.objects.all()
|
||||
serializer_class = ResultSerializer
|
||||
|
||||
def post(self, request):
|
||||
user_id = request.user.id
|
||||
answer_ids = [item['answer'] for item in request.data]
|
||||
answers = Answer.objects.in_bulk(answer_ids)
|
||||
vote = list(answers.values())[0].question.vote
|
||||
results = Result.objects.bulk_create(
|
||||
[Result(answer=answers[answer_id], user_id=user_id) for answer_id in answer_ids]
|
||||
)
|
||||
serializer = ResultSerializer(results, many=True)
|
||||
def create(self, request, *args, **kwargs):
|
||||
serializer = self.get_serializer(data=request.data, many=True)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return Response(serializer.data)
|
||||
|
||||
def get_employees_serializer(ids):
|
||||
@@ -224,8 +220,10 @@ def get_employees_serializer(ids):
|
||||
|
||||
def set_real_departments(employees):
|
||||
employee_departments = EmployeeDepartment.objects.filter(employee__in=employees)
|
||||
department_map = {ed.employee.id: ed.department for ed in employee_departments}
|
||||
departments = DictDepartment.objects.in_bulk([ed.department.id for ed in employee_departments])
|
||||
department_map = {ed.employee.id: {'name': ed.department.name, 'id': departments[ed.department.id]} for ed in employee_departments}
|
||||
|
||||
for employee in employees:
|
||||
if employee.id in department_map:
|
||||
employee.department = department_map[employee.id]
|
||||
employee.department = department_map[employee.id]['name']
|
||||
employee.id_dict_department = department_map[employee.id]['id']
|
||||
Reference in new issue
Block a user