Exemple #1
0
    def test_notted(self):
        from pyramid.config import not_
        from pyramid.testing import DummyRequest

        request = DummyRequest()
        _, predicates, _ = self._callFUT(
            xhr='xhr', request_method=not_('POST'), header=not_('header')
        )
        self.assertEqual(predicates[0].text(), 'xhr = True')
        self.assertEqual(predicates[1].text(), "!request_method = POST")
        self.assertEqual(predicates[2].text(), '!header header')
        self.assertEqual(predicates[1](None, request), True)
        self.assertEqual(predicates[2](None, request), True)
Exemple #2
0
    def test_notted(self):
        from pyramid.config import not_
        from pyramid.testing import DummyRequest

        request = DummyRequest()
        _, predicates, _ = self._callFUT(
            xhr='xhr', request_method=not_('POST'), header=not_('header')
        )
        self.assertEqual(predicates[0].text(), 'xhr = True')
        self.assertEqual(predicates[1].text(), "!request_method = POST")
        self.assertEqual(predicates[2].text(), '!header header')
        self.assertEqual(predicates[1](None, request), True)
        self.assertEqual(predicates[2](None, request), True)
Exemple #3
0
    def test_config_format_ini_commas(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request):
            return 'view1'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(route_name='foo',
                        view=view1,
                        renderer=nr,
                        request_method=not_('POST'))

        command = self._makeOne()

        L = []
        command.out = L.append
        command.bootstrap = (dummy.DummyBootstrap(registry=config.registry), )
        config_factory = dummy.DummyConfigParserFactory()
        command.ConfigParser = config_factory
        config_factory.items = [('format', 'method,name')]

        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = ['!POST,*', 'foo']

        self.assertEqual(compare_to, expected)
        self.assertEqual(L[0].split(), ['Method', 'Name'])
Exemple #4
0
    def test_view_request_method_not_post(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request): return 'view1'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST')
        )

        command = self._makeOne()
        L = []
        command.out = L.append
        command.bootstrap = (dummy.DummyBootstrap(registry=config.registry),)
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = [
            'foo', '/a/b',
            'pyramid.tests.test_scripts.test_proutes.view1',
            '!POST,*'
        ]
        self.assertEqual(compare_to, expected)
Exemple #5
0
    def test_config_format_ini_commas(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request): return 'view1'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST')
        )

        command = self._makeOne()

        L = []
        command.out = L.append
        command.bootstrap = (dummy.DummyBootstrap(registry=config.registry),)
        config_factory = dummy.DummyConfigParserFactory()
        command.ConfigParser = config_factory
        config_factory.items = [('format', 'method,name')]

        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = ['!POST,*', 'foo']

        self.assertEqual(compare_to, expected)
        self.assertEqual(L[0].split(), ['Method', 'Name'])
Exemple #6
0
    def test_config_format_ini_commas(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request):  # pragma: no cover
            return 'view1'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST'),
        )

        command = self._makeOne()

        L = []
        command.out = L.append
        command.bootstrap = dummy.DummyBootstrap(registry=config.registry)
        command.get_config_loader = dummy.DummyLoader(
            {'proutes': {'format': 'method,name'}}
        )

        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = ['!POST,*', 'foo']

        self.assertEqual(compare_to, expected)
        self.assertEqual(L[0].split(), ['Method', 'Name'])
Exemple #7
0
    def test_good_format(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request): return 'view1'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST')
        )

        command = self._makeOne()
        command.args.glob = '*foo*'
        command.args.format = 'method,name'
        L = []
        command.out = L.append
        command.bootstrap = dummy.DummyBootstrap(registry=config.registry)
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = ['!POST,*', 'foo']

        self.assertEqual(compare_to, expected)
        self.assertEqual(L[0].split(), ['Method', 'Name'])
Exemple #8
0
    def test_bad_format(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request):  # pragma: no cover
            return 'view1'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST'),
        )

        command = self._makeOne()
        command.args.glob = '*foo*'
        command.args.format = 'predicates,name,pattern'
        L = []
        command.out = L.append
        command.bootstrap = dummy.DummyBootstrap(registry=config.registry)
        expected = (
            "You provided invalid formats ['predicates'], "
            "Available formats are ['name', 'pattern', 'view', 'method']"
        )
        result = command.run()
        self.assertEqual(result, 2)
        self.assertEqual(L[0], expected)
