Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rules.contrib.views.objectgetter() does not work with default view argument values #37

Closed
chinniehendrix opened this issue Sep 7, 2016 · 3 comments

Comments

@chinniehendrix
Copy link

When using the permission_required decorator as follows:
@permission_required('perm_name', fn=objectgetter(model_name, view_arg)),
it is not possible to leverage default argument values as specified in the view declaration.

If for example, I declare my view as follows:
def edit_circle(request, cid=0):
...

When the view is called without the 'cid' argument, the following exception is raised:
ImproperlyConfigured: Argument cid is not available. Given arguments: []

@chinniehendrix
Copy link
Author

Solved using a custom object-getter function.

@dfunckt
Copy link
Owner

dfunckt commented Sep 8, 2016

Perfect 👍

@shacker
Copy link

shacker commented Mar 7, 2018

I just hit this too. I'll also solve it with a custom function, but it would be handy to have this built in. Typical use case is this: A single view that is used for both create and edit of an object. With a passed in ID, edits existing, without, creates new. No special permissions needed for new, but one can only edit their own existing objects. That's a fairly common pattern, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants