Git Product home page Git Product logo

django-groups-manager's Introduction

Django groups manager

Build Status Coverage Status Version

This application allows to create hierarchical groups by using django-mptt tree structure. It is also possible to synchronize the groups with Django's auth.models Group and User, in order to take advantage of permissions applications like django-guardian.

Documentation

Online documentation is available at http://django-groups-manager.rtfd.org/.

Requirements

- Django >= 1.7
- django-guardian for user permissions (<1.4 for Django < 1.8)

Installation

Use pip to install django-groups-manager:

pip install django-groups-manager

Django Configuration

  1. Add groups_manager into your INSTALLED_APPS:

    INSTALLED_APPS = (
       ...
       'groups_manager',
    )

If you want to use permissions related features, add also django-guardian.

  1. Create models with migrate:

    python manage.py migrate groups_manager

    Note: for users that are upgrading from <0.4.2, launch:

    python manage.py migrate groups_manager 0001 --fake
    python manage.py migrate groups_manager
  2. To enable django auth.models synchronization, add to the settings module:

    GROUPS_MANAGER = {
        'DJANGO_AUTH_SYNC': True,
    }

Basic usage

The common case is to create a simple parent-son relation:

from groups_manager.models import Group, Member
fc_internazionale = Group.objects.create(name='F.C. Internazionale Milan')
staff = Group.objects.create(name='Staff', parent=fc_internazionale)
players = Group.objects.create(name='Players', parent=fc_internazionale)
thohir = Member.objects.create(first_name='Eric', last_name='Thohir')
staff.add_member(thohir)
palacio = Member.objects.create(first_name='Rodrigo', last_name='Palacio')
players.add_member(palacio)

Per-object permissions handling is done by django-guardian. The Group/Member relation can be used to assing objects:

from football.models import TeamBudget
small_budget = TeamBudget.objects.create(euros='1000')
thohir.assign_object(staff, small_budget)
thohir.has_perm('change_teambudget', small_budget)  # True
palacio.has_perm('change_teambudget', small_budget)  # False
# or via group
mid_budget = TeamBudget.objects.create(euros='3000')
staff.assign_object(mid_budget)
thohir.has_perm('change_teambudget', mid_budget)  # True
palacio.has_perm('change_teambudget', mid_budget)  # False

Owner/Group members policies can be defined via PERMISSIONS setting, as a dictionary of GROUPS_MANAGER, but can also be overwritten via custom_permissions kwarg:

from football.models import Match
fc_barcelona = Group.objects.create(name='FC Barcelona')
friendly_match = Match.objects.create(home=fc_internazionale, away=fc_barcelona)
palacio.assign_match(players, friendly_match, custom_permissions={'group': ['play']})
thohir.has_perm('play_match', friendly_match)  # False
palacio.has_perm('play_match', friendly_match)  # True

For more complex cases, see documentation.

django-groups-manager's People

Contributors

vittoriozamboni avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.