[UPDT] LEAVE: Add next and previous data-action in individual view

This commit is contained in:
Horilla
2024-09-12 14:09:05 +05:30
parent 6feacbb954
commit 750be958a5
6 changed files with 211 additions and 216 deletions

View File

@@ -1,33 +1,47 @@
{% load i18n static %}
{% load basefilters %}
{% if instances_ids %}
{% if messages %}
<div class="oh-wrapper">
{% for message in messages %}
<div class="oh-alert-container">
<div class="oh-alert oh-alert--animated {{message.tags}}">
{{ message }}
</div>
</div>
{% endfor %}
</div>
<span hx-trigger="load" hx-get="{% url 'leave-allocation-request-filter' %}" hx-target="#view-container"></span>
{% endif %}
{% if instances_ids and leave_allocation_request %}
<div class="oh-modal__dialog oh-modal__dialog--navigation m-0 p-0">
<button
hx-get="{% url 'leave-allocation-request-single-view' previous %}?instances_ids={{instances_ids}}&my_request={{my_request}}&dashboard={{dashboard}}"
hx-target="#objectDetailsModalW25Target"
class="oh-modal__diaglog-nav oh-modal__nav-prev">
class="oh-modal__diaglog-nav oh-modal__nav-prev"
data-action="previous">
<ion-icon name="chevron-back-outline" class="md hydrated" role="img"
aria-label="chevron back outline"></ion-icon>
</button>
<button
hx-get="{% url 'leave-allocation-request-single-view' next %}?instances_ids={{instances_ids}}&my_request={{my_request}}&dashboard={{dashboard}}"
hx-target="#objectDetailsModalW25Target"
class="oh-modal__diaglog-nav oh-modal__nav-next">
class="oh-modal__diaglog-nav oh-modal__nav-next"
data-action="next">
<ion-icon name="chevron-forward-outline" class="md hydrated" role="img"
aria-label="chevron forward outline"></ion-icon>
</button>
</div>
{% endif %}
</div>
<div class="oh-modal__dialog-header">
<h2 class="oh-modal__dialog-title" id="objectDetailsModalLabel">
{% trans "Details" %}
{% trans "Details" %}
</h2>
<button class="oh-modal__close" aria-label="Close">
<ion-icon name="close-outline" role="img" class="md hydrated" aria-label="close outline"></ion-icon>
</button>
</div>
{% if leave_allocation_request %}
<div class="oh-modal__dialog-body">
<a class="oh-timeoff-modal__profile-content" style="text-decoration:none;"
href ="{% url 'employee-view-individual' leave_allocation_request.employee_id.id %}">
@@ -138,9 +152,9 @@
</button></td>
{% endif %}
{% if leave_allocation_request.status != 'approved' %}
<a class="oh-btn oh-btn--danger w-100" id="delete-link"
href="{% url 'leave-allocation-request-delete' leave_allocation_request.id %}"
onclick="return confirm('{% trans "Are you sure you want to delete ?" %}');"
<a class="oh-btn oh-btn--danger w-100" id="delete-link" hx-target="#objectDetailsModalW25Target"
hx-confirm="{% trans 'Are you sure you want to delete ?' %}"
hx-post="{% url 'leave-allocation-request-delete' leave_allocation_request.id %}?instances_ids={{instances_ids}}&my_request={{my_request}}&dashboard={{dashboard}}"
title="{% trans 'Delete' %}">
<ion-icon
name="trash-outline"
@@ -198,3 +212,16 @@
</div>
</div>
</div>
{% else %}
<div class="oh-modal__dialog-body oh-modal__dialog-relative pt-2">
<img
style="margin-left: 29%; width: 150px; height: 150px"
src="{% static 'images/ui/attendance.png' %}"
class="oh-404__image mb-2"
alt="Page not found. 404."
/>
<h5 class="oh-404__subtitle">
{% trans "There are no leave allocation requests at the moment." %}
</h5>
</div>
{% endif %}

View File

