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
|
2022-01-20 12:31:20 +01:00
|
|
|
|
|
|
|
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
2022-01-12 12:56:22 +01:00
|
|
|
from user.models import User
|
2021-07-08 11:07:33 +02:00
|
|
|
from django.http import HttpRequest
|
2021-08-02 14:10:57 +02:00
|
|
|
from django.shortcuts import render, redirect, get_object_or_404
|
2021-07-08 17:23:06 +02:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2021-07-08 11:07:33 +02:00
|
|
|
|
|
|
|
from konova.contexts import BaseContext
|
2021-08-03 09:45:41 +02:00
|
|
|
from konova.decorators import any_group_check
|
2021-08-02 14:10:57 +02:00
|
|
|
from user.forms import UserNotificationForm, UserContactForm
|
2021-07-08 11:07:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2021-08-03 09:45:41 +02:00
|
|
|
@any_group_check
|
2021-07-08 11:07:33 +02:00
|
|
|
def index_view(request: HttpRequest):
|
|
|
|
""" Renders the user's data index view
|
|
|
|
|
|
|
|
Args:
|
|
|
|
request ():
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
template = "user/index.html"
|
|
|
|
context = {
|
|
|
|
"user": request.user,
|
2022-01-20 12:31:20 +01:00
|
|
|
TAB_TITLE_IDENTIFIER: _("User settings"),
|
2021-07-08 11:07:33 +02:00
|
|
|
}
|
|
|
|
context = BaseContext(request, context).context
|
|
|
|
return render(request, template, context)
|
2021-07-08 17:23:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2021-08-03 09:45:41 +02:00
|
|
|
@any_group_check
|
2021-07-08 17:23:06 +02:00
|
|
|
def notifications_view(request: HttpRequest):
|
|
|
|
""" Renders the notifications settings view
|
|
|
|
|
|
|
|
Args:
|
|
|
|
request ():
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
template = "user/notifications.html"
|
|
|
|
user = request.user
|
|
|
|
|
|
|
|
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,
|
2022-01-20 12:31:20 +01:00
|
|
|
TAB_TITLE_IDENTIFIER: _("User notifications"),
|
2021-07-08 17:23:06 +02:00
|
|
|
}
|
|
|
|
context = BaseContext(request, context).context
|
|
|
|
return render(request, template, context)
|
2021-08-02 14:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def contact_view(request: HttpRequest, id: str):
|
|
|
|
""" Renders contact modal view of a users contact data
|
|
|
|
|
|
|
|
Args:
|
|
|
|
request (HttpRequest): The incoming request
|
|
|
|
id (str): The user's id
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
user = get_object_or_404(User, id=id)
|
2021-11-17 14:33:05 +01:00
|
|
|
form = UserContactForm(request.POST or None, instance=user, request=request)
|
2021-08-02 14:10:57 +02:00
|
|
|
template = "modal/modal_form.html"
|
|
|
|
context = {
|
|
|
|
"form": form,
|
|
|
|
}
|
|
|
|
context = BaseContext(request, context).context
|
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
template,
|
|
|
|
context
|
|
|
|
)
|