Exemple #9
0
    def test_view_request_method_not_post(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request):  # pragma: no cover
            return 'view1'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST'),
        )

        command = self._makeOne()
        L = []
        command.out = L.append
        command.bootstrap = dummy.DummyBootstrap(registry=config.registry)
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = [
            'foo',
            '/a/b',
            'tests.test_scripts.test_proutes.view1',
            '!POST,*',
        ]
        self.assertEqual(compare_to, expected)
Exemple #10
0
    def test_bad_format(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request): return 'view1'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST')
        )

        command = self._makeOne()
        command.options.glob = '*foo*'
        command.options.format = 'predicates,name,pattern'
        L = []
        command.out = L.append
        command.bootstrap = (dummy.DummyBootstrap(registry=config.registry),)
        expected = (
            "You provided invalid formats ['predicates'], "
            "Available formats are ['name', 'pattern', 'view', 'method']"
        )
        result = command.run()
        self.assertEqual(result, 2)
        self.assertEqual(L[0], expected)
Exemple #11
0
    def test_view_glob(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request):  # pragma: no cover
            return 'view1'

        def view2(context, request):  # pragma: no cover
            return 'view2'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST'),
        )

        config.add_route('bar', '/b/a')
        config.add_view(
            route_name='bar',
            view=view2,
            renderer=nr,
            request_method=not_('POST'),
        )

        command = self._makeOne()
        command.args.glob = '*foo*'

        L = []
        command.out = L.append
        command.bootstrap = dummy.DummyBootstrap(registry=config.registry)
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = [
            'foo',
            '/a/b',
            'tests.test_scripts.test_proutes.view1',
            '!POST,*',
        ]
        self.assertEqual(compare_to, expected)
Exemple #12
0
    def test_view_glob(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request): return 'view1'
        def view2(context, request): return 'view2'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST')
        )

        config.add_route('bar', '/b/a')
        config.add_view(
            route_name='bar',
            view=view2,
            renderer=nr,
            request_method=not_('POST')
        )

        command = self._makeOne()
        command.options.glob = '*foo*'

        L = []
        command.out = L.append
        command.bootstrap = (dummy.DummyBootstrap(registry=config.registry),)
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = [
            'foo', '/a/b',
            'pyramid.tests.test_scripts.test_proutes.view1',
            '!POST,*'
        ]
        self.assertEqual(compare_to, expected)
class ManagementNotAuthorized(object):
    """Anything related to management that is not authorized"""
    def __init__(self, context, request):
        """Initialises the view class

        :context: The traversal context
        :request: The current request

        """
        self.context = context
        self.request = request

    @view_config(effective_principals=not_('system.Authenticated'))
    def management_not_authed(self):
        raise HTTPForbidden()

    @notfound_view_config(
        containment='..traversal.Root',
        renderer='string',
    )
    def management_not_found(self):
        self.request.response.status_int = 404
        return "404 - Not Found"
Exemple #14
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.include('pyramid_jinja2')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('home2', '/home2')
    config.add_view('tz_pyramid.views.my_view',
                    request_method=not_('GET,HEAD'),
                    route_name='home2',
                    renderer='templates/mytemplate2.jinja2')

    config.add_route('rest', '/rest')
    config.add_view(RESTView,
                    attr='get',
                    request_method='GET',
                    http_cache=3600)
    config.add_view(RESTView, attr='post', request_method='POST')
    config.add_view(RESTView, attr='delete', request_method='DELETE')

    config.scan()
    return config.make_wsgi_app()
Exemple #15
0
        return {
            'form': self.form.render(),
            'group_path': self.request.route_path('group_read',
                                                  pubid=self.group.pubid,
                                                  slug=self.group.slug)
        }

    def _update_group(self, appstruct):
        self.group.name = appstruct['name']
        self.group.description = appstruct['description']


