xiaq avatar xiaq committed 3863288 Draft

Make RegistryContent.register accept an Entry and group name for slightly cleaner code.

Comments (0)

Files changed (1)

MoinMoin/items/content.py

         self.group_names = group_names
         self.groups = dict([(g, []) for g in group_names])
 
-    def register(self, factory, contenttype, default_contenttype_params, display_name, group, ingroup_order, priority=RegistryBase.PRIORITY_MIDDLE):
+    def register(self, e, group):
         """
-        Register a factory
-
-        :param factory: Factory to register. Callable, must return an object.
+        Register a contenttype entry and optionally add it to a specific group.
         """
-        e = self.Entry(factory, contenttype, default_contenttype_params, display_name, ingroup_order, priority)
         # If group is specified and contenttype is not a wildcard one
-        if group and contenttype.type and contenttype.subtype:
+        if group and e.content_type.type and e.content_type.subtype:
             if group not in self.groups:
                 raise ValueError('Unknown group name: {0}'.format(group))
             self.groups[group].append(e)
 ])
 
 def register(cls):
-    content_registry.register(cls._factory, Type(cls.contenttype), cls.default_contenttype_params, cls.display_name, cls.group, cls.ingroup_order)
+    content_registry.register(RegistryContent.Entry(cls._factory, Type(cls.contenttype), cls.default_contenttype_params, cls.display_name, cls.ingroup_order, RegistryContent.PRIORITY_MIDDLE), cls.group)
     return cls
 
 
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.