From 56c5f6e31f34e47d9a6c31767840c9d949d63abf Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 18 Dec 2023 18:56:31 +0100 Subject: ✨ imports: add search criteria MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/forms.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index c560dc5ec..b81b42bc6 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -1000,7 +1000,28 @@ class HistorySelect(CustomForm, TableSelect): self.custom_form_ordering() -class DocumentItemSelect(HistorySelect): +class ImportSelect(HistorySelect): + imports = forms.IntegerField( + label=_("Imported from"), + widget=widgets.JQueryAutoComplete( + reverse_lazy( + 'autocomplete-import', + ), + associated_model=models.Import), + validators=[models.valid_id(models.Import)]) + CURRENT_FIELDS = [ + "imports", + ] + HistorySelect.CURRENT_FIELDS + _explicit_ordering = True + + def __init__(self, *args, **kwargs): + user = kwargs.get("user", None) + super().__init__(*args, **kwargs) + if not user or (not user.has_perm("view_import") and not user.has_perm("view_own_import")): + self.fields.pop("imports") + + +class DocumentItemSelect(ImportSelect): documents__image__isnull = forms.NullBooleanField(label=_("Has an image?")) documents__associated_file__isnull = forms.NullBooleanField( label=_("Has an attached file?") @@ -1012,7 +1033,7 @@ class DocumentItemSelect(HistorySelect): "documents__image__isnull", "documents__associated_file__isnull", "documents__associated_url__isnull", - ] + HistorySelect.CURRENT_FIELDS + ] + ImportSelect.CURRENT_FIELDS _explicit_ordering = True -- cgit v1.2.3