From 166bbed4bf4b9114fcb154359ae5f60496fd81ef Mon Sep 17 00:00:00 2001 From: RogerHaase Date: Fri, 20 Oct 2023 14:21:44 -0700 Subject: [PATCH] Revert "remove Extra MetaData (JSON) from modify view, fixes #700" This reverts commit dd3532629f79074a651e6d16bf405e36ec8cbfb8. Added 2 mods to revert: * items/__init__.py added try/TypeError block near line 829 * templates/modify.html added test for item names ending in Group/Dict near line 71 --- src/moin/forms.py | 7 +++++++ src/moin/items/__init__.py | 9 ++++++++- src/moin/templates/modify.html | 5 +++++ src/moin/themes/basic/templates/modify.html | 7 +++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/moin/forms.py b/src/moin/forms.py index c7a56174f..ccace17c0 100644 --- a/src/moin/forms.py +++ b/src/moin/forms.py @@ -153,6 +153,13 @@ def validate(self, element, state): # incoming request is from +usersettings#personal; # apps/frontend/views.py will validate changes to user names return True + # Make sure that the other meta is valid before validating the name. + # TODO: prove the try below is always redundant and remove it. + try: + if not element.parent.parent['extra_meta_text'].valid: + return False + except AttributeError: + pass try: validate_name(state['meta'], state[ITEMID]) except NameNotValidError as e: diff --git a/src/moin/items/__init__.py b/src/moin/items/__init__.py index 7d46ef045..eb5dfd248 100644 --- a/src/moin/items/__init__.py +++ b/src/moin/items/__init__.py @@ -48,7 +48,7 @@ from moin.utils.registry import RegistryBase from moin.utils.diff_html import diff as html_diff from moin.utils import diff3 -from moin.forms import RequiredText, OptionalText, Tags, Names, validate_name, NameNotValidError +from moin.forms import RequiredText, OptionalText, JSON, Tags, Names, validate_name, NameNotValidError from moin.constants.keys import ( NAME, NAMES, NAMENGRAM, NAME_OLD, NAME_EXACT, WIKINAME, MTIME, ITEMTYPE, CONTENTTYPE, SIZE, ACTION, ADDRESS, HOSTNAME, USERID, COMMENT, @@ -790,6 +790,7 @@ class _ModifyForm(BaseModifyForm): ModifyForm. """ meta_form = BaseMetaForm + extra_meta_text = JSON.using(label=L_("Extra MetaData (JSON)")).with_properties(rows=ROWS_META, cols=COLS) meta_template = 'modify_meta.html' def _load(self, item): @@ -808,6 +809,7 @@ def _load(self, item): self['meta_form'].set(meta, policy='duck') for k in list(self['meta_form'].field_schema_mapping.keys()) + IMMUTABLE_KEYS: meta.pop(k, None) + self['extra_meta_text'].set(item.meta_dict_to_text(meta)) self['content_form']._load(item.content) def _dump(self, item): @@ -825,6 +827,11 @@ def _dump(self, item): # e.g. we get PARENTID in here meta = item.meta_filter(item.prepare_meta_for_modify(item.meta)) meta.update(self['meta_form'].value) + try: + meta.update(item.meta_text_to_dict(self['extra_meta_text'].value)) + except TypeError: + # only items with names ending in Group or Dict have extra_meta.test + pass data, contenttype_guessed = self['content_form']._dump(item.content) comment = self['comment'].value return meta, data, contenttype_guessed, comment diff --git a/src/moin/templates/modify.html b/src/moin/templates/modify.html index ff7b00978..e5fca1ebb 100644 --- a/src/moin/templates/modify.html +++ b/src/moin/templates/modify.html @@ -68,6 +68,11 @@

{{ title }}

{{ data_editor(form['content_form'], item_name) }} {% set may_admin = user.may.admin(fqname) %} {{ meta_editor(form['meta_form'], may_admin) }} + {% if fqname.fullname.endswith(('Group', 'Dict')) %} +
+ {{ forms.render(form['extra_meta_text']) }} +
+ {% endif %} {{ gen.form.close() }} diff --git a/src/moin/themes/basic/templates/modify.html b/src/moin/themes/basic/templates/modify.html index e456e58cb..7ffddef24 100644 --- a/src/moin/themes/basic/templates/modify.html +++ b/src/moin/themes/basic/templates/modify.html @@ -54,6 +54,13 @@

{{ title }}

{{ basic_meta_editor(form['meta_form']) }}
+ {% set field = form['extra_meta_text'] %} +
+
+ {{ gen.label(field) }} + {{ gen.textarea(field, rows=field.properties.rows|string, cols=field.properties.cols|string, class='form-control') }} +
+