changeset 1624:c6974ba2e2b2

Widget-based metadata editor.
author Cheer Xiao <xiaqqaix@gmail.com>
date Wed, 01 Aug 2012 23:31:14 +0800
parents e872cb536c26
children 6748d609a242
files MoinMoin/items/__init__.py MoinMoin/templates/modify.html MoinMoin/templates/modify_meta.html
diffstat 3 files changed, 39 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Wed Aug 01 00:22:42 2012 +0800
+++ b/MoinMoin/items/__init__.py	Wed Aug 01 23:31:14 2012 +0800
@@ -132,6 +132,14 @@
     submit = Submit
 
 
+class BaseMetaForm(Form):
+    wikiname = OptionalText.using(label=L_("Wiki name")).with_properties(placeholder=L_("Wiki name"))
+    itemtype = RequiredText.using(label=L_("Item type")).with_properties(placeholder=L_("Item type"))
+    contenttype = RequiredText.using(label=L_("Content type")).with_properties(placeholder=L_("Content type"))
+    acl = OptionalText.using(label=L_('ACL')).with_properties(placeholder=L_("Access Control List"))
+    summary = OptionalText.using(label=L_("Summary")).with_properties(placeholder=L_("One-line summary of the item"))
+    tags = Tags
+
 class Item(object):
     """ Highlevel (not storage) Item, wraps around a storage Revision"""
     @classmethod
@@ -308,14 +316,22 @@
 
     class _ModifyForm(BaseChangeForm):
         """Base class for ModifyForm of Item subclasses."""
-        meta_text = OptionalMultilineText.using(label=L_("MetaData (JSON)")).with_properties(rows=ROWS_META, cols=COLS).validated_by(ValidJSON())
+        meta_form = BaseMetaForm
+        extra_meta_text = OptionalMultilineText.using(label=L_("Extra MetaData (JSON)")).with_properties(rows=ROWS_META, cols=COLS).validated_by(ValidJSON())
+        meta_template = 'modify_meta.html'
 
         def _load(self, item):
-            self['meta_text'] = item.meta_dict_to_text(item.prepare_meta_for_modify(item.meta))
+            meta = item.prepare_meta_for_modify(item.meta)
+            self['meta_form'].set(meta, 'duck')
+            for k in self['meta_form'].field_schema_mapping.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):
-            meta = item.meta_text_to_dict(self['meta_text'].value)
+            meta = self['meta_form'].value.copy()
+            meta['tags'] = list(self['meta_form']['tags'])
+            meta.update(item.meta_text_to_dict(self['extra_meta_text'].value))
             data, contenttype_guessed = self['content_form']._dump(item.content)
             comment = self['comment'].value
             return meta, data, contenttype_guessed, comment
--- a/MoinMoin/templates/modify.html	Wed Aug 01 00:22:42 2012 +0800
+++ b/MoinMoin/templates/modify.html	Wed Aug 01 23:31:14 2012 +0800
@@ -2,6 +2,7 @@
 {% import "utils.html" as utils %}
 {% extends theme("layout.html") %}
 
+{% from form.meta_template import meta_editor %}
 {# Import macros data_editor and extra_head from content_form's template.
    extra_head is optional, so instead of a simple "import from" we need to do
    this manually #}
@@ -52,8 +53,9 @@
     {% if form['content_form'].help %}
         <pre id="moin-editor-help">{{ form['content_form'].help }}</pre>
     {% endif %}
+    {{ meta_editor(form['meta_form']) }}
     <dl>
-        {{ forms.render(form['meta_text']) }}
+        {{ forms.render(form['extra_meta_text']) }}
     </dl>
     {#
     {{ gen.textarea(form['meta_text'], lang='en', dir='ltr', rows=rows_meta, cols=cols) }}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/templates/modify_meta.html	Wed Aug 01 23:31:14 2012 +0800
@@ -0,0 +1,17 @@
+{% import "forms.html" as forms %}
+
+{% macro meta_editor(form) %}
+    <h2>General meta</h2>
+    <dl>
+        {% for e in [
+            'wikiname',
+            'itemtype',
+            'contenttype',
+            'acl',
+            'summary',
+            'tags',
+            ] %}
+            {{ forms.render(form[e]) }}
+        {% endfor %}
+    </dl>
+{% endmacro %}