Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deps): remove drfaddons dependency (Sourcery refactored) #209

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions drf_user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def update_user_settings() -> dict:

Author: Himanshu Shankar (https://himanshus.com)
"""
custom_settings = getattr(settings, "USER_SETTINGS", None)

if custom_settings:
if custom_settings := getattr(settings, "USER_SETTINGS", None):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function update_user_settings refactored with the following changes:

if not isinstance(custom_settings, dict):
raise TypeError("USER_SETTING must be a dict.")

Expand Down
18 changes: 7 additions & 11 deletions drf_user/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,17 @@ def validate(self, attrs: dict) -> dict:
else:
attrs["prop"] = EMAIL

user = self.get_user(attrs.get("prop"), attrs.get("destination"))
if user := self.get_user(attrs.get("prop"), attrs.get("destination")):
attrs["email"] = user.email
attrs["user"] = user

if not user:
else:
if attrs["is_login"]:
raise NotFound(_("No user exists with provided details"))
if "email" not in attrs.keys() and "verify_otp" not in attrs.keys():
raise serializers.ValidationError(
_("Email field is compulsory while verifying a non-existing user's OTP.")
)
else:
attrs["email"] = user.email
attrs["user"] = user

Comment on lines -193 to -205
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OTPSerializer.validate refactored with the following changes:

return attrs


Expand Down Expand Up @@ -328,13 +326,11 @@ def validate(self, attrs: dict) -> dict:
"""
validator = EmailValidator()
validator(attrs.get("email"))
user = self.get_user(attrs.get("email"))

if not user:
if user := self.get_user(attrs.get("email")):
return attrs
else:
raise NotFound(_("User with the provided email does not exist."))

return attrs
Comment on lines -331 to -336
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PasswordResetSerializer.validate refactored with the following changes:



class ImageSerializer(serializers.ModelSerializer):
"""This serializer is for Image Upload API.
Expand Down
5 changes: 2 additions & 3 deletions drf_user/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def get_client_ip(request: HttpRequest) -> Optional[str]:
-------
ip: str or None
"""
x_forwarded_for = request.META.get("HTTP_X_FORWARDED_FOR")
if x_forwarded_for:
if x_forwarded_for := request.META.get("HTTP_X_FORWARDED_FOR"):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_client_ip refactored with the following changes:

return x_forwarded_for.split(",")[0]
else:
return request.META.get("REMOTE_ADDR")
Expand Down Expand Up @@ -251,7 +250,7 @@ def is_mobile_valid(mobile: str) -> bool:
>>> print(is_mobile_valid('9999999999'))
True
"""
match = re.match(r"^[6-9]\d{9}$", str(mobile))
match = re.match(r"^[6-9]\d{9}$", mobile)
Comment on lines -254 to +253
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_mobile_valid refactored with the following changes:

if match is None:
raise ValidationError("Enter a valid mobile number.")
return True
Expand Down