Skip to content

Commit

Permalink
changed edit profile view from def to class
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayliable committed Mar 20, 2024
1 parent 4a1d6c1 commit 15e9aef
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
Binary file modified db.sqlite3
Binary file not shown.
2 changes: 1 addition & 1 deletion portfolio_site_IMD2900/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion register/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class UpdateUserForm(UserChangeForm):

class Meta:
model = User
fields = ["username", "email", "password"]
fields = ["username", "email"]
19 changes: 10 additions & 9 deletions register/views.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
File renamed without changes.
15 changes: 15 additions & 0 deletions templates/nav-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
<li class="nav-item">
<a class="nav-link" href="/upload_view"> Add Image </a>
</li>
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="/edit_profile"> Edit Profile </a>
</li>
<li class="nav-item">
<a class="nav-link" href="/logout"> Log Out </a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="/register"> Register </a>
</li>
<li class="nav-item">
<a class="nav-link" href="/login"> Log In </a>
</li>
{% endif %}
</ul>
</div>
</nav>
Expand Down

0 comments on commit 15e9aef

Please sign in to comment.