File tree Expand file tree Collapse file tree 3 files changed +10
-17
lines changed
Expand file tree Collapse file tree 3 files changed +10
-17
lines changed Original file line number Diff line number Diff line change @@ -44,9 +44,7 @@ def update_user_settings() -> dict:
4444
4545 Author: Himanshu Shankar (https://himanshus.com)
4646 """
47- custom_settings = getattr (settings , "USER_SETTINGS" , None )
48-
49- if custom_settings :
47+ if custom_settings := getattr (settings , "USER_SETTINGS" , None ):
5048 if not isinstance (custom_settings , dict ):
5149 raise TypeError ("USER_SETTING must be a dict." )
5250
Original file line number Diff line number Diff line change @@ -190,19 +190,17 @@ def validate(self, attrs: dict) -> dict:
190190 else :
191191 attrs ["prop" ] = EMAIL
192192
193- user = self .get_user (attrs .get ("prop" ), attrs .get ("destination" ))
193+ if user := self .get_user (attrs .get ("prop" ), attrs .get ("destination" )):
194+ attrs ["email" ] = user .email
195+ attrs ["user" ] = user
194196
195- if not user :
197+ else :
196198 if attrs ["is_login" ]:
197199 raise NotFound (_ ("No user exists with provided details" ))
198200 if "email" not in attrs .keys () and "verify_otp" not in attrs .keys ():
199201 raise serializers .ValidationError (
200202 _ ("Email field is compulsory while verifying a non-existing user's OTP." )
201203 )
202- else :
203- attrs ["email" ] = user .email
204- attrs ["user" ] = user
205-
206204 return attrs
207205
208206
@@ -323,13 +321,11 @@ def validate(self, attrs: dict) -> dict:
323321 """
324322 validator = EmailValidator ()
325323 validator (attrs .get ("email" ))
326- user = self .get_user (attrs .get ("email" ))
327-
328- if not user :
324+ if user : = self .get_user (attrs .get ("email" )):
325+ return attrs
326+ else :
329327 raise NotFound (_ ("User with the provided email does not exist." ))
330328
331- return attrs
332-
333329
334330class ImageSerializer (serializers .ModelSerializer ):
335331 """This serializer is for Image Upload API.
Original file line number Diff line number Diff line change @@ -40,8 +40,7 @@ def get_client_ip(request: HttpRequest) -> Optional[str]:
4040 -------
4141 ip: str or None
4242 """
43- x_forwarded_for = request .META .get ("HTTP_X_FORWARDED_FOR" )
44- if x_forwarded_for :
43+ if x_forwarded_for := request .META .get ("HTTP_X_FORWARDED_FOR" ):
4544 return x_forwarded_for .split ("," )[0 ]
4645 else :
4746 return request .META .get ("REMOTE_ADDR" )
@@ -251,7 +250,7 @@ def validate_mobile(mobile: str) -> bool:
251250 >>> print(validate_mobile('9999999999'))
252251 True
253252 """
254- match = re .match (r"^[6-9]\d{9}$" , str ( mobile ) )
253+ match = re .match (r"^[6-9]\d{9}$" , mobile )
255254 if match is None :
256255 raise ValidationError ("Invalid Mobile Number" )
257256 return True
You can’t perform that action at this time.
0 commit comments