Example #1
0
 def callback_view(self, context, name, view):
     view_info = self._conflicts[view]
     config = context.config
     config._ainfo.append(ActionInfo(*view_info.info.codeinfo))
     config.action((self.name, view_info.method))
     config._ainfo.pop()
     self._conflicts.pop(view)
Example #2
0
    def _add_views(self, config, resource):
        config._ainfo.append(ActionInfo(*resource.info.codeinfo))
        for view_info in resource.views.itervalues():
            if inspect.isfunction(view_info.view):
                mapper = FunctionViewMapper
                attr = None
            else:
                mapper = ClassViewMapper
                attr = view_info.view.__name__
            settings = view_info.settings.copy()
            settings.update(
                self._get_view_predicates(resource, view_info.method)
                )
            settings.setdefault('renderer', 'pyramid_rest_renderer')
            config.add_view(
                view=view_info.view,
                mapper=mapper,
                attr=attr,
                **settings
                )

        if not resource.singular:
            not_allowed = [m for m in self.methods if m not in resource.views]
        if resource.singular:
            not_allowed = [m for m in self.singular_methods if (
                m not in resource.views)
                ]

        for method in not_allowed:
            config.add_view(
                view=not_allowed_view,
                **self._get_view_predicates(resource, method)
                )
        config._ainfo.pop()
Example #3
0
 def _add_routes(self, config, resource):
     config._ainfo.append(ActionInfo(*resource.info.codeinfo))
     factory = functools.partial(ResourceContext, resource)
     if not resource.singular:
         config.add_route(
             pattern='%s' % resource.new_pattern,
             name='%s' % resource.new_route_name,
             factory=factory,
             )
         config.add_route(
             pattern=resource.item_pattern,
             name=resource.item_route_name,
             factory=factory,
             )
     config.add_route(
         pattern='%s' % resource.edit_pattern,
         name='%s' % resource.edit_route_name,
         factory=factory,
         )
     config.add_route(
         pattern=resource.pattern,
         name=resource.route_name,
         factory=factory,
         )
     config._ainfo.pop()
Example #4
0
 def action_info(self):
     info = self.info  # usually a ZCML action (ParserInfo) if self.info
     if not info:
         # Try to provide more accurate info for conflict reports
         if self._ainfo:
             info = self._ainfo[0]
         else:
             info = ActionInfo(None, 0, '', '')
     return info
Example #5
0
    def _add_introspectable(self, config, resource):
        cat_name = 'pyramid_rest resources'
        intr = config.introspectable(
            category_name=cat_name,
            discriminator=resource.discriminator,
            title=resource.name,
            type_name='resource',
            )
        intr['resource'] = resource
        intr['documentation'] = resource.__doc__
        intr.relate('routes', resource.route_name)
        intr.relate('routes', resource.edit_route_name)
        if not resource.singular:
            intr.relate('routes', resource.item_route_name)
            intr.relate('routes', resource.new_route_name)

        if resource.parent:
            intr.relate(cat_name, resource.parent.discriminator)

        config._ainfo.append(ActionInfo(*resource.info.codeinfo))
        config.action(resource.discriminator, introspectables=(intr,))
        config._ainfo.pop()