rules.contrib.views.objectgetter() does not work with default view argument values
chinniehendrix opened this issue · comments
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: []
Solved using a custom object-getter function.
Perfect 👍
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?