[UPDT] BASE: Updated base app forms and models
This commit is contained in:
@@ -251,6 +251,18 @@ class ModelForm(forms.ModelForm):
|
||||
except:
|
||||
pass
|
||||
|
||||
def verbose_name(self):
|
||||
"""
|
||||
Returns the verbose name of the model associated with the form.
|
||||
Provides fallback values if no model or verbose name is defined.
|
||||
"""
|
||||
if hasattr(self, "_meta") and hasattr(self._meta, "model"):
|
||||
model = self._meta.model
|
||||
if hasattr(model._meta, "verbose_name") and model._meta.verbose_name:
|
||||
return model._meta.verbose_name
|
||||
return model.__name__
|
||||
return ""
|
||||
|
||||
|
||||
class Form(forms.Form):
|
||||
"""
|
||||
@@ -490,20 +502,21 @@ class JobPositionMultiForm(ModelForm):
|
||||
JobPosition model's form
|
||||
"""
|
||||
|
||||
department_id = HorillaMultiSelectField(queryset=Department.objects.all())
|
||||
department_id = HorillaMultiSelectField(
|
||||
queryset=Department.objects.all(),
|
||||
label=JobPosition._meta.get_field("department_id").verbose_name,
|
||||
widget=forms.SelectMultiple(
|
||||
attrs={
|
||||
"class": "oh-select oh-select2 w-100",
|
||||
"style": "height:45px;",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = JobPosition
|
||||
fields = "__all__"
|
||||
exclude = ["department_id", "is_active"]
|
||||
widgets = {
|
||||
"department_id": forms.SelectMultiple(
|
||||
attrs={
|
||||
"class": "oh-select oh-select2 w-100",
|
||||
"style": "height:45px;",
|
||||
}
|
||||
),
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
"""
|
||||
|
||||
@@ -143,7 +143,9 @@ class JobPosition(HorillaModel):
|
||||
JobPosition model
|
||||
"""
|
||||
|
||||
job_position = models.CharField(max_length=50, blank=False, null=False)
|
||||
job_position = models.CharField(
|
||||
max_length=50, blank=False, null=False, verbose_name=_("Job Position")
|
||||
)
|
||||
department_id = models.ForeignKey(
|
||||
Department,
|
||||
on_delete=models.PROTECT,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% load i18n %}
|
||||
<div class="oh-modal__dialog-header pb-0">
|
||||
<span class="oh-modal__dialog-title" id="createModalLabel">
|
||||
{% if department.id %} {% trans "Update" %}{% else %} {% trans "Create" %} {% endif %} {% trans "Department" %}
|
||||
{% if department.id %} {% trans "Update" %}{% else %} {% trans "Create" %} {% endif %} {{form.verbose_name}}
|
||||
</span>
|
||||
<button class="oh-modal__close" aria-label="Close">
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
|
||||
@@ -1,49 +1,35 @@
|
||||
{% load i18n %}
|
||||
<div class="oh-modal__dialog-header pb-0">
|
||||
<span class="oh-modal__dialog-title" id="editModal1ModalLabel"
|
||||
>
|
||||
{% if job_position.id %}
|
||||
{% trans "Update Job Position" %}
|
||||
{% else %}
|
||||
{% trans "Create Job Position" %}
|
||||
{% endif %}
|
||||
</span>
|
||||
<button class="oh-modal__close" aria-label="Close">
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
<span class="oh-modal__dialog-title" id="editModal1ModalLabel">
|
||||
{% if job_position.id %} {% trans "Update" %} {% else %} {% trans "Create" %} {% endif %} {{form.verbose_name}}
|
||||
</span>
|
||||
<button class="oh-modal__close" aria-label="Close">
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
</div>
|
||||
<div class="oh-modal__dialog-body">
|
||||
<form
|
||||
{% if job_position.id %}
|
||||
hx-post="{% url 'job-position-update' job_position.id %}"
|
||||
{% else %}
|
||||
hx-post="{% url 'job-position-creation' %}?dynamic={{dynamic}}"
|
||||
{% endif %}
|
||||
{% if dynamic%}
|
||||
hx-target="#dynamicCreateModalBody"
|
||||
{% else %}
|
||||
hx-target="#jobPositionForm"
|
||||
{% endif %}
|
||||
class="oh-profile-section">
|
||||
{% csrf_token %}
|
||||
<div class="oh-inner-sidebar-content__body">
|
||||
<div class="oh-input-group mb-2">
|
||||
<label class="mb-1" for="id_{{form.department_id.name}}">
|
||||
{% trans "Department:" %}
|
||||
</label>
|
||||
{{form.department_id}} {{form.department_id.errors}}
|
||||
</div>
|
||||
<div class="oh-input-group mb-2">
|
||||
<label class="mb-1" for="id_{{form.job_position.name}}">
|
||||
{% trans "Job Position:" %}
|
||||
</label>
|
||||
{{form.job_position}} {{form.job_position.errors}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh-modal__dialog-footer p-0 mt-3">
|
||||
<button type="submit" class="oh-btn oh-btn--secondary oh-btn--shadow" >
|
||||
{% trans "Save" %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<form hx-post="{{ request.get_full_path }}"
|
||||
hx-target="{% if dynamic %}#dynamicCreateModalBody{% else %}#jobPositionForm{% endif %}"
|
||||
class="oh-profile-section">
|
||||
{% csrf_token %}
|
||||
<div class="oh-inner-sidebar-content__body">
|
||||
<div class="oh-input-group mb-2">
|
||||
<label class="mb-1" for="id_{{form.department_id.name}}">
|
||||
{{ form.department_id.label }}
|
||||
</label>
|
||||
{{form.department_id}} {{form.department_id.errors}}
|
||||
</div>
|
||||
<div class="oh-input-group mb-2">
|
||||
<label class="mb-1" for="id_{{form.job_position.name}}">
|
||||
{{ form.job_position.label }}
|
||||
</label>
|
||||
{{form.job_position}} {{form.job_position.errors}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh-modal__dialog-footer p-0 mt-3">
|
||||
<button type="submit" class="oh-btn oh-btn--secondary oh-btn--shadow">
|
||||
{% trans "Save" %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user