Search code examples
pythonpyramid

Permissions on specific elements in a page in pyramid-python


In Pyramid, you can set permissions on entire views. I'm trying to find a way to display a single element inside a view with different permissions. For example, if I have a page that has a lot of data about a person, such as a profile page, I want to display an element that allows a user to modify information on that page, as long as that user is in a specified group.

Can I do this from one view or do I have to create a new view for each level of authentication (or group) that has different elements on the page?


Solution

  • Use request.has_permission imperatively:

    if request.has_permission('edit', context):
        ... render some template or somehow include ui in current view's template ...
    else:
        .. dont ...