@@ -1,156 +1,118 @@
{% load static %} {% load i18n %} {% load basefilters %} {% load horillafilters %}
{% if messages %}
<div class="oh-wrapper">
{% for message in messages %}
<div class="oh-alert-container">
<div class="oh-alert oh-alert--animated {{message.tags}}">
{{ message }}
<div class="oh-wrapper">
{% for message in messages %}
<div class="oh-alert-container">
<div class="oh-alert oh-alert--animated {{message.tags}}">
{{ message }}
</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
<span hx-trigger="load" hx-get="{% url 'assign-filter' %}?{{pd}}" hx-target="#assignedLeaves"></span>
{% endif %}
<div class="oh-modal__dialog-header">
<h2
class="oh-modal__dialog-title"
id="assignedLeaveModalLabel"
>
{% trans "Details" %}
</h2>
<button class="oh-modal__close" aria-label="Close">
<ion-icon name="close-outline"></ion-icon>
</button>
<h2 class="oh-modal__dialog-title" id="assignedLeaveModalLabel">
{% trans "Details" %}
</h2>
<button class="oh-modal__close" aria-label="Close">
<ion-icon name="close-outline"></ion-icon>
</button>
</div>
<div class="oh-modal__dialog-body oh-modal__dialog-relative">
<div class="oh-modal__dialog oh-modal__dialog--navigation m-0 p-0">
<button
hx-get="{% url 'available-leave-single-view' previous_instance %}?instances_ids={{instance_ids_json}}"
hx-target="#objectDetailsModalTarget"
class="oh-modal__diaglog-nav oh-modal__nav-prev"
>
<ion-icon
name="chevron-back-outline"
class="md hydrated"
role="img"
aria-label="chevron back outline"
></ion-icon>
</button>
{% if available_leave %}
<div class="oh-modal__dialog oh-modal__dialog--navigation m-0 p-0">
<button hx-get="{% url 'available-leave-single-view' previous_instance %}?{{pd}}&instances_ids={{instance_ids_json}}"
hx-target="#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-prev"
data-action="previous">
<ion-icon name="chevron-back-outline" class="md hydrated" role="img"
aria-label="chevron back outline"></ion-icon>
</button>
<button
hx-get="{% url 'available-leave-single-view' next_instance %}?instances_ids={{instance_ids_json}}"
hx-target="#objectDetailsModalTarget"
class="oh-modal__diaglog-nav oh-modal__nav-next"
>
<ion-icon
name="chevron-forward-outline"
class="md hydrated"
role="img"
aria-label="chevron forward outline"
></ion-icon>
</button>
</div>
{% if available_leave %}
<a
class="oh-timeoff-modal__profile-content"
style="text-decoration: none"
href="{% url 'employee-view-individual' available_leave.employee_id.id %}"
>
<div class="oh-profile mb-2">
<div class="oh-profile__avatar">
<img
src="{{available_leave.employee_id.get_avatar}}"
class="oh-profile__image me-2"
alt="Mary Magdalene"
/>
</div>
<div class="oh-timeoff-modal__profile-info">
<span class="oh-timeoff-modal__user fw-bold"
>{{available_leave.employee_id}}</span
>
<span
class="oh-timeoff-modal__user m-0"
style="font-size: 18px; color: #4d4a4a"
>
{{available_leave.employee_id.employee_work_info.department_id}} /
{{available_leave.employee_id.employee_work_info.job_position_id}}</span
>
</div>
<button hx-get="{% url 'available-leave-single-view' next_instance %}?{{pd}}&instances_ids={{instance_ids_json}}"
hx-target="#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-next" data-action="next">
<ion-icon name="chevron-forward-outline" class="md hydrated" role="img"
aria-label="chevron forward outline"></ion-icon>
</button>
</div>
</a>
<div class="oh-modal__dialog-header" style="padding-top: 5px">
<div class="oh-timeoff-modal__stats-container mt-3 mb-3">
<div class="oh-timeoff-modal__stat">
<span class="oh-timeoff-modal__stat-title"
>{% trans "Leave Type" %}</span
>
<span class="oh-timeoff-modal__stat-count"
>{{available_leave.leave_type_id}}</span
>
</div>
<div class="oh-timeoff-modal__stat" style="margin-left: 20px">
<span class="oh-timeoff-modal__stat-title">{% trans "Available Days" %}</span>
<span class="oh-timeoff-modal__stat-count">{{available_leave.available_days}}</span>
</div>
</div>
<a class="oh-timeoff-modal__profile-content" style="text-decoration: none"
href="{% url 'employee-view-individual' available_leave.employee_id.id %}">
<div class="oh-profile mb-2">
<div class="oh-profile__avatar">
<img src="{{available_leave.employee_id.get_avatar}}" class="oh-profile__image me-2"
alt="Mary Magdalene" />
</div>
<div class="oh-timeoff-modal__profile-info">
<span class="oh-timeoff-modal__user fw-bold">{{available_leave.employee_id}}</span>
<span class="oh-timeoff-modal__user m-0" style="font-size: 18px; color: #4d4a4a">
{{available_leave.employee_id.employee_work_info.department_id}} /
{{available_leave.employee_id.employee_work_info.job_position_id}}</span>
</div>
</div>
</a>
<div class="oh-modal__dialog-header" style="padding-top: 5px">
<div class="oh-timeoff-modal__stats-container mt-3 mb-3">
<div class="oh-timeoff-modal__stat">
<span class="oh-timeoff-modal__stat-title">{% trans "Leave Type" %}</span>
<span class="oh-timeoff-modal__stat-count">{{available_leave.leave_type_id}}</span>
</div>
<div class="oh-timeoff-modal__stat" style="margin-left: 20px">
<span class="oh-timeoff-modal__stat-title">{% trans "Available Days" %}</span>
<span class="oh-timeoff-modal__stat-count">{{available_leave.available_days}}</span>
</div>
</div>
<div class="oh-timeoff-modal__stats-container mt-3 mb-3">
<div class="oh-timeoff-modal__stat">
<span class="oh-timeoff-modal__stat-title">{% trans "Carryforward Days" %}</span>
<span class="oh-timeoff-modal__stat-count"
>{{available_leave.carryforward_days}}</span
>
</div>
<div class="oh-timeoff-modal__stat" style="margin-left: 20px">
<span class="oh-timeoff-modal__stat-title"
>{% trans "Total Leave Days" %}</span
>
<span class="oh-timeoff-modal__stat-count"
>{{available_leave.total_leave_days}}</span
>
</div>
</div>
<div class="oh-timeoff-modal__stats-container mt-3 mb-3">
<div class="oh-timeoff-modal__stat">
<span class="oh-timeoff-modal__stat-title">{% trans "Carryforward Days" %}</span>
<span class="oh-timeoff-modal__stat-count">{{available_leave.carryforward_days}}</span>
</div>
<div class="oh-timeoff-modal__stat" style="margin-left: 20px">
<span class="oh-timeoff-modal__stat-title">{% trans "Total Leave Days" %}</span>
<span class="oh-timeoff-modal__stat-count">{{available_leave.total_leave_days}}</span>
</div>
</div>
<div class="oh-timeoff-modal__stats-container mt-3 mb-3">
<div class="oh-timeoff-modal__stat">
<span class="oh-timeoff-modal__stat-title"
>{% trans "Assigned Date" %}</span
>
<span class="oh-timeoff-modal__stat-count dateformat_changer"
>{{available_leave.assigned_date}}</span
>
</div>
<div class="oh-timeoff-modal__stat" style="margin-left: 20px">
<span class="oh-timeoff-modal__stat-title"
>{% trans "Leave Reset Date" %}</span
>
<span class="oh-timeoff-modal__stat-count dateformat_changer"
>{{available_leave.reset_date}}</span
>
</div>
</div>
{% if perms.leave.change_availableleave or perms.leave.delete_availableleave or request.user|is_reportingmanager %}
<div class="oh-modal__button-container text-center">
<div class="oh-btn-group">
{% if request.user|is_reportingmanager or perms.leave.change_availableleave %}
<a hx-get="{% url 'available-leave-update' available_leave.id %}?{{pd}}" hx-target='#objectUpdateModalTarget'
data-toggle="oh-modal-toggle" data-target='#objectUpdateModal' class="oh-btn oh-btn--info w-50" title="{% trans 'Edit' %}">
<ion-icon name="create-outline"></ion-icon>
</a>
<div class="oh-timeoff-modal__stats-container mt-3 mb-3">
<div class="oh-timeoff-modal__stat">
<span class="oh-timeoff-modal__stat-title">{% trans "Assigned Date" %}</span>
<span class="oh-timeoff-modal__stat-count dateformat_changer">{{available_leave.assigned_date}}</span>
</div>
<div class="oh-timeoff-modal__stat" style="margin-left: 20px">
<span class="oh-timeoff-modal__stat-title">{% trans "Leave Reset Date" %}</span>
<span class="oh-timeoff-modal__stat-count dateformat_changer">{{available_leave.reset_date}}</span>
</div>
</div>
{% if perms.leave.change_availableleave or perms.leave.delete_availableleave or request.user|is_reportingmanager %}
<div class="oh-modal__button-container text-center">
<div class="oh-btn-group">
{% if request.user|is_reportingmanager or perms.leave.change_availableleave %}
<a hx-get="{% url 'available-leave-update' available_leave.id %}?{{pd}}"
hx-target='#objectUpdateModalTarget' data-toggle="oh-modal-toggle" data-target='#objectUpdateModal'
class="oh-btn oh-btn--info w-50" title="{% trans 'Edit' %}">
<ion-icon name="create-outline"></ion-icon>
</a>
{% endif %}
{% if request.user|is_reportingmanager or perms.leave.delete_availableleave %}
<form hx-confirm="{% trans 'Are you sure you want to delete this assigned leave?' %}"
hx-post="{% url 'assign-delete' available_leave.id %}?{{pd}}&instances_ids={{instance_ids_json}}"
hx-target="#objectDetailsModalTarget" style="width: 50%">
{% csrf_token %}
<button type='submit' class="oh-btn oh-btn--secondary w-100" title="{% trans 'Remove' %}" data-action="delete">
<ion-icon name="trash-outline"></ion-icon>
</button>
</form>
{% endif %}
</div>
</div>
{% endif %}
<form hx-confirm="{% trans 'Are you sure you want to delete this work type request?' %}"
hx-post="{% url 'assign-delete' available_leave.id %}?instances_ids={{instance_ids_json}}" hx-target="#objectDetailsModalW25Target" style="width: 50%">
{% csrf_token %}
<button type='submit' class="oh-btn oh-btn--secondary w-100" title="{% trans 'Remove' %}"><ion-icon name="trash-outline"></ion-icon></button>
</form>
</div>
</div>
{% endif %}
</div>
{% else %}
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%;">
<img style="display: block; width: 15%; margin: 20px auto; filter: opacity(0.5);" src="{% static 'images/ui/employee_shift.png' %}" class="" alt="Page not found. 404." />
<h5 class="oh-404__subtitle">{% trans "Assigned Leave type not found." %}</h5>
</div>
{% endif %}
{% else %}
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%;">
<img style="display: block; width: 15%; margin: 20px auto; filter: opacity(0.5);"
src="{% static 'images/ui/employee_shift.png' %}" class="" alt="Page not found. 404." />
<h5 class="oh-404__subtitle">{% trans "Assigned Leave type not found." %}</h5>
</div>
{% endif %}
</div>

