From 15e9aef5bc0438bf6857a72354bcf96bb3ac2747 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 20 Mar 2024 19:40:57 -0400 Subject: [PATCH] changed edit profile view from def to class --- db.sqlite3 | Bin 147456 -> 147456 bytes portfolio_site_IMD2900/urls.py | 2 +- register/forms.py | 2 +- register/views.py | 19 +++++++++--------- .../edit_profile.html | 0 templates/nav-bar.html | 15 ++++++++++++++ 6 files changed, 27 insertions(+), 11 deletions(-) rename {register/templates/registration => templates}/edit_profile.html (100%) diff --git a/db.sqlite3 b/db.sqlite3 index 2966ce76eeef1325c27c1a11aee4bb697e613a18..6e8b871949ed271c8e684b0a6b31d77aa33930e3 100644 GIT binary patch delta 516 zcmZo@;B08%oFL6uJ5k1&v36s^vUs*F4E%|FTQ(~ytl$%9)MDagXtXuv6qYpR_+^jUSg{hu{#kbPYB+(>0w;<0lC$YlZ z!Z6#yEHT|QFD*4Oy`VBR-Ke-Y)!4wwuqe;e!^6t0peVyAt1vJ;z{fCCH!LDByecO# zKff#>#Wyn3+cL*D$-g+lGo>WT)BxfVkYnHu*RwD(H#M~=VFTHkX_=ipS#?gH8V9Ry zb1*?iOwOOR*$eCjC;!y)sv^Tgqu{c#faG$MAdeD{fW#2@z$DASV$X>7PT zF@LoJ2hT(|s%v zR diff --git a/portfolio_site_IMD2900/urls.py b/portfolio_site_IMD2900/urls.py index 27e2bc9..ad7c96f 100644 --- a/portfolio_site_IMD2900/urls.py +++ b/portfolio_site_IMD2900/urls.py @@ -9,7 +9,7 @@ path('admin/', admin.site.urls), path('', include("home.urls")), path('register/', regv.register, name="register"), - path('edit_profile/', regv.update_profile, name="edit_profile"), + path('edit_profile/', regv.ProfileEditView.as_view(), name="edit_profile"), path('logout/', regv.logout_view, name="logout"), path('', include("django.contrib.auth.urls")), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/register/forms.py b/register/forms.py index 8443ddd..fac06a0 100644 --- a/register/forms.py +++ b/register/forms.py @@ -17,4 +17,4 @@ class UpdateUserForm(UserChangeForm): class Meta: model = User - fields = ["username", "email", "password"] + fields = ["username", "email"] diff --git a/register/views.py b/register/views.py index 2b1105f..998517a 100644 --- a/register/views.py +++ b/register/views.py @@ -1,6 +1,10 @@ +from django.contrib.auth.forms import UserChangeForm from django.shortcuts import render, redirect +from django.urls import reverse_lazy + from .forms import RegisterForm, UpdateUserForm from django.contrib.auth import login, logout +from django.views.generic import UpdateView # Create your views here. @@ -21,13 +25,10 @@ def logout_view(request): return render(request, "home.html") -def update_profile(response): - if response.method == "POST": - form = UpdateUserForm(response.POST) - if form.is_valid(): - form.save() - return redirect("/") - else: - form = UpdateUserForm() - return render(response, "registration/edit_profile.html", {"form": form}) +class ProfileEditView(UpdateView): + template_name = "edit_profile.html" + form_class = UserChangeForm + success_url = reverse_lazy('home') + def get_object(self, queryset=None): + return self.request.user diff --git a/register/templates/registration/edit_profile.html b/templates/edit_profile.html similarity index 100% rename from register/templates/registration/edit_profile.html rename to templates/edit_profile.html diff --git a/templates/nav-bar.html b/templates/nav-bar.html index 5d2c0d6..82c3455 100644 --- a/templates/nav-bar.html +++ b/templates/nav-bar.html @@ -36,6 +36,21 @@ + {% if user.is_authenticated %} + + + {% else %} + + + {% endif %}