Skip to content

MichalMazurek/django-locksmith

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-locksmith

Simple way for restricting access to views

Quick Start

    1. Add 'locksmith' to installed apps in your settings.py:
INSTALLED_APPS = (
    ...
    'locksmith'
)

and install it:

./manage.py syncdb locksmith
    1. Configure your key names in settings.py:
LOCKSMITH_KEYS = (
    'articles',
    'users'
)
    1. Update your keys (you can do it every time you add a key)
./manage.py updatekeys
    1. Update your custom user model, add locksmith mixin:
class User(locksmith.models.LocksmithMixin, models.Model):
...
    1. Add key to users keychain (currently no admin interface):
from locksmith.models import Keychain, Key
...
user = Users.objects.get(pk=1) # your user
# create keychain for this user
keychain = Keychain(expiration_date="2020-12-31")
keychain.save()
user.keychain = keychain

user.keychain.add(Key.objects.get(name='articles')
    1. Configure your views
from locksmith.decorators import key_required
...
@key_required('articles')
def action(request, *args, **kwargs):

And that's it!

About

Simple way for restricting access to views

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages