diff options
-rw-r--r-- | CHANGES.md | 8 | ||||
-rw-r--r-- | ishtar_common/admin.py | 4 | ||||
-rw-r--r-- | ishtar_common/forms.py | 19 | ||||
-rw-r--r-- | ishtar_common/migrations/0226_auto_20230316_1115.py | 100 | ||||
-rw-r--r-- | ishtar_common/models.py | 11 | ||||
-rw-r--r-- | ishtar_common/templates/blocks/bs_form_snippet.html | 6 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/footer.html | 3 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 2 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 2 |
9 files changed, 144 insertions, 11 deletions
diff --git a/CHANGES.md b/CHANGES.md index 4e75bd47d..8e971e11b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -38,9 +38,10 @@ Ishtar changelog - improve many facet query - Document - source type is now a hierarchic search - Context record: add identification and activity criteria -- Find form: remove TAQ/TPQ check - File: filter plan action when preventive_operator is activated in profile -- Profile: do not display geo item list when mapping is deactivated +- Profile: + - do not display geo item list when mapping is deactivated + - custom footer message - Explicit message on associated container deletion when a warehouse is deleted - Administrative act: add a warning when associated item is deleted - Imports: register automatically type models for export @@ -48,6 +49,9 @@ Ishtar changelog - UI: - sheet header - add caret to show collapse - show/hide password on login +- Forms: + - custom form - can add header message + - Find: remove TAQ/TPQ check - Sheet: - fix treatment and file treatment sheet display (bad QR code link) diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py index 4937d75b6..a23e44b33 100644 --- a/ishtar_common/admin.py +++ b/ishtar_common/admin.py @@ -516,7 +516,8 @@ class IshtarSiteProfileAdmin(admin.ModelAdmin): "fields": ( "description", "warning_name", - "warning_message" + "warning_message", + "footer", ), }), (_("Modules"), { @@ -2066,6 +2067,7 @@ class CustomFormAdmin(admin.ModelAdmin): "form", "available", "enabled", + "header", "apply_to_all", "users", "user_types", diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 1497a97b9..e29e4ca0f 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -22,6 +22,7 @@ Forms definition """ from collections import OrderedDict import datetime +from markdown import markdown import re import types @@ -184,6 +185,7 @@ class CustomForm(BSForm): def __init__(self, *args, **kwargs): self.current_user = None + self.custom_header = "" if "user" in kwargs: try: self.current_user = kwargs.pop("user").ishtaruser @@ -194,7 +196,9 @@ class CustomForm(BSForm): self.custom_form_ordering() def custom_form_ordering(self): - available, excluded, json_fields = self.check_custom_form(self.current_user) + available, header, excluded, json_fields = self.check_custom_form( + self.current_user) + self.custom_header = header for exc in excluded: if hasattr(self, "fields"): self.remove_field(exc) @@ -329,10 +333,10 @@ class CustomForm(BSForm): """ Check form customization :param current_user: - :return: available, excluded_fields, json_fields + :return: available, custom header, excluded_fields, json_fields """ if not current_user: - return True, [], [] + return True, "", [], [] base_q = {"form": cls.form_slug, "available": True} # order is important : try for user, profile type, user type then all query_dicts = [] @@ -362,15 +366,18 @@ class CustomForm(BSForm): form = q.all()[0] break if not form: - return True, [], [] + return True, "", [], [] if not form.enabled: - return False, [], [] + return False, "", [], [] excluded_lst = [] for excluded in form.excluded_fields.all(): # could have be filtered previously excluded_lst.append(excluded.field) json_fields = cls._get_json_fields(form) - return True, excluded_lst, json_fields + header = form.header + if header: + header = markdown(header) + return True, header, excluded_lst, json_fields @classmethod def get_custom_fields(cls): diff --git a/ishtar_common/migrations/0226_auto_20230316_1115.py b/ishtar_common/migrations/0226_auto_20230316_1115.py new file mode 100644 index 000000000..4ed95ff2a --- /dev/null +++ b/ishtar_common/migrations/0226_auto_20230316_1115.py @@ -0,0 +1,100 @@ +# Generated by Django 2.2.24 on 2023-03-16 11:15 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0225_migrate_created'), + ] + + operations = [ + migrations.AlterModelOptions( + name='customformjsonfield', + options={'verbose_name': 'Custom forms - Json data field', 'verbose_name_plural': 'Custom forms - Json data fields'}, + ), + migrations.AlterModelOptions( + name='importermodel', + options={'ordering': ('name',), 'verbose_name': 'Data model', 'verbose_name_plural': 'Data models'}, + ), + migrations.AlterModelOptions( + name='ishtaruser', + options={'ordering': ('person',), 'verbose_name': 'Ishtar user', 'verbose_name_plural': 'Ishtar users'}, + ), + migrations.AlterModelOptions( + name='itemkey', + options={'verbose_name': 'Importer - Item key', 'verbose_name_plural': 'Imports - Item keys'}, + ), + migrations.AddField( + model_name='customform', + name='header', + field=models.TextField(default='', help_text='You can use markdown syntax.', verbose_name='Header text'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='footer', + field=models.TextField(default='', help_text='You can use markdown syntax.', verbose_name='Footer text'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='basefind_cached_label', + field=models.TextField(blank=True, default='', help_text='Formula to manage cached label. If not set a default formula is used.', verbose_name='Base find cached label'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='container_cached_label', + field=models.TextField(blank=True, default='', help_text='Formula to manage cached label. If not set a default formula is used.', verbose_name='Container cached label'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='contextrecord_cached_label', + field=models.TextField(blank=True, default='', help_text='Formula to manage cached label. If not set a default formula is used.', verbose_name='Context record cached label'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='document_cached_label', + field=models.TextField(blank=True, default='', help_text='Formula to manage cached label. If not set a default formula is used.', verbose_name='Document cached label'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='file_cached_label', + field=models.TextField(blank=True, default='', help_text='Formula to manage cached label. If not set a default formula is used.', verbose_name='File cached label'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='find_cached_label', + field=models.TextField(blank=True, default='', help_text='Formula to manage cached label. If not set a default formula is used.', verbose_name='Find cached label'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='operation_cached_label', + field=models.TextField(blank=True, default='', help_text='Formula to manage cached label. If not set a default formula is used.', verbose_name='Operation cached label'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='parcel_cached_label', + field=models.TextField(blank=True, default='', help_text='Formula to manage cached label. If not set a default formula is used.', verbose_name='Parcel cached label'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='parent_relations_engine', + field=models.CharField(choices=[('V', 'SQL views'), ('T', 'Cache tables')], default='V', help_text='If you experience performance problems with complex relations (for instance: complex statigraphic relations), set it to "Cache tables" in order to use static cache tables. Do not forget to update theses table with the "migrate_relations_cache_tables" manage.py command.', max_length=1, verbose_name='Parent relations engine'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='site_cached_label', + field=models.TextField(blank=True, default='', help_text='Formula to manage cached label. If not set a default formula is used.', verbose_name='Site cached label'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='srs', + field=models.ForeignKey(blank=True, help_text='Set it to the most used spatial reference system. Warning: after change launch the migrate_srid script.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='profile_srs', to='ishtar_common.SpatialReferenceSystem', verbose_name='Spatial Reference System in database'), + ), + migrations.AlterField( + model_name='ishtarsiteprofile', + name='warehouse_cached_label', + field=models.TextField(blank=True, default='', help_text='Formula to manage cached label. If not set a default formula is used.', verbose_name='Warehouse cached label'), + ), + ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index d4ea72dea..420670ca1 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -38,6 +38,7 @@ import time from io import BytesIO from subprocess import Popen, PIPE from PIL import Image +from markdown import markdown from ooopy.OOoPy import OOoPy from ooopy.Transformer import Transformer as OOTransformer import ooopy.Transforms as OOTransforms @@ -1036,6 +1037,8 @@ class IshtarSiteProfile(models.Model, Cached): description = models.TextField(_("Description"), blank=True, default="") warning_name = models.TextField(_("Warning name"), blank=True, default="") warning_message = models.TextField(_("Warning message"), blank=True, default="") + footer = models.TextField(_("Footer text"), default="", blank=True, + help_text=_("You can use markdown syntax.")) delete_image_zip_on_archive = models.BooleanField( _("Import - Delete image/document zip on archive"), default=False ) @@ -1563,6 +1566,12 @@ class IshtarSiteProfile(models.Model, Cached): return str(dict(SITE_LABELS)[self.archaeological_site_label]) return str(TRANSLATED_SITE_LABELS[self.archaeological_site_label][key]) + @property + def rendered_footer(self): + if not self.footer: + return "" + return markdown(self.footer) + def save(self, *args, **kwargs): raw = False if "raw" in kwargs: @@ -1628,6 +1637,8 @@ class CustomForm(models.Model): "fields may lead to database errors." ), ) + header = models.TextField(_("Header text"), default="", blank=True, + help_text=_("You can use markdown syntax.")) apply_to_all = models.BooleanField( _("Apply to all"), default=False, diff --git a/ishtar_common/templates/blocks/bs_form_snippet.html b/ishtar_common/templates/blocks/bs_form_snippet.html index 769234949..c80468db9 100644 --- a/ishtar_common/templates/blocks/bs_form_snippet.html +++ b/ishtar_common/templates/blocks/bs_form_snippet.html @@ -12,6 +12,12 @@ </div>{% endif %} {% endfor %} +{% if form.custom_header %} +<div class="alert alert-info" role="alert"> + {{form.custom_header|safe}} +</div> +{% endif %} + {% csrf_token %} {% for field in form.visible_fields %} {% if form.SEARCH_AND_SELECT %} diff --git a/ishtar_common/templates/ishtar/blocks/footer.html b/ishtar_common/templates/ishtar/blocks/footer.html index 8705c5892..a937b3abe 100644 --- a/ishtar_common/templates/ishtar/blocks/footer.html +++ b/ishtar_common/templates/ishtar/blocks/footer.html @@ -1,3 +1,6 @@ {% load i18n %}<div id="foot"> + {% if SITE_PROFILE.footer %}<div id="extra-foot"> + {{SITE_PROFILE.rendered_footer|safe}} + </div>{% endif %} {% blocktrans %}Powered by <a href="https://ishtar-archeo.net/">Ishtar</a> v{{VERSION}} - a free software under AGPL v3 license.{% endblocktrans %} </div>
\ No newline at end of file diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 3d43541e5..9f90db4bf 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -1870,7 +1870,7 @@ def get_item( and request.user and getattr(request.user, "ishtaruser", None) ): - available, excluded_fields, json_fields = search_form.check_custom_form( + available, __, excluded_fields, json_fields = search_form.check_custom_form( request.user.ishtaruser ) # for now no manage on excluded_fields: should we prevent search on diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index fa14d9827..f6b2894ab 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -79,7 +79,7 @@ def filter_no_fields_form(form, other_check=None): if not hasattr(self.request.user, "ishtaruser"): return False if issubclass(form, CustomForm): - enabled, excluded, json_fields = form.check_custom_form( + enabled, __, excluded, json_fields = form.check_custom_form( self.request.user.ishtaruser ) if not hasattr(self, "json_fields"): |