[ADD] LEAVE: Common form on leave request section

This commit is contained in:
Horilla
2023-10-09 16:13:10 +05:30
parent 03ccee51b8
commit 0af7c858c7
4 changed files with 55 additions and 117 deletions

View File

@@ -4,6 +4,7 @@ from django.forms import ModelForm
from django.forms.widgets import TextInput
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from django.template.loader import render_to_string
from employee.models import Employee
from .models import LeaveType, LeaveRequest, AvailableLeave, Holiday, CompanyLeave
from .methods import (
@@ -252,6 +253,14 @@ class LeaveRequestCreationForm(ModelForm):
return cleaned_data
def as_p(self, *args, **kwargs):
"""
Render the form fields as HTML table rows with Bootstrap styling.
"""
context = {"form": self}
table_html = render_to_string("attendance_form.html", context)
return table_html
class Meta:
model = LeaveRequest
fields = [
@@ -335,6 +344,14 @@ class LeaveRequestUpdationForm(ModelForm):
return cleaned_data
def as_p(self, *args, **kwargs):
"""
Render the form fields as HTML table rows with Bootstrap styling.
"""
context = {"form": self}
table_html = render_to_string("attendance_form.html", context)
return table_html
class Meta:
model = LeaveRequest
fields = [

View File

@@ -13,48 +13,5 @@
{% endif %}
<form hx-post="{% url 'request-creation' %}" hx-encoding="multipart/form-data">
<div class="oh-modal__dialog-body pb-2" id="leaveType">
<label class="oh-label d-block ">{% trans "Leave types" %}</label>
{{form.leave_type_id}}
{{form.leave_type_id.errors}}
</div>
<div class="oh-modal__dialog-body pb-2" id="employee">
<label class="oh-label d-block">{% trans "Employees" %}</label>
{{form.employee_id}}
{{form.employee_id.errors}}
</div>
<div class="oh-modal__dialog-body pb-2">
<label class="oh-label d-block">{% trans "Start Date" %}</label>
{{form.start_date}}
{{form.start_date.errors}}
</div>
<div class="oh-modal__dialog-body pb-2" id="startDate">
<label class="oh-label d-block">{% trans "Start Date Breakdown" %}</label>
{{form.start_date_breakdown}}
{{form.start_date_breakdown.errors}}
</div>
<div class="oh-modal__dialog-body pb-2">
<label class="oh-label d-block">{% trans "End Date" %}</label>
{{form.end_date}}
{{form.end_date.errors}}
</div>
<div class="oh-modal__dialog-body pb-2" id="endDate">
<label class="oh-label d-block">{% trans "End Date Breakdown" %}</label>
{{form.end_date_breakdown}}
{{form.end_date_breakdown.errors}}
</div>
<div class="oh-modal__dialog-body pb-2">
<label class="oh-label d-block">{% trans "Description" %}</label>
{{form.description}}
{{form.description.errors}}
</div>
<div class="oh-modal__dialog-body pb-2">
<label class="oh-label d-block">{% trans "Attachment" %}</label>
{{form.attachment}}
{{form.attachment.errors}}
</div>
<div class="oh-modal__dialog-footer">
<button type="submit" class="oh-btn oh-btn--secondary w-100">
{% trans "Apply" %}
</button>
</form>
{{form.as_p}}
</form>

View File

@@ -16,54 +16,5 @@
<form hx-post="{% url 'request-update' id %}" hx-encoding="multipart/form-data">
{% csrf_token %}
<div class="oh-modal__dialog-body pb-2" id="updateLeaveType">
<label class="oh-label d-block">{% trans "Leave Types" %}</label>
{{form.leave_type_id}}
{{form.leave_type_id.errors}}
</div>
<div class="oh-modal__dialog-body pb-2" id="updateEmployee">
<label class="oh-label d-block">{% trans "Employees" %}</label>
{{form.employee_id}}
{{form.employee_id.errors}}
</div>
<div class="oh-modal__dialog-body pb-2">
<label class="oh-label d-block">{% trans "Start Date" %}</label>
{{form.start_date}}
{{form.start_date.errors}}
</div>
<div class="oh-modal__dialog-body pb-2" id="updateStartDate">
<label class="oh-label d-block">{% trans "Start Date Breakdown" %}</label>
{{form.start_date_breakdown}}
{{form.start_date_breakdown.errors}}
</div>
<div class="oh-modal__dialog-body pb-2">
<label class="oh-label d-block">{% trans "End Date" %}</label>
{{form.end_date}}
{{form.end_date.errors}}
</div>
<div class="oh-modal__dialog-body pb-2" id="updateEndDate">
<label class="oh-label d-block">{% trans "End Date Breakdown" %}</label>
{{form.end_date_breakdown}}
{{form.end_date_breakdown.errors}}
</div>
<div class="oh-modal__dialog-body pb-2">
<label class="oh-label d-block">{% trans "Description" %}</label>
{{form.description}}
{{form.description.errors}}
</div>
<div class="oh-modal__dialog-body pb-2">
<label class="oh-label d-block">{% trans "Attachment" %}</label>
{{form.attachment}}
{{form.attachment.errors}}
</div>
<div class="oh-modal__dialog-body pb-2" id="updateStatus">
<label class="oh-label d-block">{% trans "Status" %}</label>
{{form.status}}
{{form.status.errors}}
</div>
<div class="oh-modal__dialog-footer">
<button type="submit" class="oh-btn oh-btn--secondary w-100">
{% trans "Apply" %}
</button>
{{form.as_p}}
</form>

View File

@@ -129,34 +129,47 @@
</div>
<!-- Create request -->
<div class="oh-modal" id="editModal1" role="dialog" aria-labelledby="editDialogModal" aria-hidden="true">
<div class="oh-modal__dialog oh-modal__dialog--timeoff">
<div class="oh-modal__dialog-header">
<span class="oh-modal__dialog-title" id="editDialogDialog">{% trans "Create Request" %}</span>
<button class="oh-modal__close" aria-label="Close">
<ion-icon name="close-outline"></ion-icon>
</button>
</div>
<div id="requestForm">
</div>
<div
class="oh-modal"
id="editModal1"
role="dialog"
aria-labelledby="editModal1"
aria-hidden="true"
>
<div class="oh-modal__dialog">
<div class="oh-modal__dialog-header">
<h2 class="oh-modal__dialog-title" id="editModal1ModalLabel">
{% trans "Leave Request Create" %}
</h2>
<button class="oh-modal__close" aria-label="Close">
<ion-icon name="close-outline"></ion-icon>
</button>
</div>
<div class="oh-modal__dialog-body" id="requestForm"></div>
</div>
</div>
<!-- update request -->
<div class="oh-modal" id="editModal2" role="dialog" aria-labelledby="editDialogModal" aria-hidden="true">
<div class="oh-modal__dialog oh-modal__dialog--timeoff">
<div class="oh-modal__dialog-header">
<span class="oh-modal__dialog-title" id="editDialogDialog">{% trans "Update Request" %}</span>
<button class="oh-modal__close" aria-label="Close">
<ion-icon name="close-outline"></ion-icon>
</button>
</div>
<div id="updateForm">
</div>
<!-- update request -->
<div
class="oh-modal"
id="editModal2"
role="dialog"
aria-labelledby="editModal2"
aria-hidden="true"
>
<div class="oh-modal__dialog">
<div class="oh-modal__dialog-header">
<h2 class="oh-modal__dialog-title" id="editModal2ModalLabel">
{% trans "Leave Request Create" %}
</h2>
<button class="oh-modal__close" aria-label="Close">
<ion-icon name="close-outline"></ion-icon>
</button>
</div>
<div class="oh-modal__dialog-body" id="updateForm"></div>
</div>
</div>