Commits

Thomas Waldmann committed 95d1033

fix show/meta view

  • Participants
  • Parent commits 3183a20
  • Branches storage-ng

Comments (0)

Files changed (5)

File MoinMoin/apps/frontend/views.py

     return redirect(url_for_item(item_name))
 
 
-@frontend.route('/+dom/<int:rev>/<itemname:item_name>')
-@frontend.route('/+dom/<itemname:item_name>', defaults=dict(rev=-1))
+@frontend.route('/+dom/<rev>/<itemname:item_name>')
+@frontend.route('/+dom/<itemname:item_name>', defaults=dict(rev=CURRENT))
 def show_dom(item_name, rev):
     try:
         item = Item.create(item_name, rev_no=rev)
 
 
 # XXX this is just a temporary view to test the indexing converter
-@frontend.route('/+indexable/<int:rev>/<itemname:item_name>')
-@frontend.route('/+indexable/<itemname:item_name>', defaults=dict(rev=-1))
+@frontend.route('/+indexable/<rev>/<itemname:item_name>')
+@frontend.route('/+indexable/<itemname:item_name>', defaults=dict(rev=CURRENT))
 def indexable(item_name, rev):
     from MoinMoin.converter import convert_to_indexable
     item = flaskg.storage.get_item(item_name)
     return Response(content, 200, mimetype='text/plain')
 
 
-@frontend.route('/+highlight/<int:rev>/<itemname:item_name>')
-@frontend.route('/+highlight/<itemname:item_name>', defaults=dict(rev=-1))
+@frontend.route('/+highlight/<rev>/<itemname:item_name>')
+@frontend.route('/+highlight/<itemname:item_name>', defaults=dict(rev=CURRENT))
 def highlight_item(item_name, rev):
     try:
         item = Item.create(item_name, rev_no=rev)
                           )
 
 
-@frontend.route('/+meta/<itemname:item_name>', defaults=dict(rev=-1))
-@frontend.route('/+meta/<int:rev>/<itemname:item_name>')
+@frontend.route('/+meta/<itemname:item_name>', defaults=dict(rev=CURRENT))
+@frontend.route('/+meta/<rev>/<itemname:item_name>')
 def show_item_meta(item_name, rev):
     flaskg.user.addTrail(item_name)
     try:
         item = Item.create(item_name, rev_no=rev)
     except AccessDeniedError:
         abort(403)
-    show_revision = show_navigation = rev >= 0
+    show_revision = show_navigation = rev != CURRENT
     # Note: rev.revno of DummyRev is None
     first_rev = None
     last_rev = None
     if show_navigation:
-        rev_nos = item.rev.item.list_revisions()
+        rev_nos = list(item.rev.item.iter_revs())
         if rev_nos:
             first_rev = rev_nos[0]
             last_rev = rev_nos[-1]
                            show_navigation=show_navigation,
                           )
 
-@frontend.route('/+content/<int:rev>/<itemname:item_name>')
-@frontend.route('/+content/<itemname:item_name>', defaults=dict(rev=-1))
+@frontend.route('/+content/<rev>/<itemname:item_name>')
+@frontend.route('/+content/<itemname:item_name>', defaults=dict(rev=CURRENT))
 def content_item(item_name, rev):
     """ same as show_item, but we only show the content """
     # first check whether we have a valid search query:
                            data_rendered=Markup(item._render_data()),
                            )
 
-@frontend.route('/+get/<int:rev>/<itemname:item_name>')
-@frontend.route('/+get/<itemname:item_name>', defaults=dict(rev=-1))
+@frontend.route('/+get/<rev>/<itemname:item_name>')
+@frontend.route('/+get/<itemname:item_name>', defaults=dict(rev=CURRENT))
 def get_item(item_name, rev):
     try:
         item = Item.create(item_name, rev_no=rev)
         abort(403)
     return item.do_get()
 
-@frontend.route('/+download/<int:rev>/<itemname:item_name>')
-@frontend.route('/+download/<itemname:item_name>', defaults=dict(rev=-1))
+@frontend.route('/+download/<rev>/<itemname:item_name>')
+@frontend.route('/+download/<itemname:item_name>', defaults=dict(rev=CURRENT))
 def download_item(item_name, rev):
     try:
         item = Item.create(item_name, rev_no=rev)
     submit = String.using(default=L_('Filter'), optional=True)
 
 
-@frontend.route('/+revert/<int:rev>/<itemname:item_name>', methods=['GET', 'POST'])
+@frontend.route('/+revert/<rev>/<itemname:item_name>', methods=['GET', 'POST'])
 def revert_item(item_name, rev):
     try:
         item = Item.create(item_name, rev_no=rev)
     return redirect(url_for('.modify_item', item_name=newitem))
 
 
-@frontend.route('/+destroy/<int:rev>/<itemname:item_name>', methods=['GET', 'POST'])
+@frontend.route('/+destroy/<rev>/<itemname:item_name>', methods=['GET', 'POST'])
 @frontend.route('/+destroy/<itemname:item_name>', methods=['GET', 'POST'], defaults=dict(rev=None))
 def destroy_item(item_name, rev):
     if rev is None:

File MoinMoin/converter/_util.py

     read and decode data, return unicode text
 
     supported types for data:
-    - rev object or other file-like object
+    - rev object
     - str
     - unicode
 
     file-like objects and str need to be either utf-8 (or ascii, which is a subset of utf-8)
     encoded or contenttype (including a charset parameter) needs to be given.
     """
-    if hasattr(data, 'read'):
-        # file-like object
-        data = data.read()
+    if not isinstance(data, (str, unicode)):
+        data = data.data.read()
     if isinstance(data, str):
         coding = 'utf-8'
         if contenttype is not None:
             coding = ct.parameters.get('charset', coding)
         data = data.decode(coding)
     if not isinstance(data, unicode):
-        raise TypeError("data must be file-like or str (requires contenttype with charset) or unicode, but we got %r" % data)
+        raise TypeError("data must be rev or str (requires contenttype with charset) or unicode, but we got %r" % data)
     return data
 
 

File MoinMoin/items/__init__.py

         self.item = item
         self.meta = {CONTENTTYPE: contenttype}
         self.data = StringIO('')
+        self.revid = ''
 
 
 class DummyItem(object):
             # make sure we have CONTENTTYPE
             meta[CONTENTTYPE] = unicode(contenttype_current or contenttype_guessed or 'application/octet-stream')
 
+        if MTIME not in meta:
+            meta[MTIME] = int(time.time())
+
         meta[ACTION] = unicode(action)
 
         if not overwrite and REVID in meta:
             form = ModifyForm.from_defaults()
             TextCha(form).amend_form()
             form['meta_text'] = self.meta_dict_to_text(self.meta)
-            form['rev'] = self.rev.revno if self.rev.revno is not None else CURRENT
+            form['rev'] = self.rev.revid if self.rev.revid is not None else CURRENT
         elif request.method == 'POST':
             form = ModifyForm.from_flat(request.form.items() + request.files.items())
             TextCha(form).amend_form()
         if PIL is None:
             # no PIL, we can't do anything, we just call the base class method
             return super(TransformableBitmapImage, self)._render_data_diff(oldrev, newrev)
-        url = url_for('frontend.diffraw', item_name=self.name, rev1=oldrev.revno, rev2=newrev.revno)
+        url = url_for('frontend.diffraw', item_name=self.name, rev1=oldrev.revid, rev2=newrev.revid)
         return Markup('<img src="%s" />' % escape(url))
 
     def _render_data_diff_raw(self, oldrev, newrev):
         #    return self._do_modify_show_templates()
         from MoinMoin.apps.frontend.views import CommentForm
         class ModifyForm(CommentForm):
-            rev = Integer.using(optional=False)
+            rev = 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:'))
             else:
                 form['data_text'] = self.data_storage_to_internal(self.data)
             form['meta_text'] = self.meta_dict_to_text(self.meta)
-            form['rev'] = self.rev.revno if self.rev.revno is not None else CURRENT
+            if self.rev.revid:
+                form['rev'] = self.rev.revid
         elif request.method == 'POST':
             form = ModifyForm.from_flat(request.form.items() + request.files.items())
             TextCha(form).amend_form()
             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)
-            form['rev'] = self.rev.revno if self.rev.revno is not None else CURRENT
+            form['rev'] = self.rev.revid if self.rev.revid is not None else CURRENT
         elif request.method == 'POST':
             # this POST comes directly from TWikiDraw (not from Browser), thus no validation
             try:
             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)
-            form['rev'] = self.rev.revno if self.rev.revno is not None else CURRENT
+            form['rev'] = self.rev.revid if self.rev.revid is not None else CURRENT
         elif request.method == 'POST':
             # this POST comes directly from AnyWikiDraw (not from Browser), thus no validation
             try:
             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)
-            form['rev'] = self.rev.revno if self.rev.revno is not None else CURRENT
+            form['rev'] = self.rev.revid if self.rev.revid is not None else CURRENT
         elif request.method == 'POST':
             # this POST comes directly from SvgDraw (not from Browser), thus no validation
             try:

File MoinMoin/templates/show.html

         {% endblock %}
     {% endif %}
     
-    {% if not rev %}
-    {{ _("This item exists, but it has no revisions.") }}
-    {% else %}
     {% block headline %}
     {# <h1>{{ rev.item.name }} {% if show_revision %}(Revision {{ rev.revno }}){% endif %}</h1> #}
     {% endblock %}
     </div>
     {% endif %}
     {% endblock %}
-    {% endif %}
 {% endblock %}
 
 {% block footer_hr %}{% endblock %}
     {% if rev %}
     <p id="moin-pageinfo" lang="{{ theme_supp.ui_lang }}" dir="{{ theme_supp.ui_dir }}">
         {% if cfg.show_interwiki %}{{ cfg.interwikiname }}:{% endif %}{{ item_name }} (rev {{rev.revno}}),
-        {{ _("modified") }} {{ rev.timestamp|datetimeformat }}
+        {{ _("modified") }} {{ rev.meta['mtime']|datetimeformat }}
         {{ _("by") }} {{ utils.editor_info(rev) }}{% if rev.tags %},
         {{ _("tagged") }}
         {% for tag in rev.tags -%}

File MoinMoin/themes/__init__.py

 
 
 def get_editor_info(rev, external=False):
-    addr = rev.get(ADDRESS)
-    hostname = rev.get(HOSTNAME)
+    addr = rev.meta.get(ADDRESS)
+    hostname = rev.meta.get(HOSTNAME)
     text = _('anonymous')  # link text
     title = ''  # link title
     css = 'editor'  # link/span css class
             title = '[%s]' % (addr, )
             css = 'editor ip'
 
-    userid = rev.get(USERID)
+    userid = rev.meta.get(USERID)
     if userid:
         u = user.User(userid)
         name = u.name