Skip to main content

Django groups manager through django-mptt.

Project description

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.readthedocs.org/.

Requirements

- Python >= 3.5
- Django >= 2
- django-guardian for user permissions

For older versions of Python or Django, please look at 0.6.2 version.

Installation

Use pip to install django-groups-manager:

pip install django-groups-manager

To use per-object permissions related features, django-guardian is required as well:

pip install django-guardian

Django Configuration

  1. Add groups_manager into your INSTALLED_APPS:

    INSTALLED_APPS = (
       ...
       # 'guardian', # add as well to use permissions related features
       'groups_manager',
    )
    
  2. 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
    
  3. To enable django auth.models synchronization, add to the settings module:

    GROUPS_MANAGER = {
        'AUTH_MODELS_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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-groups-manager-1.0.1.tar.gz (59.6 kB view details)

Uploaded Source

Built Distribution

django_groups_manager-1.0.1-py3-none-any.whl (66.8 kB view details)

Uploaded Python 3

File details

Details for the file django-groups-manager-1.0.1.tar.gz.

File metadata

  • Download URL: django-groups-manager-1.0.1.tar.gz
  • Upload date:
  • Size: 59.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0

File hashes

Hashes for django-groups-manager-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7e2f2f80d9f7bfe8c06c38b44836e1b0494d28c8c5f42b4e809ed80d6a21ce97
MD5 3573ffb7fa656692460285d608385695
BLAKE2b-256 d935970bfbf09eda8367033d9661f39b1905742ede1ac3a3a0c590821c9097b3

See more details on using hashes here.

File details

Details for the file django_groups_manager-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_groups_manager-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 66.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0

File hashes

Hashes for django_groups_manager-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4238663ce2ce3bfcedc56590bd2c1ab69acefa1fc9f2bc65a565f2ccf32edaae
MD5 5663c0388f402e202c9086a907be0efe
BLAKE2b-256 8651b23451ae1063d66ff94ac6f005a3c7939614264a9a61b58e476192eae96a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page