95 lines
2.3 KiB
Python
95 lines
2.3 KiB
Python
from django.contrib import messages
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
|
from user.models import User
|
|
from django.http import HttpRequest
|
|
from django.shortcuts import render, redirect, get_object_or_404
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from konova.contexts import BaseContext
|
|
from konova.decorators import any_group_check
|
|
from user.forms import UserNotificationForm, UserContactForm
|
|
|
|
|
|
@login_required
|
|
@any_group_check
|
|
def index_view(request: HttpRequest):
|
|
""" Renders the user's data index view
|
|
|
|
Args:
|
|
request ():
|
|
|
|
Returns:
|
|
|
|
"""
|
|
template = "user/index.html"
|
|
context = {
|
|
"user": request.user,
|
|
TAB_TITLE_IDENTIFIER: _("User settings"),
|
|
}
|
|
context = BaseContext(request, context).context
|
|
return render(request, template, context)
|
|
|
|
|
|
@login_required
|
|
@any_group_check
|
|
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,
|
|
TAB_TITLE_IDENTIFIER: _("User notifications"),
|
|
}
|
|
context = BaseContext(request, context).context
|
|
return render(request, template, context)
|
|
|
|
|
|
@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)
|
|
form = UserContactForm(request.POST or None, instance=user, request=request)
|
|
template = "modal/modal_form.html"
|
|
context = {
|
|
"form": form,
|
|
}
|
|
context = BaseContext(request, context).context
|
|
return render(
|
|
request,
|
|
template,
|
|
context
|
|
) |