示例#1
0
class PermissionGrokker(martian.ClassGrokker):
    martian.component(grokcore.security.Permission)
    martian.priority(1500)
    martian.directive(grokcore.component.name)
    martian.directive(grokcore.component.title,
                      get_default=default_fallback_to_name)
    martian.directive(grokcore.component.description)

    def execute(self, factory, config, name, title, description, **kw):
        if not name:
            raise GrokError(
                "A permission needs to have a dotted name for its id. Use "
                "grok.name to specify one.", factory)
        # We can safely convert to unicode, since the directives make sure
        # it is either unicode already or ASCII.
        permission = factory(unicode(name), unicode(title),
                             unicode(description))

        config.action(
            discriminator=('utility', IPermission, name),
            callable=grokcore.component.provideUtility,
            args=(permission, IPermission, name),
            order=-1  # need to do this early in the process
        )
        return True
示例#2
0
文件: meta.py 项目: kkdhanesh/NBADEMO
class SiteGrokker(martian.ClassGrokker):
    """Grokker for subclasses of `grokcore.site.Site`."""
    martian.component(grokcore.site.components.BaseSite)
    martian.priority(500)
    martian.directive(grokcore.site.local_utility, name='infos')

    def execute(self, factory, config, infos, **kw):
        if not infos:
            return False

        infos = infos.values()
        for info in infos:
            if info.public and not IContainer.implementedBy(factory):
                raise GrokError(
                    "Cannot set public to True with grok.local_utility as "
                    "the site (%r) is not a container." % factory, factory)

        # Store the list of info objects in their "natural" order on the
        # site class. They will be picked up by a subscriber doing the
        # actual registrations in definition order.
        factory.__grok_utilities_to_install__ = sorted(infos)
        adapts = (factory, IObjectAddedEvent)

        config.action(
            discriminator=None,
            callable=grokcore.component.provideHandler,
            args=(localUtilityRegistrationSubscriber, adapts),
        )
        return True
示例#3
0
class AlphaGrokker(martian.ClassGrokker):
    martian.component(Alpha)
    martian.priority(1)  # we need to go before BetaGrokker

    def grok(self, name, factory, module_info, config, **kw):
        print "alpha"
        return True
示例#4
0
class BetaGrokker(martian.ClassGrokker):
    martian.component(Beta)
    martian.priority(1)

    def grok(self, name, factory, module_info, **kw):
        print("beta")
        return True
示例#5
0
class GammaGrokker(martian.ClassGrokker):
    martian.component(Gamma)
    martian.priority(-1)

    def grok(self, name, factory, module_info, **kw):
        print("gamma")
        return True
示例#6
0
class ClassImplementerGrokker(martian.ClassGrokker):
    martian.component(object)
    martian.directive(grokcore.component.implements)
    martian.priority(2000)

    def execute(self, class_, implements, **kw):
        if implements is None:
            return True
        classImplements(class_, implements)
        return True
示例#7
0
文件: meta.py 项目: kkdhanesh/NBADEMO
    class FormGrokker(martian.ClassGrokker):
        martian.component(components.GrokForm)
        martian.directive(grokcore.component.context)
        martian.priority(800)  # Must be run before real formlib grokker.

        def execute(self, factory, config, context, **kw):
            # Set up form_fields from context class if they haven't been
            # configured manually already using our version of get_auto_fields
            if getattr(factory, 'form_fields', None) is None:
                factory.form_fields = formlib.get_auto_fields(context)
            return True
示例#8
0
class FilesystemPageTemplateGrokker(martian.GlobalGrokker):
    # Do this early on, but after ModulePageTemplateGrokker, as
    # findFilesystem depends on module-level templates to be already
    # grokked for error reporting.
    martian.priority(999)

    def grok(self, name, module, module_info, config, **kw):
        # We set the configuration action order to 0, to be sure to
        # register templates first.
        config.action(discriminator=None,
                      callable=templatereg.register_directory,
                      args=(module_info, ),
                      order=0)
        return True
示例#9
0
文件: meta.py 项目: kkdhanesh/NBADEMO
class ApplicationGrokker(martian.ClassGrokker):
    """Grokker for Grok application classes."""
    martian.component(grokcore.site.components.Application)
    martian.priority(500)

    def grok(self, name, factory, module_info, config, **kw):
        # XXX fail loudly if the same application name is used twice.
        provides = grokcore.site.interfaces.IApplication
        name = '%s.%s' % (module_info.dotted_name, name)
        config.action(
            discriminator=('utility', provides, name),
            callable=grokcore.component.provideUtility,
            args=(factory, provides, name),
        )
        return True
示例#10
0
class UnassociatedTemplatesGrokker(martian.GlobalGrokker):
    martian.priority(-1001)
    # XXX: The action should be registered only once, not for each module.
    # There should be a way to register the action without a module grokker...
    _action_registered = False

    def grok(self, name, module, module_info, config, **kw):
        if not self._action_registered:
            self._action_registered = True
            # We set the configuration action order to very very high
            # to be sure to check unused template at the end only.
            config.action(discriminator=None,
                          callable=templatereg.check_unassociated,
                          args=(),
                          order=sys.maxint)
        return True
示例#11
0
class ModulePageTemplateGrokker(martian.InstanceGrokker):
    martian.component(components.BaseTemplate)
    # this needs to happen before any other grokkers execute that actually
    # use the templates
    martian.priority(1000)

    def grok(self, name, instance, module_info, config, **kw):
        # We set the configuration action order to 0, to be sure to
        # register templates first.
        config.action(discriminator=None,
                      callable=templatereg.register_inline_template,
                      args=(module_info, name, instance),
                      order=0)
        config.action(discriminator=None,
                      callable=instance._annotateGrokInfo,
                      args=(name, module_info.dotted_name))
        return True
