diff MoinMoin/items/__init__.py @ 1662:465b22852fae

Let Item subclasses handle +show.
author Cheer Xiao <xiaqqaix@gmail.com>
date Sun, 12 Aug 2012 15:14:07 +0800
parents 07b2146ba96f
children c7cc251e08bd
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Thu Aug 09 22:54:37 2012 +0800
+++ b/MoinMoin/items/__init__.py	Sun Aug 12 15:14:07 2012 +0800
@@ -27,6 +27,8 @@
 from flatland import Form
 from flatland.validation import Validator
 
+from jinja2 import Markup
+
 from whoosh.query import Term, And, Prefix
 
 from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags, Submit
@@ -562,6 +564,21 @@
                                data_rendered='',
                                )
 
+    def do_show(self, revid):
+        show_revision = revid != CURRENT
+        show_navigation = False # TODO
+        first_rev = last_rev = None # TODO
+        return render_template(self.show_template,
+                               item=self, item_name=self.name,
+                               rev=self.rev,
+                               contenttype=self.contenttype,
+                               first_rev_id=first_rev,
+                               last_rev_id=last_rev,
+                               data_rendered=Markup(self.content._render_data()),
+                               show_revision=show_revision,
+                               show_navigation=show_navigation,
+                              )
+
     def do_modify(self):
         method = request.method
         if method == 'GET':
@@ -607,6 +624,7 @@
                                search_form=None,
                               )
 
+    show_template = 'show.html'
     modify_template = 'modify.html'
 
 
@@ -638,11 +656,21 @@
     def _convert(self, doc):
         abort(404)
 
+    def do_show(self, revid):
+        # First, check if the current user has the required privileges
+        if not flaskg.user.may.create(self.name):
+            return render_template('show_nonexistent.html',
+                                   item_name=self.name,
+                                  )
+        return Response(self._select_itemtype(), 404)
+
     def do_modify(self):
         # First, check if the current user has the required privileges
         if not flaskg.user.may.create(self.name):
             abort(403)
+        return self._select_itemtype()
 
+    def _select_itemtype(self):
         # TODO Construct this list from the item_registry. Two more fields (ie.
         # display name and description) are needed in the registry then to
         # support the automatic construction.