Global settings for access mixins
Nicals opened this issue · 1 comments
In a project, we usually have a global way of handling accesses in views.
The problem with access current access mixins, we need to configure raise_exception, redirect_unanthenticated_users and other mixins settings in the view class.
If I'm not wrong, their is two way of having the same settings on all views:
- create our own AccessMixins with those attribute set to our required values.
- set those settings in each views.
In one of my project, I had a huge number of views I needed to re-configure access for.
I think we need to have some globals settings that should be set to configure access mixins default attribute values. For exemple:
# file: settings.py
BRACES = {
'access_raise_exception': True,
'redirect_unauthenticated_users': True,
}
I think this could be achieve by setting the raise_exception attribute to None. This should tell to use default value from settings. Other value than None would override the setting value. For exemple, something like that:
class AccessMixin(object):
def get_raise_exception(self):
if self.raise_exception is None:
return getattr(settings, 'BRACES', dict()).get('access_raise_exception', False)
return self.raise_exception
def handle_no_permission(self, request):
raise_exception = self.get_raise_exception()
if raise_exception:
# ...
closing very old issues