kers/users/views.py

32 lines
882 B
Python
Raw Normal View History

2020-07-22 16:06:04 +02:00
from pprint import pprint
2020-07-22 05:03:01 +02:00
from django.contrib.auth import logout
2020-07-22 16:06:04 +02:00
from django.http import HttpResponseRedirect
2020-07-22 05:03:01 +02:00
from django.shortcuts import render, redirect
2020-07-22 17:33:35 +02:00
from django.urls import reverse
2020-07-22 04:21:29 +02:00
2020-07-22 16:06:04 +02:00
from users.forms import UserMetaForm
from users.models import CustomUser
2020-07-22 04:21:29 +02:00
def profile(request):
if request.method == "POST":
if not request.user.is_authenticated:
return HttpResponseRedirect(reverse("users:profile"))
2020-07-22 17:33:35 +02:00
2020-07-22 16:06:04 +02:00
form = UserMetaForm(request.POST, instance=request.user)
if form.is_valid():
form.save()
2020-07-22 17:33:35 +02:00
return HttpResponseRedirect(reverse("users:profile"))
2020-07-22 16:06:04 +02:00
else:
form = UserMetaForm(instance=request.user) if request.user.is_authenticated else None
2020-07-22 05:03:01 +02:00
return render(request, "users/profile.html", {"form": form})
2020-07-22 05:03:01 +02:00
def logout_view(request):
logout(request)
2020-07-22 17:33:35 +02:00
return redirect(reverse("users:profile"))