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):
|
2020-07-22 17:37:40 +02:00
|
|
|
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:
|
2020-07-22 17:37:40 +02:00
|
|
|
form = UserMetaForm(instance=request.user) if request.user.is_authenticated else None
|
2020-07-22 05:03:01 +02:00
|
|
|
|
2020-07-22 17:37:40 +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"))
|