-
Notifications
You must be signed in to change notification settings - Fork 447
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
enhanced code of user.py with dict.get() #1116
Closed
+31
−74
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9ee3866
enhanced code of user.py with dict.get()
aakankshaagr 91d35dc
reformatted user.py with black
aakankshaagr b97edb5
resolved errors due to dict.get()
aakankshaagr e7f07fe
reformatted with black
aakankshaagr 2f8713a
made chamges in users.py to increase coverage
aakankshaagr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -44,11 +44,11 @@ def create_user(data: Dict[str, str]): | |||||||||
A tuple with two elements. The first element is a dictionary containing a key 'message' containing a string which indicates whether or not the user was created successfully. The second is the HTTP response code. | ||||||||||
""" | ||||||||||
|
||||||||||
name = data["name"] | ||||||||||
username = data["username"] | ||||||||||
password = data["password"] | ||||||||||
email = data["email"] | ||||||||||
terms_and_conditions_checked = data["terms_and_conditions_checked"] | ||||||||||
name = data.get("name", None) | ||||||||||
username = data.get("username", None) | ||||||||||
password = data.get("password", None) | ||||||||||
email = data.get("email", None) | ||||||||||
terms_and_conditions_checked = data.get("terms_and_conditions_checked", None) | ||||||||||
|
||||||||||
existing_user = UserModel.find_by_username(data["username"]) | ||||||||||
if existing_user: | ||||||||||
|
@@ -66,10 +66,10 @@ def create_user(data: Dict[str, str]): | |||||||||
|
||||||||||
user = UserModel(name, username, password, email, terms_and_conditions_checked) | ||||||||||
if "need_mentoring" in data: | ||||||||||
user.need_mentoring = data["need_mentoring"] | ||||||||||
user.need_mentoring = data.get("need_mentoring", None) | ||||||||||
|
||||||||||
if "available_to_mentor" in data: | ||||||||||
user.available_to_mentor = data["available_to_mentor"] | ||||||||||
user.available_to_mentor = data.get("available_to_mentor", None) | ||||||||||
|
||||||||||
user.save_to_db() | ||||||||||
|
||||||||||
|
@@ -244,73 +244,46 @@ def update_user_profile(user_id: int, data: Dict[str, str]): | |||||||||
user.username = username | ||||||||||
|
||||||||||
if "name" in data and data["name"]: | ||||||||||
user.name = data["name"] | ||||||||||
user.name = data.get("name", None) or None | ||||||||||
|
||||||||||
if "bio" in data: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above similar for other cases as well |
||||||||||
if data["bio"]: | ||||||||||
user.bio = data["bio"] | ||||||||||
else: | ||||||||||
user.bio = None | ||||||||||
user.bio = data.get("bio", None) | ||||||||||
|
||||||||||
if "location" in data: | ||||||||||
if data["location"]: | ||||||||||
user.location = data["location"] | ||||||||||
else: | ||||||||||
user.location = None | ||||||||||
user.location = data.get("location", None) | ||||||||||
|
||||||||||
if "occupation" in data: | ||||||||||
if data["occupation"]: | ||||||||||
user.occupation = data["occupation"] | ||||||||||
else: | ||||||||||
user.occupation = None | ||||||||||
user.occupation = data.get("occupation", None) or None | ||||||||||
|
||||||||||
if "organization" in data: | ||||||||||
if data["organization"]: | ||||||||||
user.organization = data["organization"] | ||||||||||
else: | ||||||||||
user.organization = None | ||||||||||
user.organization = data.get("organization", None) or None | ||||||||||
|
||||||||||
if "slack_username" in data: | ||||||||||
if data["slack_username"]: | ||||||||||
user.slack_username = data["slack_username"] | ||||||||||
else: | ||||||||||
user.slack_username = None | ||||||||||
user.slack_username = data.get("slack_username", None) | ||||||||||
|
||||||||||
if "social_media_links" in data: | ||||||||||
if data["social_media_links"]: | ||||||||||
user.social_media_links = data["social_media_links"] | ||||||||||
else: | ||||||||||
user.social_media_links = None | ||||||||||
user.social_media_links = data.get("social_media_links", None) | ||||||||||
|
||||||||||
if "skills" in data: | ||||||||||
if data["skills"]: | ||||||||||
user.skills = data["skills"] | ||||||||||
else: | ||||||||||
user.skills = None | ||||||||||
user.skills = data.get("skills", None) | ||||||||||
|
||||||||||
if "interests" in data: | ||||||||||
if data["interests"]: | ||||||||||
user.interests = data["interests"] | ||||||||||
else: | ||||||||||
user.interests = None | ||||||||||
user.interests = data.get("interests", None) | ||||||||||
|
||||||||||
if "resume_url" in data: | ||||||||||
if data["resume_url"]: | ||||||||||
user.resume_url = data["resume_url"] | ||||||||||
else: | ||||||||||
user.resume_url = None | ||||||||||
user.resume_url = data.get("resume_url", None) | ||||||||||
|
||||||||||
if "photo_url" in data: | ||||||||||
if data["photo_url"]: | ||||||||||
user.photo_url = data["photo_url"] | ||||||||||
else: | ||||||||||
user.photo_url = None | ||||||||||
user.photo_url = data.get("photo_url", None) | ||||||||||
|
||||||||||
if "need_mentoring" in data: | ||||||||||
user.need_mentoring = data["need_mentoring"] | ||||||||||
user.need_mentoring = data.get("need_mentoring", None) | ||||||||||
|
||||||||||
if "available_to_mentor" in data: | ||||||||||
user.available_to_mentor = data["available_to_mentor"] | ||||||||||
user.available_to_mentor = data.get("available_to_mentor", None) | ||||||||||
|
||||||||||
user.save_to_db() | ||||||||||
|
||||||||||
|
@@ -332,8 +305,8 @@ def change_password(user_id: int, data: Dict[str, str]): | |||||||||
|
||||||||||
""" | ||||||||||
|
||||||||||
current_password = data["current_password"] | ||||||||||
new_password = data["new_password"] | ||||||||||
current_password = data.get("current_password", None) | ||||||||||
new_password = data.get("new_password", None) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None can be removed here as it is the default value returned
Suggested change
|
||||||||||
|
||||||||||
user = UserModel.find_by_id(user_id) | ||||||||||
if user.check_password(current_password): | ||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need these if conditions too