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.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
|
||||||
|
@ -25,8 +26,8 @@ def register(request, event_id):
|
||||||
event = get_object_or_404(Event, id=event_id)
|
event = get_object_or_404(Event, id=event_id)
|
||||||
|
|
||||||
event.eventregistration_set.create(
|
event.eventregistration_set.create(
|
||||||
state=EventRegistration.INTERESTED,
|
state=EventRegistration.INTERESTED,
|
||||||
event=event,
|
event=event,
|
||||||
user=CustomUser.objects.get(),
|
user=CustomUser.objects.get(),
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(reverse("events:index") + f"#{event.id}")
|
return HttpResponseRedirect(reverse("events:index") + f"#{event.id}")
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 = (
|
||||||
|
|
|
@ -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',)
|
||||||
|
|
|
@ -1,15 +1,42 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Profile</title>
|
<title>Profile</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% if user.is_authenticated %}
|
<style>
|
||||||
<p>{{ username }}</p>
|
.container {
|
||||||
{% else %}
|
margin: auto;
|
||||||
<p>Not logged in</p>
|
width: 50%;
|
||||||
<a href="/login/zeus/register">Login</a>
|
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 %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -4,4 +4,5 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('profile', views.profile),
|
path('profile', views.profile),
|
||||||
|
path('logout', views.logout_view)
|
||||||
]
|
]
|
||||||
|
|
|
@ -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')
|
||||||
|
|
Loading…
Reference in a new issue