diff --git a/db.sqlite3 b/db.sqlite3 index 2966ce7..6e8b871 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ 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 @@