diff options
| author | Bobby <[email protected]> | 2023-01-02 14:22:04 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-01-02 14:22:04 -0500 |
| commit | 5a40fdd435185290b77596b792d3f6eb81819c16 (patch) | |
| tree | 4f35500b301740d591d5998f1de9d02db718b607 /users | |
| parent | 24183dbddd0db7c34a020f65e8c52cffadc9b49e (diff) | |
| download | thatcomputerscientist-5a40fdd435185290b77596b792d3f6eb81819c16.tar.xz thatcomputerscientist-5a40fdd435185290b77596b792d3f6eb81819c16.zip | |
post improvements and avatar chooser
Diffstat (limited to 'users')
| -rw-r--r-- | users/urls.py | 1 | ||||
| -rw-r--r-- | users/views.py | 20 |
2 files changed, 18 insertions, 3 deletions
diff --git a/users/urls.py b/users/urls.py index 02a7e302..1450653e 100644 --- a/users/urls.py +++ b/users/urls.py @@ -12,6 +12,7 @@ urlpatterns = [ path('/verifyemail/<uidb64>/<token>', views.verify_email, name='verifyemail'), path('/sendchangeuseremail', views.send_change_user_email, name='sendchangeuseremail'), path('/changeemail/<uidb64>/<token>', views.change_email, name='changeemail'), + path('updateavatar', views.update_avatar, name='updateavatar'), ] # Configure Admin Site diff --git a/users/views.py b/users/views.py index 05d379ff..5027bd64 100644 --- a/users/views.py +++ b/users/views.py @@ -51,7 +51,6 @@ def update_user(request): first_name = request.POST['firstname'] last_name = request.POST['lastname'] location = request.POST['location'] - gravatar_email = request.POST['gravatarEmail'] bio = request.POST['bio'] is_public = False email_public = False @@ -69,13 +68,12 @@ def update_user(request): try: user_profile = UserProfile.objects.get(user=username) user_profile.location = location - user_profile.gravatar_email = gravatar_email user_profile.bio = bio user_profile.is_public = is_public user_profile.email_public = email_public user_profile.save() except UserProfile.DoesNotExist: - user_profile = UserProfile(user=username, location=location, gravatar_email=gravatar_email, bio=bio, is_public=is_public, email_public=email_public) + user_profile = UserProfile(user=username, location=location, bio=bio, is_public=is_public, email_public=email_public) user_profile.save() messages.success(request, 'Profile was successfully updated!') return redirect('blog:account') @@ -83,6 +81,22 @@ def update_user(request): messages.error(request, 'Unable to update profile! Please try again later.') return redirect('blog:home') +def update_avatar(request): + user = request.user + if user is not None: + if request.method == 'POST': + user_profile = UserProfile.objects.get(user=user) + user_profile.avatar_url = request.POST['avatar'] + user_profile.save() + messages.success(request, 'Avatar was successfully updated!') + return redirect('blog:account') + else: + messages.error(request, 'Unable to update avatar! Please try again later.') + return redirect('blog:home') + else: + messages.error(request, 'You must be logged in to update your avatar!') + return redirect('blog:home') + def change_password(request): username = request.user |