@view_config(route_name='group_read',
             request_method='GET',
             renderer='h:templates/groups/join.html.jinja2',
             effective_principals=not_(security.Authenticated))
def read_unauthenticated(group, request):
    """Group view for logged-out users, allowing them to join the group."""
    check_slug(group, request)
    return {'group': group}


@view_defaults(route_name='group_read',
               renderer='h:templates/groups/join.html.jinja2',
               effective_principals=security.Authenticated,
               has_permission=not_('read'))
class GroupJoinController(object):
    """Views for "group_read" when logged in but not a member of the group."""

    def __init__(self, group, request):
        self.group = group
Exemple #16
0
def simple(global_conf, **settings):
    config = Configurator()
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view(name='static2', path='/var/www/static')
    config.add_static_view(
        name='pdt_images',
        path='pyramid_debugtoolbar:static/img/'
    )
    config.add_route('a', '')
    config.add_route('no_view_attached', '/')
    config.add_route('route_and_view_attached', '/')
    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='route_and_view_attached'
    )

    config.add_route('only_post_on_route', '/route', request_method='POST')
    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='only_post_on_route'
    )

    config.add_route('only_post_on_view', '/view')
    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='only_post_on_view',
        request_method='POST'
    )

    config.add_route(
        'method_intersection',
        '/intersection', request_method=('POST', 'PUT')
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='method_intersection',
        request_method='POST'
    )

    config.add_route(
        'method_conflicts',
        '/conflicts', request_method=('POST', 'PUT')
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='method_conflicts',
        request_method='PATCH'
    )

    config.add_route(
        'multiview',
        '/multiview',
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='multiview',
        request_method='PATCH'
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='multiview',
        request_method='GET'
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.hello_world',
        route_name='multiview',
        request_method='POST'
    )

    config.add_route(
        'class_based_view',
        '/classes',
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.ClassBasedView',
        attr='awesome',
        route_name='class_based_view',
        request_method='POST'
    )

    config.add_route(
        'factory',
        '/factory',
        factory=RootContext,
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='factory',
    )

    config.add_route(
        'not_post',
        '/not_post',
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='not_post',
        request_method=not_('POST'),
    )

    config.add_route(
        'not_post_only_get',
        '/not_post_only_get',
        request_method=('POST', 'GET'),
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='not_post_only_get',
        request_method=not_('POST'),
    )

    config.add_route(
        'permission_on_view',
        '/permission_on_view',
        permission='boom'
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='permission_on_view',
    )

    wsgi_app = config.make_wsgi_app()
    return wsgi_app
Exemple #17
0
            self.form.render(),
            'group_path':
            self.request.route_path('group_read',
                                    pubid=self.group.pubid,
                                    slug=self.group.slug)
        }

    def _update_group(self, appstruct):
        self.group.name = appstruct['name']
        self.group.description = appstruct['description']


@view_config(route_name='group_read',
             request_method='GET',
             renderer='h:templates/groups/join.html.jinja2',
             effective_principals=not_(security.Authenticated))
def read_unauthenticated(group, request):
    """Group view for logged-out users, allowing them to join the group."""
    check_slug(group, request)

    if group.joinable_by is None:
        raise httpexceptions.HTTPNotFound()

    return {'group': group}


@view_config(route_name='group_read_noslug', request_method='GET')
def read_noslug(group, request):
    check_slug(group, request)

