Created
August 16, 2016 16:16
-
-
Save edelooff/7913e2d74ef369d0f60a210c4650a3bc to your computer and use it in GitHub Desktop.
Pyramid 1.7 view deriver to alert on view_configs that lack a permission setting.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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