install superperms
pip install superpermsadd superperms to your INSTALLED_APPS
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.flatpages',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.humanize',
'django.contrib.admin',
'south',
'superperms.orgs',
)Run migrations to create the database tables
python manage.py migrate superperms.orgsNote: if your app uses a custom AUTH_USER_MODEL (a user model that is not django.contrib.auth.User), you will need to create the table for your user before you run the migrations for superperms. You can declare this dependency in the initial migration for the custom user as show below. This is necessary so that superperm organizations can have a foreign key to the custom user model.
class Migration(SchemaMigration):
needed_by = (
('superperms.orgs', '0001_initial'),
)ALLOW_SUPER_USER_PERMS: Allows Django super_user class accounts to bypass permissions checks. This is useful mainly for development, but defaults toTrue.
- To limit views to people who have member-level roles and above, you could use the following decorator definiition. Users who are
viewerswill recieve a DjangoHttpRequestNotAuthorizedresponse (e.g. a 403) without ever executing the code inside the view.
from superperms.orgs.decorators import has_perm # Imports our decorator factory.
# This view will be protected against anybody whose account is "lower"
# than a member. Default role types include ['owner', 'member', 'viewer'].
@has_perm('requires_member')
def protected_view(request):
passclone the repo and install requirements
$ git clone git@github.com:buildingenergy/superperms.git
$ mkvirtualenv superperms
(superperms)$ cd superperms
(superperms)$ pip install -r requirements.txttests should pass, PEP8 is enforced
(superperms)$ ./test.sh
