changeset 859:95d1033b7808 storage-ng

fix show/meta view
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 25 Sep 2011 00:41:38 +0200
parents 3183a202d916
children de6ece090b7d
files MoinMoin/apps/frontend/views.py MoinMoin/converter/_util.py MoinMoin/items/__init__.py MoinMoin/templates/show.html MoinMoin/themes/__init__.py
diffstat 5 files changed, 38 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sat Sep 24 18:52:46 2011 +0200
+++ b/MoinMoin/apps/frontend/views.py	Sun Sep 25 00:41:38 2011 +0200
@@ -231,8 +231,8 @@
     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)
@@ -249,8 +249,8 @@
 
 
 # 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)
@@ -259,8 +259,8 @@
     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)
@@ -272,20 +272,20 @@
                           )
 
 
-@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]
@@ -300,8 +300,8 @@
                            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:
@@ -320,8 +320,8 @@
                            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)
@@ -329,8 +329,8 @@
         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)
@@ -419,7 +419,7 @@
     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)
@@ -573,7 +573,7 @@
     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:
--- a/MoinMoin/converter/_util.py	Sat Sep 24 18:52:46 2011 +0200
+++ b/MoinMoin/converter/_util.py	Sun Sep 25 00:41:38 2011 +0200
@@ -16,16 +16,15 @@
     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:
@@ -33,7 +32,7 @@
             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
 
 
--- a/MoinMoin/items/__init__.py	Sat Sep 24 18:52:46 2011 +0200
+++ b/MoinMoin/items/__init__.py	Sun Sep 25 00:41:38 2011 +0200
@@ -149,6 +149,7 @@
         self.item = item
         self.meta = {CONTENTTYPE: contenttype}
         self.data = StringIO('')
+        self.revid = ''
 
 
 class DummyItem(object):
@@ -476,6 +477,9 @@
             # 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:
@@ -671,7 +675,7 @@
             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()
@@ -1008,7 +1012,7 @@
         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):
@@ -1122,7 +1126,7 @@
         #    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:'))
@@ -1138,7 +1142,8 @@
             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()
@@ -1300,7 +1305,7 @@
             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:
@@ -1392,7 +1397,7 @@
             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:
@@ -1480,7 +1485,7 @@
             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:
--- a/MoinMoin/templates/show.html	Sat Sep 24 18:52:46 2011 +0200
+++ b/MoinMoin/templates/show.html	Sun Sep 25 00:41:38 2011 +0200
@@ -43,9 +43,6 @@
         {% 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 %}
@@ -56,7 +53,6 @@
     </div>
     {% endif %}
     {% endblock %}
-    {% endif %}
 {% endblock %}
 
 {% block footer_hr %}{% endblock %}
@@ -69,7 +65,7 @@
     {% 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 -%}
--- a/MoinMoin/themes/__init__.py	Sat Sep 24 18:52:46 2011 +0200
+++ b/MoinMoin/themes/__init__.py	Sun Sep 25 00:41:38 2011 +0200
@@ -271,8 +271,8 @@
 
 
 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
@@ -290,7 +290,7 @@
             title = '[%s]' % (addr, )
             css = 'editor ip'
 
-    userid = rev.get(USERID)
+    userid = rev.meta.get(USERID)
     if userid:
         u = user.User(userid)
         name = u.name