From dcc85ef63807cf6092ba17bb118eb3b15ba5a59e Mon Sep 17 00:00:00 2001 From: Horilla Date: Tue, 16 Sep 2025 10:14:32 +0530 Subject: [PATCH] [UPDT] HELPDESK: Updated helpdesk form widgets --- helpdesk/forms.py | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/helpdesk/forms.py b/helpdesk/forms.py index 219619070..ef3935ca3 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -66,22 +66,16 @@ class FAQForm(ModelForm): exclude = ["is_active"] widgets = { "category": forms.HiddenInput(), - "tags": forms.SelectMultiple( - attrs={ - "class": "oh-select oh-select-2 select2-hidden-accessible", - "onchange": "updateTag(this)", - } - ), } def __init__(self, *args, **kwargs): - """ - Initializes the Ticket tag form instance. - If an instance is provided, sets the initial value for the form's . - """ + """Initializes the FAQ form instance and adjusts the tags field.""" super().__init__(*args, **kwargs) - self.fields["tags"].choices = list(self.fields["tags"].choices) - self.fields["tags"].choices.append(("create_new_tag", "Create new tag")) + + if "tags" in self.fields: + self.fields["tags"].choices = list(self.fields["tags"].choices) + self.fields["tags"].widget.attrs.update({"onchange": "updateTag(this)"}) + self.fields["tags"].choices.append(("create_new_tag", "Create new tag")) class TicketForm(ModelForm): @@ -161,14 +155,6 @@ class TicketTagForm(ModelForm): fields = [ "tags", ] - widgets = { - "tags": forms.SelectMultiple( - attrs={ - "class": "oh-select oh-select-2 select2-hidden-accessible", - "onchange": "updateTag()", - } - ), - } def __init__(self, *args, **kwargs): """ @@ -177,7 +163,13 @@ class TicketTagForm(ModelForm): """ super().__init__(*args, **kwargs) request = getattr(horilla_middlewares._thread_locals, "request", None) - if is_reportingmanager(request) or request.user.has_perm("base.add_tags"): + + if ( + request + and request.user.is_authenticated + and (is_reportingmanager(request) or request.user.has_perm("base.add_tags")) + ): + self.fields["tags"].widget.attrs.update({"onchange": "updateTag(this)"}) self.fields["tags"].choices = list(self.fields["tags"].choices) self.fields["tags"].choices.append(("create_new_tag", "Create new tag"))