diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-03-11 13:27:04 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-03-11 13:27:04 +0100 |
commit | c9b07622ebf6f6dcceff3d6906d3ed33d74f24fd (patch) | |
tree | c248b4e8b129d017373af2a07d399f5ca82717b1 /ishtar_common | |
parent | df67b2c757e813512a6e5f1ea31f8a4693444013 (diff) | |
download | Ishtar-c9b07622ebf6f6dcceff3d6906d3ed33d74f24fd.tar.bz2 Ishtar-c9b07622ebf6f6dcceff3d6906d3ed33d74f24fd.zip |
Searc criteria: add has image/file/url criteria for all document items
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms.py | 24 | ||||
-rw-r--r-- | ishtar_common/models.py | 17 |
2 files changed, 37 insertions, 4 deletions
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 \ |