Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Fix undefined search value
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Oct 17, 2023
1 parent 31a144c commit d90fc9d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d90fc9d

Please sign in to comment.