Files
ihrm/helpdesk/forms.py

218 lines
5.7 KiB
Python
Raw Normal View History

"""
forms.py
This module contains the form classes used in the application.
Each form represents a specific functionality or data input in the
application. They are responsible for validating
and processing user input data.
Classes:
- YourForm: Represents a form for handling specific data input.
Usage:
from django import forms
class YourForm(forms.Form):
field_name = forms.CharField()
def clean_field_name(self):
# Custom validation logic goes here
pass
"""
from typing import Any
from django import forms
from django.template.loader import render_to_string
from base.forms import ModelForm
from base.methods import is_reportingmanager
from base.models import Department, JobPosition
from employee.forms import MultipleFileField
from employee.models import Employee
from helpdesk.models import (
FAQ,
Attachment,
Comment,
DepartmentManager,
FAQCategory,
Ticket,
TicketType,
)
from horilla import horilla_middlewares
class TicketTypeForm(ModelForm):
class Meta:
model = TicketType
fields = "__all__"
exclude = ["is_active"]
def as_p(self, *args, **kwargs):
"""
Render the form fields as HTML table rows with Bootstrap styling.
"""
context = {"form": self}
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
table_html = render_to_string("horilla_form.html", context)
return table_html
class FAQForm(ModelForm):
class Meta:
model = FAQ
fields = "__all__"
exclude = ["is_active"]
widgets = {
"category": forms.HiddenInput(),
"tags": forms.SelectMultiple(
attrs={
"class": "oh-select oh-select-2 select2-hidden-accessible",
"onchange": "updateTag()",
}
),
}
def __init__(self, *args, **kwargs):
"""
Initializes the Ticket tag form instance.
If an instance is provided, sets the initial value for the form's .
"""
super().__init__(*args, **kwargs)
self.fields["tags"].choices = list(self.fields["tags"].choices)
self.fields["tags"].choices.append(("create_new_tag", "Create new tag"))
class TicketForm(ModelForm):
deadline = forms.DateField(widget=forms.DateInput(attrs={"type": "date"}))
class Meta:
model = Ticket
fields = [
"id",
"title",
"employee_id",
"description",
"ticket_type",
"priority",
"assigning_type",
"raised_on",
"deadline",
"status",
"tags",
]
widgets = {
"raised_on": forms.Select(
attrs={"class": "oh-select oh-select-2", "required": "true"}
),
}
def as_p(self, *args, **kwargs):
"""
Render the form fields as HTML table rows with Bootstrap styling.
"""
context = {"form": self}
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
table_html = render_to_string("horilla_form.html", context)
return table_html
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["attachment"] = MultipleFileField(
label="Attachements", required=False
)
self.fields["tags"].choices = list(self.fields["tags"].choices)
self.fields["tags"].choices.append(("create_new_tag", "Create new tag"))
self.fields["ticket_type"].choices = list(self.fields["ticket_type"].choices)
request = getattr(horilla_middlewares._thread_locals, "request", None)
if is_reportingmanager(request):
self.fields["ticket_type"].choices.append(
("create_new_ticket_type", "Create new ticket type")
)
class TicketTagForm(ModelForm):
class Meta:
model = Ticket
fields = [
"tags",
]
widgets = {
"tags": forms.SelectMultiple(
attrs={
"class": "oh-select oh-select-2 select2-hidden-accessible",
"onchange": "updateTag()",
}
),
}
def __init__(self, *args, **kwargs):
"""
Initializes the Ticket tag form instance.
If an instance is provided, sets the initial value for the form's .
"""
super().__init__(*args, **kwargs)
self.fields["tags"].choices = list(self.fields["tags"].choices)
self.fields["tags"].choices.append(("create_new_tag", "Create new tag"))
class TicketRaisedOnForm(ModelForm):
class Meta:
model = Ticket
fields = ["assigning_type", "raised_on"]
widgets = {
"raised_on": forms.Select(
attrs={"class": "oh-select oh-select-2", "required": "true"},
),
}
class TicketAssigneesForm(ModelForm):
class Meta:
model = Ticket
fields = [
"assigned_to",
]
class FAQCategoryForm(ModelForm):
class Meta:
model = FAQCategory
fields = "__all__"
exclude = ["is_active"]
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = [
"comment",
]
exclude = ["is_active"]
widgets = {"employee_id": forms.HiddenInput()}
class AttachmentForm(forms.ModelForm):
file = forms.FileField(
widget=forms.TextInput(
attrs={
"name": "file",
"type": "File",
"class": "form-control",
"multiple": "True",
}
),
label="",
)
class Meta:
model = Attachment
fields = ["file", "comment", "ticket"]
exclude = ["is_active"]
class DepartmentManagerCreateForm(ModelForm):
class Meta:
model = DepartmentManager
fields = ["department", "manager"]