is_active test
This commit is contained in:
1 parent
7ae3dbd5b3
commit
c2cfdbbd2a
2 files changed
+12
No files matched your search
@@ -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
|
||||||
@@ -129,6 +130,16 @@ class TestsSerializer(serializers.ModelSerializer):
|
|||||||
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)
|
||||||
|
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:
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in new issue
Block a user