chore [P-01]: подтянул бэк

This commit is contained in:
Denis Voinovich committed 2025-05-29 13:41:30 +03:00
commit ba1b3d3724
2 files changed
+15 -2

No files matched your search

+14 -2
View File
@@ -104,6 +104,7 @@ class TestResultSerializer(serializers.ModelSerializer):
class TestsSerializer(serializers.ModelSerializer): class TestsSerializer(serializers.ModelSerializer):
dateend = serializers.SerializerMethodField() dateend = serializers.SerializerMethodField()
is_passed = serializers.SerializerMethodField() is_passed = serializers.SerializerMethodField()
is_active = serializers.SerializerMethodField()
class Meta: class Meta:
model = Test model = Test
@@ -114,7 +115,8 @@ class TestsSerializer(serializers.ModelSerializer):
if not user.is_authenticated: if not user.is_authenticated:
return None return None
testing = Testing.objects.filter(test=obj, user=user).order_by('-completion_date').first() # testing = Testing.objects.filter(test=obj, user=user, is_active=True).order_by('-completion_date').first()
testing = Testing.objects.filter(test=obj, user=user, is_active=True).first()
if testing and testing.completion_date: if testing and testing.completion_date:
return testing.completion_date return testing.completion_date
return None return None
@@ -124,11 +126,21 @@ class TestsSerializer(serializers.ModelSerializer):
if not user.is_authenticated: if not user.is_authenticated:
return None return None
testing = Testing.objects.filter(test=obj, user=user, is_active=True).order_by('-completion_date').first() testing = Testing.objects.filter(test=obj, user=user, is_active=True).first()
if testing and testing.test_passed: if testing and testing.test_passed:
return testing.test_passed return testing.test_passed
return None return None
def get_is_active(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).first()
if testing and testing.is_active:
return testing.is_active
return False
def create(self, validated_data): def create(self, validated_data):
user = self.context['request'].user user = self.context['request'].user
if user.is_authenticated: if user.is_authenticated:
+1
View File
@@ -263,6 +263,7 @@ class TestingView(generics.ListCreateAPIView):
return Response({"status": "error", "message": str(e)}, status=400) return Response({"status": "error", "message": str(e)}, status=400)
def put(self, request): def put(self, request):
"""when removing testing from an employee"""
testing_id = request.data.get("id") testing_id = request.data.get("id")
try: try:
testing = Testing.objects.get(id=testing_id) testing = Testing.objects.get(id=testing_id)