Exemple #1
0
class SignUpView(CreateAPIView):
    serializer_class = get_class(SIGNUP_REQUEST_SERIALIZER, SignUpSerializer)
    serializer_class_response = get_class(SIGNUP_RESPONSE_SERIALIZER, SignUpSerializer)

    @staticmethod
    def on_save_success(instance):
        if instance and instance.requires_verification:
            token, code = instance.request_verification(send_mail=True)
class ProfileView(generics.RetrieveUpdateDestroyAPIView):
    lookup_field = USER_LOOKUP_FIELD
    queryset = get_user_model().objects.all()
    # on provides (`dict`) data usable in `serializer_class_response`
    serializer_class = get_class(PROFILE_REQUEST_SERIALIZER,
                                 profile.ProfileSerializer)
    # does normal operations of `serializer_class` would it not have been used to provide data
    serializer_class_response = get_class(PROFILE_RESPONSE_SERIALIZER,
                                          profile.ProfileSerializer)
    permission_classes = [
        IsOwnerOrSuperuserOrReadOnly,
    ]

    def get_serializer(self, *args, **kwargs):
        request_serializer = self.serializer_class(
            data=kwargs.get('data'),
            context=self.get_serializer_context(),
        )
        if request_serializer.is_valid(raise_exception=False):
            kwargs['data'] = request_serializer.data
        return super().get_serializer(*args, **kwargs)

    def get_serializer_class(self):
        return self.serializer_class_response or super().get_serializer_class()
Exemple #3
0
class AuthSerializer(
        get_class(PROFILE_REQUEST_SERIALIZER, profile.ProfileSerializer)):
    token = serializers.DictField(
        source='token.tokens',
        read_only=True,
    )

    class Meta(
            get_class(PROFILE_REQUEST_SERIALIZER,
                      profile.ProfileSerializer).Meta):
        fields = tuple(
            get_class(PROFILE_REQUEST_SERIALIZER,
                      profile.ProfileSerializer).Meta.fields) + ('token', )

    def validate(self, attrs):
        return super().validate(attrs)
Exemple #4
0
 class Meta(
         get_class(PROFILE_REQUEST_SERIALIZER,
                   profile.ProfileSerializer).Meta):
     fields = tuple(
         get_class(PROFILE_REQUEST_SERIALIZER,
                   profile.ProfileSerializer).Meta.fields) + ('token', )
Exemple #5
0
 def test_class_name_returns_default_class_name_for_empty_class_string(self):
     class_name = get_class('', None)
     self.assertEqual(class_name, None)
Exemple #6
0
 def test_class_name_does_not_return_default_class_if_passed_class_name_string_is_valid(self):
     class_name = get_class('xauth.tests.test_xauth_utils.XauthUtilTest', TestCase)
     self.assertNotEqual(class_name, TestCase)
Exemple #7
0
 def test_class_name_returns_correct_class_name_for_valid_class_string(self):
     class_name = get_class('xauth.tests.test_xauth_utils.XauthUtilTest', )
     self.assertEqual(class_name, XauthUtilTest)
Exemple #8
0
 def test_class_name_returns_default_class_name_for_invalid_class_string(self):
     class_name = get_class('invalidclass', XauthUtilTest)
     self.assertEqual(class_name, XauthUtilTest)
     class_name = get_class('xauth.tests.test_xauth_utils.XauthUtil Test', XauthUtilTest)
     self.assertEqual(class_name, XauthUtilTest)