django-rules-light 0.2.0

Rule registry for django

This is a simple alternative to django-rules. The core difference is that it uses as registry that can be modified on runtime, instead of database models.

One of the goal is to enable developpers of external apps to make rules, depend on it, while allowing a project to override rules.

Example your_app/rules_light_registry.py:

# Everybody can read a blog post (for now!):
rules_light.registry['blog.post.read'] = True

# Require authentication to create a blog post, using a shortcut:
rules_light.registry['blog.post.create'] = rules_light.is_authenticated

def is_staff_or_mine(user, rule, obj):
    return user.is_staff or obj.author == user

# But others shouldn't mess with my posts !
rules_light.registry['blog.post.update'] = is_staff_or_mine
rules_light.registry['blog.post.delete'] = is_staff_or_mine

Example your_app/views.py:

@rules_light.class_decorator
class PostDetailView(generic.DetailView):
    model = Post

@rules_light.class_decorator
class PostCreateView(generic.CreateView):
    model = Post

@rules_light.class_decorator
class PostUpdateView(generic.UpdateView):
    model = Post

@rules_light.class_decorator
class PostDeleteView(generic.DeleteView):
    model = Post

You might want to read the tutorial for more.

What's the catch ?

The catch is that this approach does not offer any feature to get secure querysets.

This means that the developper has to:

  • think about security when making querysets,
  • override eventual external app ListViews,

Requirements

  • Python 2.7+ (Python 3 supported)
  • Django 1.4+

Quick Install

  • Install module: pip install django-rules-light,
  • Add to settings.INSTALLED_APPS: rules_light,
  • Add in settings.MIDDLEWARE_CLASSES: rules_light.middleware.Middleware,
  • Add in urls.py: rules_light.autodiscover() if you have admin.autodiscover() in there too (Django < 1.7),

You might want to read the tutorial.

There is also a lot of documentation, from the core to the tools, including pointers to debug, log and test your security.

Contributing

Run tests with the tox command. Documented patches passing all tests have more chances getting merged in, see community guidelines for details.

Resources

You could subscribe to the mailing list ask questions or just be informed of package updates.

MIT

Author

James Pic

Pip

django-rules-light==0.2.0

Classifiers

  • Development Status :: 5 - Production/Stable
  • Intended Audience :: Developers
  • License :: OSI Approved :: MIT License
  • Operating System :: OS Independent
  • Programming Language :: Python
  • Programming Language :: Python :: 2
  • Programming Language :: Python :: 3
  • Topic :: Software Development :: Libraries :: Python Modules
File Type Python Version Uploaded On Downloads
django-rules-light-0.2.0.tar.gz Source April 23, 2015 1,727
Version Release Date
0.2.0 April 23, 2015
0.1.3 April 18, 2015
0.1.2 Dec. 11, 2013
0.1.1 Sept. 25, 2013
0.1.0 Sept. 25, 2013
0.0.9 March 26, 2013
0.0.8 Feb. 13, 2013
0.0.7 Feb. 13, 2013
0.0.6 Jan. 29, 2013
0.0.5 Dec. 11, 2012
0.0.3 Nov. 30, 2012
0.0.2 Nov. 30, 2012
0.0.1 Nov. 28, 2012
0.0.0 Nov. 27, 2012
Date Package Version Action
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.1.3 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.1.2 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.1.1 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.1.0 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.2.0 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.0.8 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.0.9 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.0.2 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.0.3 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.0.0 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.0.1 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.0.6 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.0.7 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light 0.0.5 Release Created
Aug. 26, 2015, 12:24 a.m. django-rules-light Package Created