xiaq avatar xiaq committed a38ad19

Replace ITEMTYPES with information collected in item_registry.

Comments (0)

Files changed (6)


 from MoinMoin.items.content import content_registry
 from MoinMoin import config, user, util
 from MoinMoin.constants.keys import *
-from MoinMoin.constants.itemtypes import ITEMTYPES
 from MoinMoin.util import crypto
 from MoinMoin.util.interwiki import url_for_item
 from MoinMoin.search import SearchForm, ValidSearch


 from __future__ import absolute_import, division
-from collections import namedtuple
-from MoinMoin.i18n import L_
-ItemtypeSpec = namedtuple('ItemtypeSpec', 'itemtype display_name description')
 ITEMTYPE_DEFAULT = u'default'
+ITEMTYPE_USERPROFILE = u'userprofile'
+ITEMTYPE_NONEXISTENT = u'nonexistent'
 ITEMTYPE_TICKET = u'ticket'
 ITEMTYPE_BLOG = u'blog'
 ITEMTYPE_BLOGENTRY = u'blogentry'
-# TODO Perhaps construct this list from the item_registry instead of having it
-# as a constant, which is more extensible (we can have itemtype plugins in
-# future and plugged-in itemtypes will be included too). Two more fields (ie.
-# display name and description) are needed in the registry then to support the
-# automatic construction.
-    ItemtypeSpec(ITEMTYPE_DEFAULT, L_('Default'), L_('Wiki item')),
-    ItemtypeSpec(ITEMTYPE_TICKET, L_('Ticket'), L_('Ticket item')),
-    ItemtypeSpec(ITEMTYPE_BLOG, L_('Blog'), L_('Blog item')),
-    ItemtypeSpec(ITEMTYPE_BLOGENTRY, L_('Blog entry'), L_('Blog entry item')),


 import json
 from StringIO import StringIO
 from collections import namedtuple
+from operator import attrgetter
 from flask import current_app as app
 from flask import g as flaskg
 from MoinMoin.constants.contenttypes import charset
-from MoinMoin.constants.itemtypes import ITEMTYPES
 from .content import content_registry, Content, NonExistentContent, Draw
 class RegistryItem(RegistryBase):
-    class Entry(namedtuple('Entry', 'factory itemtype priority')):
+    class Entry(namedtuple('Entry', 'factory itemtype display_name description order')):
         def __call__(self, itemtype, *args, **kw):
             if self.itemtype == itemtype:
                 return self.factory(*args, **kw)
         def __lt__(self, other):
             if isinstance(other, self.__class__):
-                if self.priority != other.priority:
-                    return self.priority < other.priority
                 return self.itemtype < other.itemtype
             return NotImplemented
-    def register(self, factory, itemtype, priority=RegistryBase.PRIORITY_MIDDLE):
+    def __init__(self):
+        super(RegistryItem, self).__init__()
+        self.shown_entries = []
+    def register(self, e, shown):
         Register a factory
         :param factory: Factory to register. Callable, must return an object.
-        return self._register(self.Entry(factory, itemtype, priority))
+        if shown:
+            self.shown_entries.append(e)
+            self.shown_entries.sort(key=attrgetter('order'))
+        return self._register(e)
 item_registry = RegistryItem()
 def register(cls):
-    item_registry.register(cls._factory, cls.itemtype)
+    item_registry.register(RegistryItem.Entry(cls._factory, cls.itemtype, cls.display_name, cls.description, cls.order), cls.shown)
     return cls
 class Item(object):
     """ Highlevel (not storage) Item, wraps around a storage Revision"""
+    # placeholder values for registry entry properties
+    itemtype = ''
+    display_name = u''
+    description = u''
+    shown = True
+    order = 0
     def _factory(cls, *args, **kw):
         return cls(*args, **kw)
     A "conventional" wiki item.
     itemtype = u'default'
+    display_name = L_('Default')
+    description = L_('Wiki item')
+    order = -10
     def _do_modify_show_templates(self):
         # call this if the item is still empty
     itemtype implementation of userprofile.
     itemtype = u'userprofile'
+    display_name = L_('User profile')
+    description = L_('User profile item (not implemented yet!)')
     undetermined itemtype)
     itemtype = u'nonexistent'
+    shown = False
     def _convert(self, doc):
     def _select_itemtype(self):
         return render_template('modify_select_itemtype.html',
-                               itemtypes=ITEMTYPES,
+                               itemtypes=item_registry.shown_entries,


 class Blog(Default):
     itemtype = ITEMTYPE_BLOG
+    display_name = L_('Blog')
+    description = L_('Blog item')
+    order = 0
     class _ModifyForm(Default._ModifyForm):
         meta_form = BlogMetaForm
 class BlogEntry(Default):
     itemtype = ITEMTYPE_BLOG_ENTRY
+    display_name = L_('Blog entry')
+    description = L_('Blog entry item')
+    order = 0
     class _ModifyForm(Default._ModifyForm):
         meta_form = BlogEntryMetaForm


 class Ticket(Contentful):
     itemtype = ITEMTYPE_TICKET
+    display_name = L_('Ticket')
+    description = L_('Ticket item')
     modify_template = 'ticket.html'
     def do_show(self, revid):


 {{ _("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) }}
 <table class="zebra">
-    {% for it in itemtypes %}
+    {% for e in itemtypes %}
-            <a href="{{ url_for('frontend.modify_item', item_name=item_name, itemtype=it.itemtype) }}">{{ it.display_name }}</a> - {{ it.description }}
+            <a href="{{ url_for('frontend.modify_item', item_name=item_name, itemtype=e.itemtype) }}">{{ e.display_name }}</a> - {{ e.description }}
     {% endfor %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.