Skip to content

feat: add profile picture handling and auto-create UserProfile#37

Merged
emidiovaleretto merged 6 commits into
mainfrom
feature/picture-profile
Jun 12, 2026
Merged

feat: add profile picture handling and auto-create UserProfile#37
emidiovaleretto merged 6 commits into
mainfrom
feature/picture-profile

Conversation

@emidiovaleretto

Copy link
Copy Markdown
Owner

Context

UserProfile had no profile picture, and profiles weren't being created
automatically when a user signed up (they had to be created manually).
This PR addresses both.

What

  • Adds a picture_profile ImageField to UserProfile
  • Resizes uploaded images to a standard width (400px) and converts them to JPEG before saving
  • Auto-creates a UserProfile whenever a new User is created, via a post_save signal
  • Ignores the media/ 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 every
save path (API, admin, shell) goes through it.

Auto-create profile: a UserProfile should always exist for a User.
Using a post_save signal guarantees this regardless of how the user is
created. Discovered while testing — creating a user left it without a profile.

How it works

  • accounts/utils.py: resize_image (proportional resize, LANCZOS) and
    convert_type_image (Pillow → JPEG → Django file via BytesIO/ContentFile)
  • UserProfile.save(): resizes + converts before persisting, only when an image is present
  • accounts/signals.py: create_user_profile receiver, registered in apps.py ready()

Out of scope

  • Placeholder image for users without a photo (next)
  • PNG-with-transparency edge case in JPEG conversion (next)
  • External storage (Cloudinary) for production — separate sprint

How to verify

  • Upload a large image via admin → it's saved resized (~400px) as .jpg under media/photos/...
  • Create a new user → a UserProfile is created automatically

Relates to #35

@emidiovaleretto emidiovaleretto self-assigned this Jun 11, 2026
@emidiovaleretto emidiovaleretto force-pushed the feature/picture-profile branch from 49ac0c2 to 22df3e4 Compare June 11, 2026 18:25
@emidiovaleretto emidiovaleretto merged commit 518eada into main Jun 12, 2026
2 checks passed
@emidiovaleretto emidiovaleretto deleted the feature/picture-profile branch June 12, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant