From d61f91a467bac79543c0788e46774db68f7b55cb Mon Sep 17 00:00:00 2001 From: Horilla Date: Fri, 29 Aug 2025 12:02:42 +0530 Subject: [PATCH] [UPDT] LEAVE: Updated restricted leave page to cbv --- leave/cbv/leave_requests.py | 23 ++++- leave/cbv/my_leave_request.py | 7 +- .../my_leave_request/attachment_action.html | 2 +- .../detail_leave_actions.html | 91 ++++++++----------- .../cbv/my_leave_request/rejected_action.html | 23 +++-- 5 files changed, 79 insertions(+), 67 deletions(-) diff --git a/leave/cbv/leave_requests.py b/leave/cbv/leave_requests.py index 32556e99f..c52947f87 100644 --- a/leave/cbv/leave_requests.py +++ b/leave/cbv/leave_requests.py @@ -297,12 +297,29 @@ class LeaveRequestsDetailView(HorillaDetailedView): (_("Created By"), "created_by"), (_("Description"), "description"), (_("View attachment"), "attachment_action", True), - (_("Reason for Rejection"), "rejected_action", True), - (_("Reason for Cancellation"), "cancelled_action", True), - (_("Multiple Approvals"), "multiple_approval_action", True), ] action_method = "leave_requests_detail_view_actions" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + body = list(self.body) + + if self.instance.multiple_approvals: + insert_index = 7 + body.insert( + insert_index, + (_("Multiple Approvals"), "multiple_approval_action", True), + ) + + if self.instance.reject_reason: + insert_index = 8 + body.insert( + insert_index, (_("Reason for Rejection"), "rejected_action", True) + ) + + context["body"] = body + return context + @method_decorator(login_required, name="dispatch") @method_decorator(manager_can_enter("leave.add_leaverequest"), name="dispatch") diff --git a/leave/cbv/my_leave_request.py b/leave/cbv/my_leave_request.py index 7f6c7332f..b0293e673 100644 --- a/leave/cbv/my_leave_request.py +++ b/leave/cbv/my_leave_request.py @@ -231,15 +231,18 @@ class MyLeaveRequestDetailView(HorillaDetailedView): "subtitle": "my_leave_request_detail_subtitle", "avatar": "employee_id__get_avatar", } + # cols = { + # "rejected_action" : 12, + # "attachment_action" : 12 + # } body = [ ("Leave Type", "leave_type_id"), ("Days", "requested_days"), ("Start Date", "start_date"), ("End Date", "end_date"), - ("Status", "get_status"), + ("Status", "get_status_display"), ("Description", "description"), ("Reason for Rejection", "rejected_action", True), - ("Reason for Cancellation", "cancelled_action", True), ("View attachment", "attachment_action", True), ] action_method = "detail_leave_actions" diff --git a/leave/templates/cbv/my_leave_request/attachment_action.html b/leave/templates/cbv/my_leave_request/attachment_action.html index efac6c5b5..666734372 100644 --- a/leave/templates/cbv/my_leave_request/attachment_action.html +++ b/leave/templates/cbv/my_leave_request/attachment_action.html @@ -6,7 +6,7 @@ {% if instance.attachment %} - + {% trans "View attachment" %} diff --git a/leave/templates/cbv/my_leave_request/detail_leave_actions.html b/leave/templates/cbv/my_leave_request/detail_leave_actions.html index 9af94eadc..af3200a18 100644 --- a/leave/templates/cbv/my_leave_request/detail_leave_actions.html +++ b/leave/templates/cbv/my_leave_request/detail_leave_actions.html @@ -1,56 +1,41 @@ -{% load basefilters %} -{% load i18n %} +{% load basefilters i18n %} + {% if instance.status == 'requested'%} - - - - {% else %} - - {% endif %} - {% if instance.status == 'requested'%} -
- {% csrf_token %} - -
- {% else %} - + + + {% trans 'Edit' %} + +{% else %} + {% endif %} - -{% comment %} -{% load i18n %} -
- {% if instance.status == 'requested'%} -
- - - - -
- {% else %} -
- - -
- {% endif %} -
{% endcomment %} +{% if instance.status == 'requested'%} +
+ {% csrf_token %} + +
+{% else %} + +{% endif %} diff --git a/leave/templates/cbv/my_leave_request/rejected_action.html b/leave/templates/cbv/my_leave_request/rejected_action.html index b6ef915ee..34d9d978c 100644 --- a/leave/templates/cbv/my_leave_request/rejected_action.html +++ b/leave/templates/cbv/my_leave_request/rejected_action.html @@ -7,13 +7,20 @@ {% if instance.reject_reason %} - {% if instance.status == "rejected" %} -
-
- {% trans "Reason for Rejection" %} -
{{instance.reject_reason}}
-
-
+ {% if instance.status == "rejected" %} +
+
+ {% trans "Reason for Rejection" %} +
{{instance.reject_reason}}
+
+
- {% endif %} + {% elif instance.status == "cancelled" %} +
+
+ {% trans "Reason for Cancellation" %} +
{{instance.reject_reason}}
+
+
+ {% endif %} {% endif %}