View File

@@ -2,14 +2,14 @@
<div class="oh-modal__dialog oh-modal__dialog--navigation m-0 p-0">
<button
hx-get="{% url 'one-request-view' previous %}?instances_ids={{requests_ids}}&dashboard={{dashboard}}" hx-target="#objectDetailsModalW25Target"
class="oh-modal__diaglog-nav oh-modal__nav-prev">
class="oh-modal__diaglog-nav oh-modal__nav-prev" data-action="previous">
<ion-icon name="chevron-back-outline" class="md hydrated" role="img"
aria-label="chevron back outline"></ion-icon>
</button>
<button
hx-get="{% url 'one-request-view' next %}?instances_ids={{requests_ids}}&dashboard={{dashboard}}" hx-target="#objectDetailsModalW25Target"
class="oh-modal__diaglog-nav oh-modal__nav-next">
class="oh-modal__diaglog-nav oh-modal__nav-next" data-action="next">
<ion-icon name="chevron-forward-outline" class="md hydrated" role="img"
aria-label="chevron forward outline"></ion-icon>
</button>

View File

@@ -8,16 +8,7 @@
</div>
{% endfor %}
</div>
<script>
setTimeout(function () {
$(".oh-span__class").click();
}, 1000);
</script>
<span
class="oh-span__class"
hx-get="{% url 'type-filter' %}"
hx-target="#leaveTypes"
></span>
<span class="oh-span__class" hx-trigger="load" hx-get="{% url 'type-filter' %}" hx-target="#leaveTypes"></span>
{% endif %}
{% if leave_type and request.GET.instances_ids and not compensatory %}
<div class="oh-modal__dialog oh-modal__dialog--navigation m-0 p-0">
@@ -25,6 +16,7 @@
hx-get="{% url 'leave-type-individual-view' previous %}?instances_ids={{requests_ids}}"
hx-target="#objectDetailsModalTarget"
class="oh-modal__diaglog-nav oh-modal__nav-prev"
data-action="previous"
>
<ion-icon
name="chevron-back-outline"
@@ -38,6 +30,7 @@
hx-get="{% url 'leave-type-individual-view' next %}?instances_ids={{requests_ids}}"
hx-target="#objectDetailsModalTarget"
class="oh-modal__diaglog-nav oh-modal__nav-next"
data-action="next"
>
<ion-icon
name="chevron-forward-outline"
@@ -273,15 +266,14 @@
{% trans "Assign" %}
</a>
{% endif %}
<a
hx-confirm="{% trans 'Do you really want to delete this leave type?' %}"
hx-post="{% url 'type-delete' leave_type.id %}?instances_ids={{requests_ids}}"
hx-target="#objectDetailsModalTarget"
class="oh-btn oh-btn--danger w-50"
>
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
{% trans "Delete" %}
</a>
<button class="oh-btn oh-btn--danger w-50" data-action="delete"
hx-confirm="{% trans 'Do you really want to delete this leave type?' %}"
hx-post="{% url 'type-delete' leave_type.id %}?instances_ids={{requests_ids}}"
hx-target="#objectDetailsModalTarget"
>
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
{% trans "Delete" %}
</button>
{% endif %}
</div>
{% endif %}

