diff --git a/edx_name_affirmation/models.py b/edx_name_affirmation/models.py index 14ef24b..0dc2056 100644 --- a/edx_name_affirmation/models.py +++ b/edx_name_affirmation/models.py @@ -45,6 +45,20 @@ class Meta: db_table = 'nameaffirmation_verifiedname' verbose_name = 'verified name' + @property + def verification_attempt_status(self): + if not self.verification_attempt_id: + return None + + try: + from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification + except ImportError: + return None + + verification = SoftwareSecurePhotoVerification.objects.get(id=self.verification_attempt_id) + + return verification.status if verification else None + class VerifiedNameConfig(ConfigurationModel): """ diff --git a/edx_name_affirmation/serializers.py b/edx_name_affirmation/serializers.py index 8ca7b20..08e0f43 100644 --- a/edx_name_affirmation/serializers.py +++ b/edx_name_affirmation/serializers.py @@ -19,25 +19,10 @@ class VerifiedNameSerializer(serializers.ModelSerializer): verified_name = serializers.CharField(required=True) profile_name = serializers.CharField(required=True) verification_attempt_id = serializers.IntegerField(required=False, allow_null=True) - verification_attempt_status = serializers.SerializerMethodField('get_verification_attempt_status') + verification_attempt_status = serializers.CharField() proctored_exam_attempt_id = serializers.IntegerField(required=False, allow_null=True) status = serializers.CharField(required=False, allow_null=True) - def get_verification_attempt_status(self, obj): - try: - from lms.djangoapps.verify_student.services import IDVerificationService # pylint: disable=import-error,import-outside-toplevel - except ImportError: - return None - - idv_attempt_id = obj.verification_attempt_id - - if not idv_attempt_id: - return None - - verification = IDVerificationService.get_verification_details_by_id(idv_attempt_id) - - return verification.status if verification else None - class Meta: """ Meta Class diff --git a/edx_name_affirmation/tests/test_models.py b/edx_name_affirmation/tests/test_models.py index 1f22e35..043c1bf 100644 --- a/edx_name_affirmation/tests/test_models.py +++ b/edx_name_affirmation/tests/test_models.py @@ -8,6 +8,11 @@ from edx_name_affirmation.models import VerifiedName from edx_name_affirmation.statuses import VerifiedNameStatus +try: + from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification +except ImportError: + pass + User = get_user_model()