From d90fc9d5070c51944c4a36163d44809866c52dd9 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Tue, 17 Oct 2023 14:02:54 +0200 Subject: [PATCH] Fix undefined search value --- core/forms.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/forms.py b/core/forms.py index e2b2ede..b8fa91e 100644 --- a/core/forms.py +++ b/core/forms.py @@ -209,12 +209,13 @@ class Meta: class SecurityMeasureCreateForm(LinkCleanMixin, StyledModelForm): + folder = forms.ModelChoiceField(queryset=Folder.objects.none()) def __init__(self, user=None, *args, **kwargs): super().__init__(*args, **kwargs) if user: self.fields['folder'].queryset = Folder.objects.filter(id__in=RoleAssignment.get_accessible_folders(Folder.get_root_folder(), user, Folder.ContentType.DOMAIN, codename="add_securitymeasure")) else: - self.fields['folder'].queryset = Folder.objects.filter(content_type=Folder.ContentType.DOMAIN) + self.fields['folder'].queryset = Folder.objects.none() self.fields['folder'].widget = SearchableSelect(attrs={'class': 'text-sm rounded', 'searchbar_class': '[&_.search-icon]:text-gray-500 text-sm px-3', 'wrapper_class': 'border border-gray-300 bg-gray-50 text-gray-900 text-sm rounded-b-lg focus:ring-blue-500 focus:border-blue-500 max-h-56 overflow-y-scroll'}, @@ -389,16 +390,17 @@ def clean(self): class ProjectForm(StyledModelForm): - def __init__(self, user=None, *args, **kwargs): - super(ProjectForm, self).__init__(*args, **kwargs) + folder = forms.ModelChoiceField(queryset=Folder.objects.none()) + def __init__(self, user=None, *args, **kwargs): + super().__init__(*args, **kwargs) if user: - self.fields['folder'].queryset = Folder.objects.filter(id__in=RoleAssignment.get_accessible_folders(Folder.get_root_folder(), user, Folder.ContentType.DOMAIN, codename="add_project")) + self.fields['folder'].queryset = Folder.objects.filter(id__in=RoleAssignment.get_accessible_folders(Folder.get_root_folder(), user, Folder.ContentType.DOMAIN, codename="add_securitymeasure")) else: - self.fields['folder'].queryset = Folder.objects.filter(content_type=Folder.ContentType.DOMAIN) + self.fields['folder'].queryset = Folder.objects.none() self.fields['folder'].widget = SearchableSelect(attrs={'class': 'text-sm rounded', - 'searchbar_class': '[&_.search-icon]:text-gray-500 text-sm px-3', - 'wrapper_class': 'border border-gray-300 bg-gray-50 text-gray-900 text-sm rounded-b-lg focus:ring-blue-500 focus:border-blue-500 max-h-56 overflow-y-scroll'}, - choices=self.fields['folder'].choices) + 'searchbar_class': '[&_.search-icon]:text-gray-500 text-sm px-3', + 'wrapper_class': 'border border-gray-300 bg-gray-50 text-gray-900 text-sm rounded-b-lg focus:ring-blue-500 focus:border-blue-500 max-h-56 overflow-y-scroll'}, + choices=self.fields['folder'].choices) class Meta: