From 146f81b0feeeca65d0fb9d2ea04877aa9b3bc76b Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Wed, 22 Jul 2020 05:03:01 +0200 Subject: [PATCH] Add some profile viewing --- events/views.py | 7 +++--- oauth/urls.py | 1 + users/admin.py | 2 +- users/forms.py | 4 ++-- users/templates/profile.html | 41 ++++++++++++++++++++++++++++++------ users/urls.py | 1 + users/views.py | 10 +++++++-- 7 files changed, 51 insertions(+), 15 deletions(-) diff --git a/events/views.py b/events/views.py index d2bb975..c2a1367 100644 --- a/events/views.py +++ b/events/views.py @@ -1,5 +1,6 @@ from django.http import HttpResponseRedirect from django.shortcuts import render, get_object_or_404 + from django.utils import timezone from django.urls import reverse import datetime @@ -25,8 +26,8 @@ def register(request, event_id): event = get_object_or_404(Event, id=event_id) event.eventregistration_set.create( - state=EventRegistration.INTERESTED, - event=event, - user=CustomUser.objects.get(), + state=EventRegistration.INTERESTED, + event=event, + user=CustomUser.objects.get(), ) return HttpResponseRedirect(reverse("events:index") + f"#{event.id}") diff --git a/oauth/urls.py b/oauth/urls.py index e36421a..383cc5b 100644 --- a/oauth/urls.py +++ b/oauth/urls.py @@ -1,3 +1,4 @@ +from django.contrib.auth import logout from django.urls import path from . import views diff --git a/users/admin.py b/users/admin.py index 2980848..b7ebc91 100644 --- a/users/admin.py +++ b/users/admin.py @@ -12,7 +12,7 @@ class CustomUserAdmin(UserAdmin): list_display = ('username', 'is_staff', 'is_superuser') list_filter = ('username', 'is_staff') fieldsets = ( - (None, {'fields': ('username', 'password')}), + (None, {'fields': ('username', 'password', 'student_number', 'real_name',)}), ('Permissions', {'fields': ('is_staff', 'is_superuser')}), ) add_fieldsets = ( diff --git a/users/forms.py b/users/forms.py index d08ecbd..1b3b845 100644 --- a/users/forms.py +++ b/users/forms.py @@ -6,10 +6,10 @@ from .models import CustomUser class CustomUserCreationForm(UserCreationForm): class Meta(UserCreationForm): model = CustomUser - fields = ('username',) + fields = ('username', 'student_number', 'real_name',) class CustomUserChangeForm(UserChangeForm): class Meta: model = CustomUser - fields = ('username',) + fields = ('username', 'student_number', 'real_name',) diff --git a/users/templates/profile.html b/users/templates/profile.html index 33ca143..33c40ee 100644 --- a/users/templates/profile.html +++ b/users/templates/profile.html @@ -1,15 +1,42 @@ - - Profile + + Profile -{% if user.is_authenticated %} -

{{ username }}

-{% else %} -

Not logged in

- Login + +
+

Profile

+ {% if user.is_authenticated %} +

Username: {{ username }}

+ + + + + + Logout + {% else %} +

Not logged in

+ Login {% endif %} +
diff --git a/users/urls.py b/users/urls.py index 88d0fbc..0f4c3e9 100644 --- a/users/urls.py +++ b/users/urls.py @@ -4,4 +4,5 @@ from . import views urlpatterns = [ path('profile', views.profile), + path('logout', views.logout_view) ] diff --git a/users/views.py b/users/views.py index 693e1d4..fc41d10 100644 --- a/users/views.py +++ b/users/views.py @@ -1,6 +1,12 @@ -from django.http import HttpResponse -from django.shortcuts import render +from django.contrib.auth import logout +from django.shortcuts import render, redirect def profile(request): return render(request, "profile.html", {"username": request.user.username}) + + +def logout_view(request): + logout(request) + + return redirect('/user/profile')