2021-07-08 17:23:06 +02:00
|
|
|
from django.contrib import messages
|
2021-07-08 11:07:33 +02:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.http import HttpRequest
|
2021-07-08 17:23:06 +02:00
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2021-07-08 11:07:33 +02:00
|
|
|
|
|
|
|
from konova.contexts import BaseContext
|
2021-07-08 17:23:06 +02:00
|
|
|
from user.forms import UserNotificationForm
|
|
|
|
from user.models import KonovaUserExtension
|
2021-07-08 11:07:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def index_view(request: HttpRequest):
|
|
|
|
""" Renders the user's data index view
|
|
|
|
|
|
|
|
Args:
|
|
|
|
request ():
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
template = "user/index.html"
|
|
|
|
context = {
|
|
|
|
"user": request.user,
|
|
|
|
}
|
|
|
|
context = BaseContext(request, context).context
|
|
|
|
return render(request, template, context)
|
2021-07-08 17:23:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def notifications_view(request: HttpRequest):
|
|
|
|
""" Renders the notifications settings view
|
|
|
|
|
|
|
|
Args:
|
|
|
|
request ():
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
template = "user/notifications.html"
|
|
|
|
user = request.user
|
|
|
|
konova_ext = KonovaUserExtension.objects.get_or_create(
|
|
|
|
user=user
|
|
|
|
)[0]
|
|
|
|
|
|
|
|
form = UserNotificationForm(user=user, data=request.POST or None)
|
|
|
|
if request.method == "POST":
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
|
|
|
messages.success(
|
|
|
|
request,
|
|
|
|
_("Notifications edited")
|
|
|
|
)
|
|
|
|
return redirect("user:index")
|
|
|
|
elif request.method == "GET":
|
|
|
|
# Implicit
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"user": user,
|
|
|
|
"form": form,
|
|
|
|
"konova_ext": konova_ext,
|
|
|
|
}
|
|
|
|
context = BaseContext(request, context).context
|
|
|
|
return render(request, template, context)
|