Exemple #18
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view(name='static2', path='/var/www/static')
    config.add_static_view(name='pdt_images',
                           path='pyramid_debugtoolbar:static/img/')
    config.add_route('a', '')
    config.add_route('no_view_attached', '/')
    config.add_route('route_and_view_attached', '/')
    config.add_view('dummy_starter.standard_views.route_and_view_attached',
                    route_name='route_and_view_attached')

    config.add_route('only_post_on_route', '/route', request_method='POST')
    config.add_view('dummy_starter.standard_views.route_and_view_attached',
                    route_name='only_post_on_route')

    config.add_route('only_post_on_view', '/view')
    config.add_view('dummy_starter.standard_views.route_and_view_attached',
                    route_name='only_post_on_view',
                    request_method='POST')

    config.add_route('method_intersection',
                     '/intersection',
                     request_method=('POST', 'PUT'))

    config.add_view('dummy_starter.standard_views.route_and_view_attached',
                    route_name='method_intersection',
                    request_method='POST')

    config.add_route('method_conflicts',
                     '/conflicts',
                     request_method=('POST', 'PUT'))

    config.add_view('dummy_starter.standard_views.route_and_view_attached',
                    route_name='method_conflicts',
                    request_method='PATCH')

    config.add_route(
        'multiview',
        '/multiview',
    )

    config.add_view('dummy_starter.standard_views.route_and_view_attached',
                    route_name='multiview',
                    request_method='PATCH')

    config.add_view('dummy_starter.standard_views.route_and_view_attached',
                    route_name='multiview',
                    request_method='GET')

    config.add_view('dummy_starter.standard_views.hello_world',
                    route_name='multiview',
                    request_method='POST')

    config.add_route(
        'class_based_view',
        '/classes',
    )

    config.add_view('dummy_starter.standard_views.ClassBasedView',
                    attr='awesome',
                    route_name='class_based_view',
                    request_method='POST')

    config.add_route(
        'factory',
        '/factory',
        factory=RootContext,
    )

    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='factory',
    )

    config.add_route(
        'not_post',
        '/not_post',
    )

    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='not_post',
        request_method=not_('POST'),
    )

    config.add_route(
        'not_post_only_get',
        '/not_post_only_get',
        request_method=('POST', 'GET'),
    )

    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='not_post_only_get',
        request_method=not_('POST'),
    )

    config.scan()
    return config.make_wsgi_app()
Exemple #19
0
def simple(global_conf, **settings):
    config = Configurator()
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view(name='static2', path='/var/www/static')
    config.add_static_view(name='pdt_images',
                           path='pyramid_debugtoolbar:static/img/')
    config.add_route('a', '')
    config.add_route('no_view_attached', '/')
    config.add_route('route_and_view_attached', '/')
    config.add_view('tomb_cli_testapps.standard_views.route_and_view_attached',
                    route_name='route_and_view_attached')

    config.add_route('only_post_on_route', '/route', request_method='POST')
    config.add_view('tomb_cli_testapps.standard_views.route_and_view_attached',
                    route_name='only_post_on_route')

    config.add_route('only_post_on_view', '/view')
    config.add_view('tomb_cli_testapps.standard_views.route_and_view_attached',
                    route_name='only_post_on_view',
                    request_method='POST')

    config.add_route('method_intersection',
                     '/intersection',
                     request_method=('POST', 'PUT'))

    config.add_view('tomb_cli_testapps.standard_views.route_and_view_attached',
                    route_name='method_intersection',
                    request_method='POST')

    config.add_route('method_conflicts',
                     '/conflicts',
                     request_method=('POST', 'PUT'))

    config.add_view('tomb_cli_testapps.standard_views.route_and_view_attached',
                    route_name='method_conflicts',
                    request_method='PATCH')

    config.add_route(
        'multiview',
        '/multiview',
    )

    config.add_view('tomb_cli_testapps.standard_views.route_and_view_attached',
                    route_name='multiview',
                    request_method='PATCH')

    config.add_view('tomb_cli_testapps.standard_views.route_and_view_attached',
                    route_name='multiview',
                    request_method='GET')

    config.add_view('tomb_cli_testapps.standard_views.hello_world',
                    route_name='multiview',
                    request_method='POST')

    config.add_route(
        'class_based_view',
        '/classes',
    )

    config.add_view('tomb_cli_testapps.standard_views.ClassBasedView',
                    attr='awesome',
                    route_name='class_based_view',
                    request_method='POST')

    config.add_route(
        'factory',
        '/factory',
        factory=RootContext,
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='factory',
    )

    config.add_route(
        'not_post',
        '/not_post',
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='not_post',
        request_method=not_('POST'),
    )

    config.add_route(
        'not_post_only_get',
        '/not_post_only_get',
        request_method=('POST', 'GET'),
    )

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='not_post_only_get',
        request_method=not_('POST'),
    )

    config.add_route('permission_on_view',
                     '/permission_on_view',
                     permission='boom')

    config.add_view(
        'tomb_cli_testapps.standard_views.route_and_view_attached',
        route_name='permission_on_view',
    )

    wsgi_app = config.make_wsgi_app()
    return wsgi_app
