Add some profile viewing

This commit is contained in:
Maxime Bloch 2020-07-22 05:03:01 +02:00
parent 84a46989ac
commit 146f81b0fe
7 changed files with 51 additions and 15 deletions

View file

@ -1,5 +1,6 @@
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.utils import timezone from django.utils import timezone
from django.urls import reverse from django.urls import reverse
import datetime import datetime

View file

@ -1,3 +1,4 @@
from django.contrib.auth import logout
from django.urls import path from django.urls import path
from . import views from . import views

View file

@ -12,7 +12,7 @@ class CustomUserAdmin(UserAdmin):
list_display = ('username', 'is_staff', 'is_superuser') list_display = ('username', 'is_staff', 'is_superuser')
list_filter = ('username', 'is_staff') list_filter = ('username', 'is_staff')
fieldsets = ( fieldsets = (
(None, {'fields': ('username', 'password')}), (None, {'fields': ('username', 'password', 'student_number', 'real_name',)}),
('Permissions', {'fields': ('is_staff', 'is_superuser')}), ('Permissions', {'fields': ('is_staff', 'is_superuser')}),
) )
add_fieldsets = ( add_fieldsets = (

View file

@ -6,10 +6,10 @@ from .models import CustomUser
class CustomUserCreationForm(UserCreationForm): class CustomUserCreationForm(UserCreationForm):
class Meta(UserCreationForm): class Meta(UserCreationForm):
model = CustomUser model = CustomUser
fields = ('username',) fields = ('username', 'student_number', 'real_name',)
class CustomUserChangeForm(UserChangeForm): class CustomUserChangeForm(UserChangeForm):
class Meta: class Meta:
model = CustomUser model = CustomUser
fields = ('username',) fields = ('username', 'student_number', 'real_name',)

View file

@ -5,11 +5,38 @@
<title>Profile</title> <title>Profile</title>
</head> </head>
<body> <body>
{% if user.is_authenticated %} <style>
<p>{{ username }}</p> .container {
{% else %} margin: auto;
width: 50%;
padding: 10px;
}
input {
width: 100%;
}
input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
</style>
<div class="container">
<h1>Profile</h1>
{% if user.is_authenticated %}
<p>Username: {{ username }}</p>
<label>Student number</label>
<input type="text" value="{{ user.student_number }}"/>
<label>Real name</label>
<input type="text" value="{{ user.real_name }}">
<input type="submit" value="Save"/>
<a href="/user/logout">Logout</a>
{% else %}
<p>Not logged in</p> <p>Not logged in</p>
<a href="/login/zeus/register">Login</a> <a href="/login/zeus/register">Login</a>
{% endif %} {% endif %}
</div>
</body> </body>
</html> </html>

View file

@ -4,4 +4,5 @@ from . import views
urlpatterns = [ urlpatterns = [
path('profile', views.profile), path('profile', views.profile),
path('logout', views.logout_view)
] ]

View file

@ -1,6 +1,12 @@
from django.http import HttpResponse from django.contrib.auth import logout
from django.shortcuts import render from django.shortcuts import render, redirect
def profile(request): def profile(request):
return render(request, "profile.html", {"username": request.user.username}) return render(request, "profile.html", {"username": request.user.username})
def logout_view(request):
logout(request)
return redirect('/user/profile')