View File

@@ -16,6 +16,7 @@
<button
hx-get="{% url 'user-request-one' previous %}?instances_ids={{instances_ids}}"
hx-target="#objectDetailsModalW25Target"
data-action="previous"
class="oh-modal__diaglog-nav oh-modal__nav-prev">
<ion-icon name="chevron-back-outline" class="md hydrated" role="img"
aria-label="chevron back outline"></ion-icon>
@@ -23,7 +24,9 @@
<button
hx-get="{% url 'user-request-one' next %}?instances_ids={{instances_ids}}"
hx-target="#objectDetailsModalW25Target"
class="oh-modal__diaglog-nav oh-modal__nav-next">
class="oh-modal__diaglog-nav oh-modal__nav-next"
data-action="next"
>
<ion-icon name="chevron-forward-outline" class="md hydrated" role="img"
aria-label="chevron forward outline"></ion-icon>
</button>

View File

@@ -1219,7 +1219,7 @@ def leave_assign_one(request, id):
@manager_can_enter("leave.view_availableleave")
def leave_assign_view(request):
"""
function used to view assigned employee leaves.
Function to view assigned employee leaves.
Parameters:
request (HttpRequest): The HTTP request object.
@@ -1227,38 +1227,33 @@ def leave_assign_view(request):
Returns:
GET : return leave assigned view template
"""
queryset = AvailableLeave.objects.all()
queryset = filtersubordinates(request, queryset, "leave.view_availableleave")
previous_data = request.GET.urlencode()
queryset = filtersubordinates(
request, AvailableLeave.objects.all(), "leave.view_availableleave"
)
previous_data = request.GET.urlencode() or "field=leave_type_id"
field = request.GET.get("field", "leave_type_id")
page_number = request.GET.get("page")
page_obj = paginator_qry(queryset.order_by("-id"), page_number)
assigned_leave_filter = AssignedLeaveFilter()
assign_form = AssignLeaveForm()
# default group by configuration
data_dict = {"field": ["leave_type_id"]}
# Paginate and group queryset by field
page_obj = group_by_queryset(queryset.order_by("-id"), field, page_number)
available_leave_ids = json.dumps(
[instance.id for entry in page_obj for instance in entry["list"].object_list]
)
# to check condition on the template
setattr(request.GET, "field", True)
page_obj = group_by_queryset(queryset.order_by("-id"), "leave_type_id", page_number)
list_values = [entry["list"] for entry in page_obj]
id_list = []
for value in list_values:
for instance in value.object_list:
id_list.append(instance.id)
available_leave_ids = json.dumps(list(id_list))
# Setting a condition for the template
request.GET = request.GET.copy()
request.GET["field"] = True
return render(
request,
"leave/leave_assign/assign_view.html",
{
"available_leaves": page_obj,
"f": assigned_leave_filter,
"f": AssignedLeaveFilter(),
"pd": previous_data,
"filter_dict": data_dict,
"filter_dict": parse_qs(previous_data),
"gp_fields": LeaveAssignReGroup.fields,
"assign_form": assign_form,
"assign_form": AssignLeaveForm(),
"available_leave_ids": available_leave_ids,
},
)
@@ -1268,16 +1263,21 @@ def leave_assign_view(request):
@hx_request_required
@manager_can_enter("leave.view_availableleave")
def available_leave_single_view(request, obj_id):
previous_data = request.GET.urlencode()
get_data = request.GET.copy()
get_data.pop("instances_ids", None)
previous_data = get_data.urlencode()
available_leave = AvailableLeave.objects.filter(id=obj_id).first()
instance_ids_json = request.GET["instances_ids"]
instance_ids = json.loads(instance_ids_json) if instance_ids_json else []
previous_instance, next_instance = closest_numbers(instance_ids, obj_id)
instance_ids = json.loads(request.GET.get("instances_ids", "[]"))
previous_instance, next_instance = (
closest_numbers(instance_ids, obj_id) if instance_ids else (None, None)
)
content = {
"available_leave": available_leave,
"previous_instance": previous_instance,
"next_instance": next_instance,
"instance_ids_json": instance_ids_json,
"instance_ids_json": json.dumps(instance_ids),
"pd": previous_data,
}
return render(
@@ -1451,39 +1451,38 @@ def available_leave_update(request, id):
@manager_can_enter("leave.delete_availableleave")
def leave_assign_delete(request, obj_id):
"""
function used to delete assign leave type of an employee.
Function to delete an assigned leave type of an employee.
Parameters:
request (HttpRequest): The HTTP request object.
id : available leave id
- request (HttpRequest): The HTTP request object.
- obj_id (int): Available leave ID.
Returns:
GET : return leave type assigned view template
- Redirects to the assigned leave type view or refreshes the page.
"""
pd = request.GET.urlencode()
try:
AvailableLeave.objects.get(id=obj_id).delete()
messages.success(request, _("Assigned leave is successfully deleted."))
messages.success(request, _("Assigned leave successfully deleted."))
except AvailableLeave.DoesNotExist:
messages.error(request, _("Assigned leave not found."))
except ProtectedError:
messages.error(request, _("Related entries exists"))
if not request.GET.get("instances_ids"):
if not AvailableLeave.objects.filter():
return HttpResponse("<script>window.location.reload()</script>")
return redirect(f"/leave/assign-filter?{pd}")
else:
instances_ids = request.GET.get("instances_ids")
messages.error(request, _("Related entries exist."))
if instances_ids := request.GET.get("instances_ids"):
instances_list = json.loads(instances_ids)
previous_instance, next_instance = closest_numbers(instances_list, obj_id)
if obj_id in instances_list:
instances_list.remove(obj_id)
previous_instance, next_instance = closest_numbers(
json.loads(instances_ids), obj_id
)
return redirect(
f"/leave/available-leave-single-view/{next_instance}/?instances_ids={instances_list}"
f"/leave/available-leave-single-view/{next_instance}/?{pd}&instances_ids={json.dumps(instances_list)}"
)
if not AvailableLeave.objects.exists():
return HttpResponse("<script>window.location.reload()</script>")
return redirect(f"/leave/assign-filter?{pd}")
@require_http_methods(["POST"])
@permission_required("leave.delete_availableleave")
@@ -3082,7 +3081,7 @@ def leave_allocation_request_single_view(request, req_id):
if requests_ids_json:
requests_ids = json.loads(requests_ids_json)
previous_id, next_id = closest_numbers(requests_ids, req_id)
leave_allocation_request = LeaveAllocationRequest.objects.get(id=req_id)
leave_allocation_request = LeaveAllocationRequest.find(req_id)
context = {
"leave_allocation_request": leave_allocation_request,
"my_request": my_request,
@@ -3457,13 +3456,25 @@ def leave_allocation_request_delete(request, req_id):
except ProtectedError:
messages.error(request, _("Related entries exist"))
hx_target = request.META.get("HTTP_HX_TARGET")
previous_data = request.GET.urlencode()
if hx_target and hx_target == "view-container":
previous_data = request.GET.urlencode()
leave_allocations = LeaveAllocationRequest.objects.all()
if leave_allocations.exists():
return redirect(f"/leave/leave-allocation-request-filter?{previous_data}")
else:
return HttpResponse("<script>location.reload();</script>")
elif hx_target and hx_target == "objectDetailsModalW25Target":
instances_ids = request.GET.get("instances_ids")
instances_list = json.loads(instances_ids)
if req_id in instances_list:
instances_list.remove(req_id)
previous_instance, next_instance = closest_numbers(
json.loads(instances_ids), req_id
)
return redirect(
f"/leave/leave-allocation-request-single-view/{next_instance}?{previous_data}"
)
return redirect(leave_allocation_request_view)