forked from horilla-opensource/horilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
60 lines (51 loc) · 1.96 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
employee/accessibility.py
Employee accessibility related methods and functionalites
"""
from django.contrib import messages
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.utils.translation import gettext_lazy as _
from accessibility.accessibility import ACCESSBILITY_FEATURE
from accessibility.filters import AccessibilityFilter
from accessibility.models import DefaultAccessibility
from horilla.decorators import login_required, permission_required
@login_required
@permission_required("auth.change_permission")
def user_accessibility(request):
"""
User accessibility method
"""
if request.POST:
feature = request.POST["feature"]
accessibility = DefaultAccessibility.objects.filter(feature=feature).first()
accessibility = accessibility if accessibility else DefaultAccessibility()
accessibility.feature = feature
accessibility.filter = dict(request.POST)
accessibility.exclude_all = bool(request.POST.get("exclude_all"))
accessibility.save()
if len(request.POST.keys()) > 1:
messages.success(request, _("Accessibility filter saved"))
else:
messages.info(request, _("All filter cleared"))
return HttpResponse("<script>$('#reloadMessagesButton').click()</script>")
accessibility_filter = AccessibilityFilter()
return render(
request,
"accessibility/accessibility.html",
{
"accessibility": ACCESSBILITY_FEATURE,
"accessibility_filter": accessibility_filter,
},
)
@login_required
@permission_required("auth.change_permission")
def get_accessibility_data(request):
"""
Save accessibility filter method
"""
feature = request.GET["feature"]
accessibility = DefaultAccessibility.objects.filter(feature=feature).first()
if not accessibility:
return JsonResponse("", safe=False)
return JsonResponse(accessibility.filter)