Commits

Thomas Waldmann  committed 79f80ce

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).

  • Participants
  • Parent commits d90782a
  • Branches storage-ng

Comments (0)

Files changed (5)

File MoinMoin/apps/feed/views.py

             name = rev.meta[NAME]
             item = rev.item
             this_revno = rev.meta[REVID]
-            previous_revno = None # XXX TODO we need PARENT for this
+            previous_revno = rev.meta.get(PARENTID)
             this_rev = rev
             try:
                 hl_item = Item.create(name, rev_no=this_revno)

File MoinMoin/config/__init__.py

 NAME_EXACT = "name_exact"
 ITEMID = "itemid"
 REVID = "revid"
+PARENTID = "parentid"
 DATAID = "dataid"
 WIKINAME = "wikiname"
 CONTENT = "content"

File MoinMoin/items/__init__.py

                             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
             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)
         #    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()
         #    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:'))
                 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()
         #    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:'))
             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:
         #    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:'))
             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:
         #    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:'))
             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:

File MoinMoin/storage/middleware/indexing.py

 from MoinMoin.config import WIKINAME, NAME, NAME_EXACT, MTIME, CONTENTTYPE, TAGS, \
                             LANGUAGE, USERID, ADDRESS, HOSTNAME, SIZE, ACTION, COMMENT, \
                             CONTENT, ITEMLINKS, ITEMTRANSCLUSIONS, ACL, EMAIL, OPENID, \
-                            ITEMID, REVID, CURRENT
+                            ITEMID, REVID, CURRENT, PARENTID
 
 from MoinMoin.search.analyzers import item_name_analyzer, MimeTokenizer, AclTokenizer
 from MoinMoin.util.crypto import make_uuid
             NAME_EXACT: ID(field_boost=3.0),
             # revision id (aka meta id)
             REVID: ID(unique=True, stored=True),
+            # parent revision id
+            PARENTID: ID(stored=True),
             # MTIME from revision metadata (converted to UTC datetime)
             MTIME: DATETIME(stored=True),
             # tokenized CONTENTTYPE from metadata

File MoinMoin/templates/modify_applet.html

 <div class="moin-form">
 {{ gen.form.open(form, method='post', action='', enctype='multipart/form-data') }}
 {{ forms.render_errors(form) }}
-{{ gen.input(form['parent'], type='hidden') }}
 {% block extra_form %}{% endblock %}
 {% block data_editor %}{% endblock %}
 {{ forms.render_field(gen, form['data_file'], 'file') }}