Add some profile viewing
This commit is contained in:
parent
84a46989ac
commit
146f81b0fe
7 changed files with 51 additions and 15 deletions
|
@ -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}")
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from django.contrib.auth import logout
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
|
|
@ -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 = (
|
||||
|
|
|
@ -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',)
|
||||
|
|
|
@ -1,15 +1,42 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Profile</title>
|
||||
<meta charset="UTF-8">
|
||||
<title>Profile</title>
|
||||
</head>
|
||||
<body>
|
||||
{% if user.is_authenticated %}
|
||||
<p>{{ username }}</p>
|
||||
{% else %}
|
||||
<p>Not logged in</p>
|
||||
<a href="/login/zeus/register">Login</a>
|
||||
<style>
|
||||
.container {
|
||||
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>
|
||||
<a href="/login/zeus/register">Login</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -4,4 +4,5 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path('profile', views.profile),
|
||||
path('logout', views.logout_view)
|
||||
]
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue