[UPDT] ATTENDANCE: Updated attendance form.py file by replace ModelForm with BaseModelForm for horilla label craft
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# pylint: disable=too-few-public-methods
|
||||
"""
|
||||
forms.py
|
||||
|
||||
@@ -53,6 +54,7 @@ from attendance.models import (
|
||||
strtime_seconds,
|
||||
validate_time_format,
|
||||
)
|
||||
from base.forms import ModelForm as BaseModelForm
|
||||
from base.methods import (
|
||||
filtersubordinatesemployeemodel,
|
||||
get_working_days,
|
||||
@@ -69,82 +71,7 @@ from horilla_widgets.widgets.select_widgets import HorillaMultiSelectWidget
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ModelForm(forms.ModelForm):
|
||||
"""
|
||||
Overriding django default model form to apply some styles
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
reload_queryset(self.fields)
|
||||
request = getattr(horilla_middlewares._thread_locals, "request", None)
|
||||
|
||||
for field_name, field in self.fields.items():
|
||||
widget = field.widget
|
||||
if isinstance(widget, (forms.DateInput)):
|
||||
field.initial = datetime.date.today()
|
||||
|
||||
if isinstance(
|
||||
widget, (forms.NumberInput, forms.EmailInput, forms.TextInput)
|
||||
):
|
||||
label = _(field.label.title())
|
||||
|
||||
field.widget.attrs.update(
|
||||
{"class": "oh-input w-100", "placeholder": label}
|
||||
)
|
||||
elif isinstance(widget, (forms.Select,)):
|
||||
label = ""
|
||||
if field.label is not None:
|
||||
label = _(field.label)
|
||||
field.empty_label = _("---Choose {label}---").format(label=label)
|
||||
self.fields[field_name].widget.attrs.update(
|
||||
{
|
||||
"class": "oh-select oh-select-2 w-100",
|
||||
"id": uuid.uuid4(),
|
||||
"style": "height:50px;border-radius:0;",
|
||||
}
|
||||
)
|
||||
elif isinstance(widget, (forms.Textarea)):
|
||||
label = _(field.label)
|
||||
field.widget.attrs.update(
|
||||
{
|
||||
"class": "oh-input w-100",
|
||||
"placeholder": label,
|
||||
"rows": 2,
|
||||
"cols": 40,
|
||||
}
|
||||
)
|
||||
elif isinstance(
|
||||
widget,
|
||||
(
|
||||
forms.CheckboxInput,
|
||||
forms.CheckboxSelectMultiple,
|
||||
),
|
||||
):
|
||||
field.widget.attrs.update({"class": "oh-switch__checkbox"})
|
||||
if isinstance(widget, forms.DateInput):
|
||||
field.widget = forms.DateInput(
|
||||
attrs={"type": "date", "class": "oh-input w-100"}
|
||||
)
|
||||
if isinstance(widget, forms.TimeInput):
|
||||
field.widget = forms.DateInput(
|
||||
attrs={"type": "time", "class": "oh-input w-100"}
|
||||
)
|
||||
|
||||
try:
|
||||
self.fields["employee_id"].initial = request.user.employee_get
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
self.fields["company_id"].initial = (
|
||||
request.user.employee_get.get_company
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
class AttendanceUpdateForm(ModelForm):
|
||||
class AttendanceUpdateForm(BaseModelForm):
|
||||
"""
|
||||
This model form is used to direct save the validated query dict to attendance model
|
||||
from AttendanceUpdateForm. This form can be used to update existing attendance.
|
||||
@@ -242,8 +169,6 @@ class AttendanceUpdateForm(ModelForm):
|
||||
)
|
||||
self.fields["work_type_id"].widget.attrs.update({"id": str(uuid.uuid4())})
|
||||
|
||||
self.fields["attendance_overtime_approve"].label = _("Approve overtime?")
|
||||
self.fields["attendance_validated"].label = _("Validate Attendance?")
|
||||
if (
|
||||
instance is not None
|
||||
and not instance.attendance_overtime_approve
|
||||
@@ -266,12 +191,13 @@ class AttendanceUpdateForm(ModelForm):
|
||||
"""
|
||||
Render the form fields as HTML table rows with Bootstrap styling.
|
||||
"""
|
||||
_ = args, kwargs # Explicitly mark as used for pylint
|
||||
context = {"form": self}
|
||||
table_html = render_to_string("attendance_form.html", context)
|
||||
return table_html
|
||||
|
||||
|
||||
class AttendanceForm(ModelForm):
|
||||
class AttendanceForm(BaseModelForm):
|
||||
"""
|
||||
Model form for Attendance model
|
||||
"""
|
||||
@@ -421,6 +347,7 @@ class AttendanceForm(ModelForm):
|
||||
"""
|
||||
Render the form fields as HTML table rows with Bootstrap styling.
|
||||
"""
|
||||
_ = args, kwargs # Explicitly mark as used for pylint
|
||||
context = {"form": self}
|
||||
table_html = render_to_string("attendance_form.html", context)
|
||||
return table_html
|
||||
@@ -472,7 +399,7 @@ class AttendanceForm(ModelForm):
|
||||
return employee.first()
|
||||
|
||||
|
||||
class AttendanceActivityForm(ModelForm):
|
||||
class AttendanceActivityForm(BaseModelForm):
|
||||
"""
|
||||
Model form for AttendanceActivity model
|
||||
"""
|
||||
@@ -520,7 +447,7 @@ class MonthSelectField(forms.ChoiceField):
|
||||
super().__init__(choices=choices, *args, **kwargs)
|
||||
|
||||
|
||||
class AttendanceOverTimeForm(ModelForm):
|
||||
class AttendanceOverTimeForm(BaseModelForm):
|
||||
"""
|
||||
Model form for AttendanceOverTime model
|
||||
"""
|
||||
@@ -557,12 +484,13 @@ class AttendanceOverTimeForm(ModelForm):
|
||||
"""
|
||||
Render the form fields as HTML table rows with Bootstrap styling.
|
||||
"""
|
||||
_ = args, kwargs # Explicitly mark as used for pylint
|
||||
context = {"form": self}
|
||||
table_html = render_to_string("attendance_form.html", context)
|
||||
return table_html
|
||||
|
||||
|
||||
class AttendanceLateComeEarlyOutForm(ModelForm):
|
||||
class AttendanceLateComeEarlyOutForm(BaseModelForm):
|
||||
"""
|
||||
Model form for attendance AttendanceLateComeEarlyOut
|
||||
"""
|
||||
@@ -618,12 +546,16 @@ class AttendanceValidationConditionForm(forms.ModelForm):
|
||||
)
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
Meta class for additional options
|
||||
"""
|
||||
|
||||
model = AttendanceValidationCondition
|
||||
fields = "__all__"
|
||||
exclude = ["is_active"]
|
||||
|
||||
|
||||
class AttendanceRequestForm(ModelForm):
|
||||
class AttendanceRequestForm(BaseModelForm):
|
||||
"""
|
||||
AttendanceRequestForm
|
||||
"""
|
||||
@@ -719,6 +651,7 @@ class AttendanceRequestForm(ModelForm):
|
||||
"""
|
||||
Render the form fields as HTML table rows with Bootstrap styling.
|
||||
"""
|
||||
_ = args, kwargs # Explicitly mark as used for pylint
|
||||
context = {"form": self}
|
||||
table_html = render_to_string("attendance_form.html", context)
|
||||
return table_html
|
||||
@@ -764,7 +697,6 @@ class NewRequestForm(AttendanceRequestForm):
|
||||
),
|
||||
),
|
||||
}
|
||||
self.fields["request_description"].label = _("Request description")
|
||||
new_dict.update(old_dict)
|
||||
self.fields = new_dict
|
||||
|
||||
@@ -774,6 +706,7 @@ class NewRequestForm(AttendanceRequestForm):
|
||||
"""
|
||||
Render the form fields as HTML table rows with Bootstrap styling.
|
||||
"""
|
||||
_ = args, kwargs # Explicitly mark as used for pylint
|
||||
context = {"form": self}
|
||||
form_html = render_to_string(
|
||||
"requests/attendance/request_new_form.html", context
|
||||
@@ -980,7 +913,7 @@ class AttendanceOverTimeExportForm(forms.Form):
|
||||
)
|
||||
|
||||
|
||||
class GraceTimeForm(ModelForm):
|
||||
class GraceTimeForm(BaseModelForm):
|
||||
"""
|
||||
Form for create or update Grace time
|
||||
"""
|
||||
@@ -1020,6 +953,7 @@ class GraceTimeAssignForm(forms.Form):
|
||||
"""
|
||||
Render the form fields as HTML table rows with Bootstrap styling.
|
||||
"""
|
||||
_ = args, kwargs # Explicitly mark as used for pylint
|
||||
context = {"form": self}
|
||||
form_html = render_to_string("common_form.html", context)
|
||||
return form_html
|
||||
@@ -1029,7 +963,7 @@ class GraceTimeAssignForm(forms.Form):
|
||||
self.fields["shifts"].widget.attrs["class"] = "oh-select w-100 oh-select-2"
|
||||
|
||||
|
||||
class AttendanceRequestCommentForm(ModelForm):
|
||||
class AttendanceRequestCommentForm(BaseModelForm):
|
||||
"""
|
||||
AttendanceRequestComment form
|
||||
"""
|
||||
@@ -1093,7 +1027,7 @@ def get_date_list(employee_id, from_date, to_date):
|
||||
return date_list
|
||||
|
||||
|
||||
class BulkAttendanceRequestForm(ModelForm):
|
||||
class BulkAttendanceRequestForm(BaseModelForm):
|
||||
"""
|
||||
Bulk attendance request create form
|
||||
"""
|
||||
@@ -1293,7 +1227,7 @@ class BulkAttendanceRequestForm(ModelForm):
|
||||
return instance
|
||||
|
||||
|
||||
class WorkRecordsForm(ModelForm):
|
||||
class WorkRecordsForm(BaseModelForm):
|
||||
"""
|
||||
WorkRecordForm
|
||||
"""
|
||||
@@ -1307,7 +1241,7 @@ class WorkRecordsForm(ModelForm):
|
||||
model = WorkRecords
|
||||
|
||||
|
||||
class BatchAttendanceForm(ModelForm):
|
||||
class BatchAttendanceForm(BaseModelForm):
|
||||
"""
|
||||
BatchAttendanceForm
|
||||
"""
|
||||
@@ -1327,6 +1261,7 @@ class BatchAttendanceForm(ModelForm):
|
||||
"""
|
||||
Render the form fields as HTML table rows with Bootstrap styling.
|
||||
"""
|
||||
_ = args, kwargs # Explicitly mark as used for pylint
|
||||
context = {"form": self}
|
||||
form_html = render_to_string("common_form.html", context)
|
||||
return form_html
|
||||
@@ -1335,4 +1270,4 @@ class BatchAttendanceForm(ModelForm):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if self.instance.pk:
|
||||
self.verbose_name = _("Update batch attendance")
|
||||
self.verbose_name = _("Update attendance batch")
|
||||
|
||||
@@ -103,7 +103,7 @@ class BatchAttendance(HorillaModel):
|
||||
Batch attendance model
|
||||
"""
|
||||
|
||||
title = models.CharField(max_length=150)
|
||||
title = models.CharField(max_length=150, verbose_name=_("Title"))
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title}-{self.id}"
|
||||
@@ -190,10 +190,10 @@ class Attendance(HorillaModel):
|
||||
verbose_name=_("Overtime"),
|
||||
)
|
||||
attendance_overtime_approve = models.BooleanField(
|
||||
default=False, verbose_name=_("Overtime approved")
|
||||
default=False, verbose_name=_("Overtime Approve")
|
||||
)
|
||||
attendance_validated = models.BooleanField(
|
||||
default=False, verbose_name=_("Attendance validated")
|
||||
default=False, verbose_name=_("Attendance Validate")
|
||||
)
|
||||
at_work_second = models.IntegerField(null=True, blank=True)
|
||||
overtime_second = models.IntegerField(
|
||||
@@ -207,7 +207,9 @@ class Attendance(HorillaModel):
|
||||
is_validate_request_approved = models.BooleanField(
|
||||
default=False, verbose_name=_("Is validate request approved")
|
||||
)
|
||||
request_description = models.TextField(null=True, max_length=255)
|
||||
request_description = models.TextField(
|
||||
null=True, max_length=255, verbose_name=_("Request Description")
|
||||
)
|
||||
request_type = models.CharField(
|
||||
max_length=18, null=True, choices=status, default="update_request"
|
||||
)
|
||||
@@ -238,6 +240,8 @@ class Attendance(HorillaModel):
|
||||
"employee_id__employee_first_name",
|
||||
"attendance_clock_in",
|
||||
]
|
||||
verbose_name = _("Attendance")
|
||||
verbose_name_plural = _("Attendances")
|
||||
|
||||
def check_min_ot(self):
|
||||
"""
|
||||
@@ -645,6 +649,8 @@ class AttendanceOverTime(HorillaModel):
|
||||
|
||||
unique_together = [("employee_id"), ("month"), ("year")]
|
||||
ordering = ["-year", "-month_sequence"]
|
||||
verbose_name = _("Hour Account")
|
||||
verbose_name_plural = _("Hour Accounts")
|
||||
|
||||
def clean(self):
|
||||
try:
|
||||
@@ -828,14 +834,18 @@ class GraceTime(HorillaModel):
|
||||
default="00:00:00",
|
||||
validators=[validate_hh_mm_ss_format],
|
||||
max_length=10,
|
||||
verbose_name=_("Allowed time"),
|
||||
verbose_name=_("Allowed Time"),
|
||||
)
|
||||
allowed_time_in_secs = models.IntegerField()
|
||||
allowed_clock_in = models.BooleanField(
|
||||
default=True, help_text=_("Allcocate this grace time for Check-In Attendance")
|
||||
default=True,
|
||||
help_text=_("Allcocate this grace time for Check-In Attendance"),
|
||||
verbose_name=_("Allowed Clock-In"),
|
||||
)
|
||||
allowed_clock_out = models.BooleanField(
|
||||
default=False, help_text=_("Allcocate this grace time for Check-Out Attendance")
|
||||
default=False,
|
||||
help_text=_("Allcocate this grace time for Check-Out Attendance"),
|
||||
verbose_name=_("Allowed Clock-Out"),
|
||||
)
|
||||
is_default = models.BooleanField(default=False)
|
||||
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
{% load i18n %}
|
||||
<div class="oh-modal__dialog-header">
|
||||
<h2 class="oh-modal__dialog-title" id="objectCreateModalLabel">
|
||||
{% trans "Hour Account" %}
|
||||
</h2>
|
||||
<button class="oh-modal__close" aria-label="Close">
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
<h2 class="oh-modal__dialog-title" id="objectCreateModalLabel">
|
||||
{{form.verbose_name}}
|
||||
</h2>
|
||||
<button class="oh-modal__close" aria-label="Close">
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="oh-modal__dialog-body">
|
||||
<form
|
||||
id="add-form"
|
||||
hx-post="{% url 'attendance-overtime-create' %}"
|
||||
hx-target="#objectCreateModalTarget"
|
||||
hx-swap="innerHTML"
|
||||
>
|
||||
{{form.as_p}}
|
||||
</form>
|
||||
<form id="add-form" hx-post="{% url 'attendance-overtime-create' %}" hx-target="#objectCreateModalTarget"
|
||||
hx-swap="innerHTML">
|
||||
{{form.as_p}}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="oh-input__group">
|
||||
<label class="oh-input__label" for="{{ form.allowed_time.id_for_label }}">{% trans 'Allowed Time' %}</label>
|
||||
<label class="oh-input__label" for="{{ form.allowed_time.id_for_label }}">{{ form.allowed_time.label }}</label>
|
||||
{{ form.allowed_time }}
|
||||
{{ form.allowed_time.errors }}
|
||||
</div>
|
||||
@@ -50,7 +50,7 @@
|
||||
<div class="col-12 col-sm-12 col-md-6 col-lg-6">
|
||||
<div class="oh-input__group">
|
||||
<div style="display: flex;">
|
||||
<label class="oh-input__label" for="{{ form.allowed_clock_in.id_for_label }}">{% trans 'Allowed Clock-In' %}</label>
|
||||
<label class="oh-input__label" for="{{ form.allowed_clock_in.id_for_label }}">{{ form.allowed_clock_in.label }}</label>
|
||||
<span class="oh-info mt-2" title="{{form.allowed_clock_in.help_text|safe }}"></span>
|
||||
</div>
|
||||
<div class="oh-switch p-2 pt-0">
|
||||
@@ -62,7 +62,7 @@
|
||||
<div class="col-12 col-sm-12 col-md-6 col-lg-6">
|
||||
<div class="oh-input__group">
|
||||
<div style="display: flex;">
|
||||
<label class="oh-input__label" for="{{ form.allowed_clock_out.id_for_label }}">{% trans 'Allowed Clock-Out' %}</label>
|
||||
<label class="oh-input__label" for="{{ form.allowed_clock_out.id_for_label }}">{{ form.allowed_clock_out.label }}</label>
|
||||
<span class="oh-info mt-2" title="{{form.allowed_clock_out.help_text|safe }}"></span>
|
||||
</div>
|
||||
<div class="oh-switch p-2 pt-0">
|
||||
|
||||
@@ -427,7 +427,6 @@ def validate_attendance_request(request, attendance_id):
|
||||
other_dict = first_dict
|
||||
first_dict = empty_data
|
||||
else:
|
||||
print(attendance.requested_data)
|
||||
other_dict = json.loads(attendance.requested_data)
|
||||
requests_ids_json = request.GET.get("requests_ids")
|
||||
previous_instance_id = next_instance_id = attendance.pk
|
||||
|
||||
Reference in New Issue
Block a user