Exemple #20
0
        return {
            'form': self.form.render(),
            'group_path': self.request.route_path('group_read',
                                                  pubid=self.group.pubid,
                                                  slug=self.group.slug)
        }

    def _update_group(self, appstruct):
        self.group.name = appstruct['name']
        self.group.description = appstruct['description']


@view_config(route_name='group_read',
             request_method='GET',
             renderer='h:templates/groups/join.html.jinja2',
             effective_principals=not_(security.Authenticated))
def read_unauthenticated(group, request):
    """Group view for logged-out users, allowing them to join the group."""
    check_slug(group, request)

    if group.joinable_by is None:
        raise httpexceptions.HTTPNotFound()

    return {'group': group}


@view_config(route_name='group_read_noslug', request_method='GET')
def read_noslug(group, request):
    check_slug(group, request)

Exemple #21
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view(name='static2', path='/var/www/static')
    config.add_static_view(
        name='pdt_images',
        path='pyramid_debugtoolbar:static/img/'
    )
    config.add_route('a', '')
    config.add_route('no_view_attached', '/')
    config.add_route('route_and_view_attached', '/')
    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='route_and_view_attached'
    )

    config.add_route('only_post_on_route', '/route', request_method='POST')
    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='only_post_on_route'
    )

    config.add_route('only_post_on_view', '/view')
    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='only_post_on_view',
        request_method='POST'
    )

    config.add_route(
        'method_intersection',
        '/intersection', request_method=('POST', 'PUT')
    )

    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='method_intersection',
        request_method='POST'
    )

    config.add_route(
        'method_conflicts',
        '/conflicts', request_method=('POST', 'PUT')
    )

    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='method_conflicts',
        request_method='PATCH'
    )

    config.add_route(
        'multiview',
        '/multiview',
    )

    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='multiview',
        request_method='PATCH'
    )

    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='multiview',
        request_method='GET'
    )

    config.add_view(
        'dummy_starter.standard_views.hello_world',
        route_name='multiview',
        request_method='POST'
    )

    config.add_route(
        'class_based_view',
        '/classes',
    )

    config.add_view(
        'dummy_starter.standard_views.ClassBasedView',
        attr='awesome',
        route_name='class_based_view',
        request_method='POST'
    )

    config.add_route(
        'factory',
        '/factory',
        factory=RootContext,
    )

    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='factory',
    )


    config.add_route(
        'not_post',
        '/not_post',
    )

    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='not_post',
        request_method=not_('POST'),
    )

    config.add_route(
        'not_post_only_get',
        '/not_post_only_get',
        request_method=('POST', 'GET'),
    )

    config.add_view(
        'dummy_starter.standard_views.route_and_view_attached',
        route_name='not_post_only_get',
        request_method=not_('POST'),
    )

    config.scan()
    return config.make_wsgi_app()
Exemple #22
0
# limitation we do not need to lift any time soon.
@view_config(route_name='token', renderer='string', request_method='GET')
def annotator_token(request):
    """
    Return a JWT access token for the given request.

    The token can be used in the Authorization header in subsequent requests to
    the API to authenticate the user identified by the
    request.authenticated_userid of the _current_ request, which may be None.
    """
    return generate_jwt(request, 3600)


@view_config(route_name='embed',
             renderer='h:templates/embed.js.jinja2',
             has_feature_flag=not_('use_client_boot_script'))
def embed(request):
    """
    Render the script which loads the Hypothesis client on a page.

    This view renders a script which loads the assets required by the client.
    """
    request.response.content_type = 'text/javascript'

    assets_env = request.registry['assets_client_env']
    base_url = request.route_url('index')

    def absolute_asset_urls(bundle_name):
        return [
            urlparse.urljoin(base_url, url)
            for url in assets_env.urls(bundle_name)