Skip to content

Commit

Permalink
Revert "remove Extra MetaData (JSON) from modify view, fixes #700"
Browse files Browse the repository at this point in the history
This reverts commit dd35326.

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
  • Loading branch information
RogerHaase committed Oct 20, 2023
1 parent 3dba5df commit 166bbed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/moin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src/moin/items/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/moin/templates/modify.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ <h1>{{ title }}</h1>
{{ 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')) %}
<dl>
{{ forms.render(form['extra_meta_text']) }}
</dl>
{% endif %}
{{ gen.form.close() }}
</div>

Expand Down
7 changes: 7 additions & 0 deletions src/moin/themes/basic/templates/modify.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ <h1>{{ title }}</h1>
<div class="col-md-6">
{{ basic_meta_editor(form['meta_form']) }}
</div>
{% set field = form['extra_meta_text'] %}
<div class="col-md-6">
<div class="form-group">
{{ gen.label(field) }}
{{ gen.textarea(field, rows=field.properties.rows|string, cols=field.properties.cols|string, class='form-control') }}
</div>
</div>
</div>
</div>

Expand Down

0 comments on commit 166bbed

Please sign in to comment.