feat: add profile picture handling and auto-create UserProfile#37
Merged
Conversation
49ac0c2 to
22df3e4
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Context
UserProfilehad no profile picture, and profiles weren't being createdautomatically when a user signed up (they had to be created manually).
This PR addresses both.
What
picture_profileImageField toUserProfileUserProfilewhenever a newUseris created, via apost_savesignalmedia/directory in git (user uploads shouldn't be versioned)Why
Picture handling: users upload images of any size/format. Normalizing
to a fixed width and a single format (JPEG) keeps storage consistent and
avoids broken layouts. Resizing happens in the model's
save(), so everysave path (API, admin, shell) goes through it.
Auto-create profile: a
UserProfileshould always exist for aUser.Using a
post_savesignal guarantees this regardless of how the user iscreated. Discovered while testing — creating a user left it without a profile.
How it works
accounts/utils.py:resize_image(proportional resize, LANCZOS) andconvert_type_image(Pillow → JPEG → Django file via BytesIO/ContentFile)UserProfile.save(): resizes + converts before persisting, only when an image is presentaccounts/signals.py:create_user_profilereceiver, registered inapps.pyready()Out of scope
How to verify
.jpgundermedia/photos/...UserProfileis created automaticallyRelates to #35