Skip to content

Instantly share code, notes, and snippets.

@edelooff

edelooff/app.py

Created Aug 16, 2016
Embed
What would you like to do?
Pyramid 1.7 view deriver to alert on view_configs that lack a permission setting.
def permission_check(view, info):
"""View deriver to verify all view configs define a 'permission'.
This deriver prints a message for each view config that lacks a permission
setting. Regardless of this setting, the original view is returned.
"""
opts = info.options
if opts.get('permission') is None:
name_parts = [opts['view'].__module__, opts['view'].__name__]
if opts['attr'] is not None:
name_parts.append(opts['attr'])
print('{}: no permission defined ¯\_(ツ)_/¯'.format('.'.join(func)))
return view
def main(global_config, **settings):
config = Configurator(settings=settings)
config.add_default_permission('nobody_should_assign_this')
config.add_view_deriver(permission_check)
# Everything else to set up and return your wsgi app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.