From c9b07622ebf6f6dcceff3d6906d3ed33d74f24fd Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 11 Mar 2020 13:27:04 +0100 Subject: Searc criteria: add has image/file/url criteria for all document items --- ishtar_common/forms.py | 24 ++++++++++++++++++++---- ishtar_common/models.py | 17 +++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 17ada982f..939563334 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -782,23 +782,39 @@ class HistorySelect(CustomForm, TableSelect): label=_("Modified after"), widget=DatePicker, required=False) _explicit_ordering = True + CURRENT_FIELDS = ["history_creator", "history_modifier", + "modified_before", "modified_after"] def __init__(self, *args, **kwargs): super(HistorySelect, self).__init__(*args, **kwargs) field_order = self.fields.keys() - current_fields = ["history_creator", "history_modifier", - "modified_before", "modified_after"] fields = OrderedDict() for k in field_order: - if k in current_fields: + if k in self.CURRENT_FIELDS: continue fields[k] = self.fields[k] - for k in current_fields: + for k in self.CURRENT_FIELDS: fields[k] = self.fields[k] self.fields = fields self.custom_form_ordering() +class DocumentItemSelect(HistorySelect): + documents__image__isnull = forms.NullBooleanField(label=_("Has an image?")) + documents__associated_file__isnull = forms.NullBooleanField( + label=_("Has an attached file?")) + documents__associated_url__isnull = forms.NullBooleanField( + label=_("Has a web address?")) + CURRENT_FIELDS = [ + 'documents__image__isnull', + 'documents__associated_file__isnull', + 'documents__associated_url__isnull', + "history_creator", "history_modifier", + "modified_before", "modified_after" + ] + _explicit_ordering = True + + def get_now(): format = formats.get_format('DATE_INPUT_FORMATS')[0] value = datetime.datetime.now().strftime(format) diff --git a/ishtar_common/models.py b/ishtar_common/models.py index dc2fef815..5fa668faf 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1818,6 +1818,21 @@ class QRCodeItem(models.Model, ImageContainerModel): class DocumentItem(object): + ALT_NAMES = { + 'documents__image__isnull': + SearchAltName( + pgettext_lazy("key for text search", "has-image"), + 'documents__image__isnull'), + 'documents__associated_url__isnull': + SearchAltName( + pgettext_lazy("key for text search", "has-url"), + 'documents__associated_url__isnull'), + 'documents__associated_file__isnull': + SearchAltName( + pgettext_lazy("key for text search", "has-attached-file"), + 'documents__associated_file__isnull'), + } + def public_representation(self): images = [] if getattr(self, "main_image", None): @@ -5600,6 +5615,8 @@ class Document(BaseHistorizedItem, QRCodeItem, OwnPerms, ImageModel, no_path_change = 'no_path_change' in kwargs \ and kwargs.pop('no_path_change') self.set_index() + if not self.associated_url: + self.associated_url = None super(Document, self).save(*args, **kwargs) if self.image and not no_path_change and \ -- cgit v1.2.3