diff MoinMoin/items/__init__.py @ 892:79f80ce3cf78 storage-ng

implement parents (key PARENTID), add it to index schema use it for the atom feed (to generate diffs to previous rev). when preparing the metadata to fill into the editor, put the current revid in there as parent (do not use the hidden form field any more).
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 26 Sep 2011 18:49:49 +0200
parents d90782ad8b24
children 7a01ee71dc4c
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Mon Sep 26 17:51:13 2011 +0200
+++ b/MoinMoin/items/__init__.py	Mon Sep 26 18:49:49 2011 +0200
@@ -73,7 +73,7 @@
                             CONTENTTYPE, SIZE, LANGUAGE, ITEMLINKS, ITEMTRANSCLUSIONS, \
                             TAGS, ACTION, ADDRESS, HOSTNAME, USERID, EXTRA, COMMENT, \
                             HASH_ALGORITHM, CONTENTTYPE_GROUPS, ITEMID, REVID, DATAID, \
-                            CURRENT
+                            CURRENT, PARENTID
 
 COLS = 80
 ROWS_DATA = 20
@@ -345,6 +345,17 @@
             meta = self.meta_filter(meta)
         return json.dumps(meta, sort_keys=True, indent=2, ensure_ascii=False)
 
+    def prepare_meta_for_modify(self, meta):
+        """
+        transform the meta dict of the current revision into a meta dict
+        that can be used for savind next revision (after "modify").
+        """
+        meta = dict(meta)
+        revid = meta.pop(REVID, None)
+        if revid is not None:
+            meta[PARENTID] = revid
+        return meta
+
     def get_data(self):
         return '' # TODO create a better method for binary stuff
     data = property(fget=get_data)
@@ -673,16 +684,13 @@
         #    return self._do_modify_show_templates()
         from MoinMoin.apps.frontend.views import CommentForm
         class ModifyForm(CommentForm):
-            parent = String.using(optional=True)
             meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)")).validated_by(ValidJSON())
             data_file = FileStorage.using(optional=True, label=L_('Upload file:'))
 
         if request.method == 'GET':
             form = ModifyForm.from_defaults()
             TextCha(form).amend_form()
-            form['meta_text'] = self.meta_dict_to_text(self.meta)
-            if self.rev.revid:
-                form['parent'] = self.rev.revid
+            form['meta_text'] = self.meta_dict_to_text(self.prepare_meta_for_modify(self.meta))
         elif request.method == 'POST':
             form = ModifyForm.from_flat(request.form.items() + request.files.items())
             TextCha(form).amend_form()
@@ -1133,7 +1141,6 @@
         #    return self._do_modify_show_templates()
         from MoinMoin.apps.frontend.views import CommentForm
         class ModifyForm(CommentForm):
-            parent = String.using(optional=True)
             meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)")).validated_by(ValidJSON())
             data_text = String.using(optional=True).with_properties(placeholder=L_("Type your text here"))
             data_file = FileStorage.using(optional=True, label=L_('Upload file:'))
@@ -1148,9 +1155,7 @@
                 form['data_text'] = self.data_storage_to_internal(item.data)
             else:
                 form['data_text'] = self.data_storage_to_internal(self.data)
-            form['meta_text'] = self.meta_dict_to_text(self.meta)
-            if self.rev.revid:
-                form['parent'] = self.rev.revid
+            form['meta_text'] = self.meta_dict_to_text(self.prepare_meta_for_modify(self.meta))
         elif request.method == 'POST':
             form = ModifyForm.from_flat(request.form.items() + request.files.items())
             TextCha(form).amend_form()
@@ -1302,7 +1307,6 @@
         #    return self._do_modify_show_templates()
         from MoinMoin.apps.frontend.views import CommentForm
         class ModifyForm(CommentForm):
-            parent = String.using(optional=True)
             # XXX as the "saving" POSTs come from TWikiDraw (not the form), editing meta_text doesn't work
             meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)")).validated_by(ValidJSON())
             data_file = FileStorage.using(optional=True, label=L_('Upload file:'))
@@ -1311,9 +1315,7 @@
             form = ModifyForm.from_defaults()
             TextCha(form).amend_form()
             # XXX currently this is rather pointless, as the form does not get POSTed:
-            form['meta_text'] = self.meta_dict_to_text(self.meta)
-            if self.rev.revid:
-                form['parent'] = self.rev.revid
+            form['meta_text'] = self.meta_dict_to_text(self.prepare_meta_for_modify(self.meta))
         elif request.method == 'POST':
             # this POST comes directly from TWikiDraw (not from Browser), thus no validation
             try:
@@ -1395,7 +1397,6 @@
         #    return self._do_modify_show_templates()
         from MoinMoin.apps.frontend.views import CommentForm
         class ModifyForm(CommentForm):
-            parent = String.using(optional=True)
             # XXX as the "saving" POSTs come from AnyWikiDraw (not the form), editing meta_text doesn't work
             meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)")).validated_by(ValidJSON())
             data_file = FileStorage.using(optional=True, label=L_('Upload file:'))
@@ -1404,9 +1405,7 @@
             form = ModifyForm.from_defaults()
             TextCha(form).amend_form()
             # XXX currently this is rather pointless, as the form does not get POSTed:
-            form['meta_text'] = self.meta_dict_to_text(self.meta)
-            if self.rev.revid:
-                form['parent'] = self.rev.revid
+            form['meta_text'] = self.meta_dict_to_text(self.prepare_meta_for_modify(self.meta))
         elif request.method == 'POST':
             # this POST comes directly from AnyWikiDraw (not from Browser), thus no validation
             try:
@@ -1484,7 +1483,6 @@
         #    return self._do_modify_show_templates()
         from MoinMoin.apps.frontend.views import CommentForm
         class ModifyForm(CommentForm):
-            parent = String.using(optional=True)
             # XXX as the "saving" POSTs come from SvgDraw (not the form), editing meta_text doesn't work
             meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)")).validated_by(ValidJSON())
             data_file = FileStorage.using(optional=True, label=L_('Upload file:'))
@@ -1493,9 +1491,7 @@
             form = ModifyForm.from_defaults()
             TextCha(form).amend_form()
             # XXX currently this is rather pointless, as the form does not get POSTed:
-            form['meta_text'] = self.meta_dict_to_text(self.meta)
-            if self.rev.revid:
-                form['parent'] = self.rev.revid
+            form['meta_text'] = self.meta_dict_to_text(self.prepare_meta_for_modify(self.meta))
         elif request.method == 'POST':
             # this POST comes directly from SvgDraw (not from Browser), thus no validation
             try: