changeset 1665:c7cc251e08bd

Automated merge with http://hg.moinmo.in/moin/2.0
author Cheer Xiao <xiaqqaix@gmail.com>
date Sun, 12 Aug 2012 15:32:28 +0800
parents ad8995d32748 (current diff) a11de88b6da1 (diff)
children fa66e4447d63 0104f76e30d0
files MoinMoin/items/__init__.py MoinMoin/templates/modify_select_itemtype.html
diffstat 6 files changed, 107 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sat Aug 11 18:29:13 2012 +0530
+++ b/MoinMoin/apps/frontend/views.py	Sun Aug 12 15:32:28 2012 +0800
@@ -344,7 +344,9 @@
     return partial(add_presenter, view=view, add_trail=add_trail, abort404=abort404)
 
 
-@frontend.route('/<itemname:item_name>', defaults=dict(rev=CURRENT), methods=['GET'])
+# The first form accepts POST to allow modifying behavior like modify_item.
+# The second form only accpets GET since modifying a historical revision is not allowed (yet).
+@frontend.route('/<itemname:item_name>', defaults=dict(rev=CURRENT), methods=['GET', 'POST'])
 @frontend.route('/+show/+<rev>/<itemname:item_name>', methods=['GET'])
 def show_item(item_name, rev):
     flaskg.user.add_trail(item_name)
@@ -354,24 +356,7 @@
         item = Item.create(item_name, rev_id=rev)
     except AccessDenied:
         abort(403)
-    show_revision = rev != CURRENT
-    show_navigation = False # TODO
-    first_rev = last_rev = None # TODO
-    if isinstance(item, NonExistent):
-        status = 404
-    else:
-        status = 200
-    content = render_template('show.html',
-                              item=item, item_name=item.name,
-                              rev=item.rev,
-                              contenttype=item.contenttype,
-                              first_rev_id=first_rev,
-                              last_rev_id=last_rev,
-                              data_rendered=Markup(item.content._render_data()),
-                              show_revision=show_revision,
-                              show_navigation=show_navigation,
-                             )
-    return Response(content, status)
+    return item.do_show(rev)
 
 
 @frontend.route('/+show/<itemname:item_name>')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/converter/_tests/test_registry.py	Sun Aug 12 15:32:28 2012 +0800
@@ -0,0 +1,63 @@
+# Copyright: 2012 MoinMoin:CheerXiao
+# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
+
+"""
+MoinMoin - Tests for MoinMoin.converter.default_registry
+"""
+
+
+import pytest
+
+from MoinMoin.util.mime import Type, type_moin_document, type_moin_wiki
+from MoinMoin.converter import default_registry
+from MoinMoin.converter.text_in import Converter as TextInConverter
+from MoinMoin.converter.moinwiki_in import Converter as MoinwikiInConverter
+from MoinMoin.converter.html_in import Converter as HtmlInConverter
+from MoinMoin.converter.pygments_in import Converter as PygmentsInConverter
+from MoinMoin.converter.everything import Converter as EverythingConverter
+
+from MoinMoin.converter.html_out import ConverterPage as HtmlOutConverterPage
+from MoinMoin.converter.moinwiki_out import Converter as MoinwikiOutConverter
+
+from MoinMoin.converter.highlight import Converter as HighlightConverter
+from MoinMoin.converter.macro import Converter as MacroConverter
+from MoinMoin.converter.include import Converter as IncludeConverter
+from MoinMoin.converter.link import ConverterExternOutput as LinkConverterExternOutput
+from MoinMoin.converter.link import ConverterItemRefs as LinkConverterItemRefs
+
+
+class TestRegistry(object):
+    def testConverterFinder(self):
+        for type_input, type_output, ExpectedClass in [
+                # *_in converters
+                (type_moin_wiki, type_moin_document, MoinwikiInConverter),
+                (Type('x-moin/format;name=wiki'), type_moin_document, MoinwikiInConverter),
+                # pygments_in can handle this too but html_in should have more priority
+                (Type('text/html'), type_moin_document, HtmlInConverter),
+                # fall back to pygments_in
+                (Type('text/html+jinja'), type_moin_document, PygmentsInConverter),
+                # fallback for any random text/* input types
+                (Type('text/blahblah'), type_moin_document, TextInConverter),
+                # fallback for anything
+                (Type('mua/haha'), type_moin_document, EverythingConverter),
+
+                # *_out converters
+                (type_moin_document, Type('application/x-xhtml-moin-page'), HtmlOutConverterPage),
+                (type_moin_document, type_moin_wiki, MoinwikiOutConverter),
+                (type_moin_document, Type('x-moin/format;name=wiki'), MoinwikiOutConverter),
+            ]:
+            conv = default_registry.get(type_input, type_output)
+            assert isinstance(conv, ExpectedClass)
+
+        for kwargs, ExpectedClass in [
+                # DOM converters, which depend on keyword argument to default_registry.get
+                (dict(macros='expandall'), MacroConverter),
+                (dict(includes='expandall'), IncludeConverter),
+                (dict(links='extern'), LinkConverterExternOutput),
+                (dict(items='refs'), LinkConverterItemRefs),
+            ]:
+            conv = default_registry.get(type_moin_document, type_moin_document, **kwargs)
+            assert isinstance(conv, ExpectedClass)
+
+
+coverage_modules = ['MoinMoin.converter']
--- a/MoinMoin/converter/highlight.py	Sat Aug 11 18:29:13 2012 +0530
+++ b/MoinMoin/converter/highlight.py	Sun Aug 12 15:32:28 2012 +0800
@@ -13,10 +13,9 @@
 
 class Converter(object):
     @classmethod
-    def _factory(cls, input, output, **kw):
-        if input == 'application/x.moin.document' and \
-                output == 'application/x.moin.document;highlight=regex':
-            return cls
+    def _factory(cls, input, output, highlight='', re='', **kw):
+        if highlight == 'regex':
+            return cls(re)
 
     def recurse(self, elem):
         new_childs = []
--- a/MoinMoin/items/__init__.py	Sat Aug 11 18:29:13 2012 +0530
+++ b/MoinMoin/items/__init__.py	Sun Aug 12 15:32:28 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, DateTime, 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.
--- a/MoinMoin/templates/modify_select_itemtype.html	Sat Aug 11 18:29:13 2012 +0530
+++ b/MoinMoin/templates/modify_select_itemtype.html	Sun Aug 12 15:32:28 2012 +0800
@@ -1,8 +1,8 @@
 {% extends theme("show.html") %}
 {% block content %}
-<h1>{{ _("Create new item?") }}</h1>
+<h1>{{ _("Item not found, create it now?") }}</h1>
 <p>
-{{ _("This item does not exist (yet), but you can try creating it now. Please select the type of the item you want to create.") }}
+{{ _("Item '%(name)s' does not exist (yet), but you can try creating it now. Please select the type of the item you want to create.", name=item_name) }}
 </p>
 <table class="zebra">
     {% for itname, itlabel, itdesc in itemtypes %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/templates/show_nonexistent.html	Sun Aug 12 15:32:28 2012 +0800
@@ -0,0 +1,7 @@
+{% extends theme("layout.html") %}
+{% block content %}
+<h1>{{ _("Item not found") }}</h1>
+<p>
+{{ _("Item '%(name)s' does not exist.", name=item_name) }}
+</p>
+{% endblock %}