示例#12
0
class UnassociatedTemplatesGrokker(martian.GlobalGrokker):
    martian.priority(-1001)
    # XXX: The action should be registered only once, not for each module.
    # There should be a way to register the action without a module grokker...
    _action_registered = os.environ.get('GROK_DISABLE_TEMPLATE_WARNING',
                                        'no').lower() in ('yes', 'on', 'true')

    def grok(self, name, module, module_info, config, **kw):
        if not self._action_registered:
            self._action_registered = True
            # We set the configuration action order to very very high
            # to be sure to check unused template at the end only.
            config.action(discriminator=None,
                          callable=templatereg.check_unassociated,
                          args=(),
                          order=sys.maxsize)
        return True
示例#13
0
    class RoleGrokker(martian.ClassGrokker):
        """Grokker for components subclassed from `grok.Role`.

        Each role is registered as a global utility providing the service
        `IRole` under its own particular name, and then granted every
        permission named in its `grok.permission()` directive.

        """
        martian.component(Role)
        martian.priority(martian.priority.bind().get(PermissionGrokker()) - 1)
        martian.directive(grokcore.component.name)
        martian.directive(grokcore.component.title,
                          get_default=default_fallback_to_name)
        martian.directive(grokcore.component.description)
        martian.directive(permissions)

        def execute(self, factory, config, name, title, description,
                    permissions, **kw):
            if not name:
                raise GrokError(
                    "A role needs to have a dotted name for its id. Use "
                    "grok.name to specify one.", factory)
            # We can safely convert to unicode, since the directives makes sure
            # it is either unicode already or ASCII.
            if not isinstance(title, Message):
                title = unicode(title)
            if not isinstance(description, Message):
                description = unicode(description)
            role = factory(unicode(name), title, description)

            config.action(
                discriminator=('utility', IRole, name),
                callable=grokcore.component.provideUtility,
                args=(role, IRole, name),
            )

            for permission in permissions:
                config.action(
                    discriminator=('grantPermissionToRole', permission, name),
                    callable=rolePermissionManager.grantPermissionToRole,
                    args=(permission, name),
                )
            return True
示例#14
0
class GlobalUtilityGrokker(martian.ClassGrokker):
    martian.component(grokcore.component.GlobalUtility)

    # This needs to happen before the FilesystemPageTemplateGrokker grokker
    # happens, since it relies on the ITemplateFileFactories being grokked.
    martian.priority(1100)

    martian.directive(grokcore.component.direct)
    martian.directive(grokcore.component.provides,
                      get_default=default_global_utility_provides)
    martian.directive(grokcore.component.name)

    def execute(self, factory, config, direct, provides, name, **kw):
        if not direct:
            factory = factory()

        config.action(
            discriminator=('utility', provides, name),
            callable=grokcore.component.provideUtility,
            args=(factory, provides, name),
        )
        return True
示例#15
0
class MenuViewGrokker(ViewGrokker):
    _dynamic_items = 0
    martian.priority(-1)
    martian.component(View)
    martian.directive(directives.menuitem, name='menus', default={})
    martian.directive(directives.sitemenuitem, name='sitemenus', default={})
    martian.directive(grokcore.viewlet.context)
    martian.directive(grokcore.viewlet.layer, default=IDefaultBrowserLayer)
    martian.directive(grokcore.viewlet.require, name='permission')
    martian.directive(grokcore.viewlet.name, get_default=default_view_name)
    martian.directive(grokcore.component.title, name='viewtitle')
    martian.directive(grokcore.component.description)

    def execute(self, factory, config, menus, sitemenus, context, layer, name,
                viewtitle, permission, description, **kw):
        for sitemenu, (title, order, icon, group) in sitemenus.items():
            title = title or viewtitle or name
            if martian.util.check_subclass(permission,
                                           grokcore.security.Permission):
                permission = grokcore.component.name.bind().get(permission)
            item_name = name
            item_itf = directives.itemsimplement.bind().get(sitemenu)
            config.action(discriminator=('viewlet', None, layer, IBrowserView,
                                         sitemenu, item_name),
                          callable=registerMenuItem,
                          args=(
                              factory.module_info,
                              components.SiteMenuItem,
                              (None, layer, IBrowserView, sitemenu),
                              item_name,
                              permission,
                              item_itf,
                              layer,
                              {
                                  'title': title,
                                  'viewName': name,
                                  'description': description,
                                  '_icon': icon,
                                  'group': group
                              },
                              (order, MenuViewGrokker._dynamic_items),
                          ))
            MenuViewGrokker._dynamic_items += 1
        for menu, (title, order, icon, group) in menus.items():
            title = title or viewtitle or name
            if martian.util.check_subclass(permission,
                                           grokcore.security.Permission):
                permission = grokcore.component.name.bind().get(permission)
            if isinstance(context, InterfaceClass):
                item_name = "%s_%s" % (context.getName(), name)
            else:
                item_name = "%s_%s" % (context.__name__, name)
            item_itf = directives.itemsimplement.bind().get(menu)
            config.action(discriminator=('viewlet', Interface, layer,
                                         IBrowserView, menu, item_name),
                          callable=registerMenuItem,
                          args=(
                              factory.module_info,
                              components.ContextMenuItem,
                              (context, layer, IBrowserView, menu),
                              item_name,
                              permission,
                              item_itf,
                              layer,
                              {
                                  'title': title,
                                  'viewName': name,
                                  'description': description,
                                  '_icon': icon,
                                  'group': group
                              },
                              (order, MenuViewGrokker._dynamic_items),
                          ))
            MenuViewGrokker._dynamic_items += 1
        return True