-
Notifications
You must be signed in to change notification settings - Fork 27
Story 2448 - Webpage Integration Edit User Profile Avatar #2523
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
Changes from all commits
f7d473c
2fae2bc
c01049a
24509ec
a6c9b4d
8458c08
d26d5c7
d13ab48
25a25b7
f6fb3ee
fce231e
1e365d1
dff4a81
ff853b5
394b533
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Generated by Django 6.0.2 on 2026-07-21 20:48 | ||
|
|
||
| import core.validators | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("users", "0022_user_profile_links"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name="user", | ||
| name="profile_image", | ||
| field=models.FileField( | ||
| blank=True, | ||
| null=True, | ||
| upload_to="profile-images", | ||
| validators=[ | ||
| core.validators.FileTypeValidator( | ||
| extensions=[".jpg", ".jpeg", ".png"] | ||
| ), | ||
| core.validators.MaxFileSizeValidator(max_size=5242880), | ||
| ], | ||
| ), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,17 @@ class CurrentUserAPIView(generics.RetrieveUpdateAPIView): | |
| serializer_class = CurrentUserSerializer | ||
| permission_classes = [IsAuthenticated] | ||
|
|
||
| def perform_update(self, serializer: CurrentUserSerializer): | ||
| instance: User = serializer.save() | ||
| # Only allow for image deletion if the user is allowed to update their image. | ||
| if ( | ||
| self.request.POST.get("delete_profile_image", "").lower() == "true" | ||
| and instance.can_update_image | ||
| ): | ||
| instance.profile_image.delete() | ||
|
Collaborator
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. After deleting the avatar, I found the
Collaborator
Author
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. Good catch, updated. |
||
| instance.image_uploaded = False | ||
| instance.save() | ||
|
Comment on lines
+81
to
+90
Collaborator
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. Nit: I'm just curious, is there a reason why we're having just the deletion handled in this view, and not in the
Collaborator
Author
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. It is handled here because the serializer only has access to its field data in update. While we could add the field to the serializer to give it access to the delete_profile_image data, this is less clear to me since it is a model serializer and that is not a field on the model. |
||
|
|
||
| def get_object(self): | ||
| return self.request.user | ||
|
|
||
|
|
||
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.
Nit: Should we add
required=Falsehere to be consistent?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.
This is actually automagically handled by Django rest framework: https://www.django-rest-framework.org/api-guide/fields/#required