testing is_active

This commit is contained in:
cja committed 2025-05-29 12:00:00 +03:00
1 parent 25810b0fcc
commit bfd67c8a17
3 files changed
+25 -1

No files matched your search

+1
View File
@@ -75,6 +75,7 @@ class Testing(models.Model):
null=True,
verbose_name="Дата завершения тестирования")
test_passed = models.BooleanField(blank=False, verbose_name="Тест пройден")
is_active = models.BooleanField(default=True, verbose_name="Тестирование активно")
class Meta:
verbose_name = "Тестирование"
+12 -1
View File
@@ -82,7 +82,7 @@ class TestingSeriaizer(serializers.ModelSerializer):
class Meta:
model = Testing
fields = ['id', 'user', 'test', 'completion_date', 'test_passed', 'user_details']
fields = '__all__'
class TestAttemptSerializer(serializers.ModelSerializer):
@@ -103,6 +103,7 @@ class TestResultSerializer(serializers.ModelSerializer):
class TestsSerializer(serializers.ModelSerializer):
dateend = serializers.SerializerMethodField()
is_passed = serializers.SerializerMethodField()
class Meta:
model = Test
@@ -118,6 +119,16 @@ class TestsSerializer(serializers.ModelSerializer):
return testing.completion_date
return None
def get_is_passed(self, obj):
user = self.context['request'].user
if not user.is_authenticated:
return None
testing = Testing.objects.filter(test=obj, user=user, is_active=True).order_by('-completion_date').first()
if testing and testing.test_passed:
return testing.test_passed
return None
def create(self, validated_data):
user = self.context['request'].user
if user.is_authenticated:
+12
View File
@@ -262,6 +262,18 @@ class TestingView(generics.ListCreateAPIView):
print(e)
return Response({"status": "error", "message": str(e)}, status=400)
def put(self, request):
testing_id = request.data.get("id")
try:
testing = Testing.objects.get(id=testing_id)
testing.is_active = False
testing.save()
return Response({"status": "success", "message": "Testing is not active."},
status=200)
except DatabaseError as e:
print(e)
return Response({"status": "error", "message": str(e)}, status=400)
def delete(self, request):
testing_id = request.data.get("id")
try: