django-groups-manager


Namedjango-groups-manager JSON
Version 1.3.0 PyPI version JSON
download
home_pagehttps://github.com/vittoriozamboni/django-groups-manager
SummaryDjango groups manager through django-mptt.
upload_time2023-06-15 09:52:08
maintainer
docs_urlNone
authorVittorio Zamboni
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            # Django groups manager

[![Build Status](https://travis-ci.org/vittoriozamboni/django-groups-manager.svg?branch=master)](https://travis-ci.org/vittoriozamboni/django-groups-manager) [![Coverage Status](https://coveralls.io/repos/vittoriozamboni/django-groups-manager/badge.png?branch=master)](https://coveralls.io/r/vittoriozamboni/django-groups-manager?branch=master) ![Version](https://badge.fury.io/py/django-groups-manager.svg)

This application allows to create hierarchical groups by using [django-mptt](https://github.com/django-mptt/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](https://github.com/lukaszb/django-guardian/).

## Documentation

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

### Note

Version `1.1.0` changed the default slugify function from `awesome-slugify` to `django.utils.text.slugify`.
To keep using `awesome-slugify` you need to install it separately, and then
[customize the settings](https://django-groups-manager.readthedocs.io/en/latest/settings.html#slugify-function):

```python
from slugify import slugify
GROUPS_MANAGER = {
    # ... other settings
    'SLUGIFY_FUNCTION': lambda s: slugify(s, to_lower=True),
    'SLUGIFY_USERNAME_FUNCTION': lambda s: slugify(s, to_lower=True, separator="_")
}
```

## Requirements

    - Python >= 3.8
    - Django >= 3.2
    - django-guardian for user permissions
    - jsonfield == 3.1.0

For older versions of Python or Django, please look at 1.2.0 (Django <3.2, Python < 3.8>) or 0.6.2 version (Django 1.x, Python < 3.5).

## Installation

Use pip to install `django-groups-manager`:

```bash
pip install django-groups-manager
```

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

```bash
pip install django-guardian
```

### Django Configuration

1. Add `groups_manager` into your `INSTALLED_APPS`:

   ```python
   INSTALLED_APPS = (
      ...
      # 'guardian', # add as well to use permissions related features
      'groups_manager',
   )
   ```

2. Create models with `migrate`:

   ```bash
   python manage.py migrate groups_manager
   ```

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

   ```bash
   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:

   ```python
   GROUPS_MANAGER = {
       'AUTH_MODELS_SYNC': True,
   }
   ```

## Basic usage

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

```python
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:

```python
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`:

```python
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.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vittoriozamboni/django-groups-manager",
    "name": "django-groups-manager",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Vittorio Zamboni",
    "author_email": "vittorio.zamboni@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a6/47/3420f49d6316cb194e9ad26e3490573791f0829d24ba6a5913c3c8849818/django-groups-manager-1.3.0.tar.gz",
    "platform": null,
    "description": "# Django groups manager\n\n[![Build Status](https://travis-ci.org/vittoriozamboni/django-groups-manager.svg?branch=master)](https://travis-ci.org/vittoriozamboni/django-groups-manager) [![Coverage Status](https://coveralls.io/repos/vittoriozamboni/django-groups-manager/badge.png?branch=master)](https://coveralls.io/r/vittoriozamboni/django-groups-manager?branch=master) ![Version](https://badge.fury.io/py/django-groups-manager.svg)\n\nThis application allows to create hierarchical groups by using [django-mptt](https://github.com/django-mptt/django-mptt) tree structure.\nIt 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](https://github.com/lukaszb/django-guardian/).\n\n## Documentation\n\nOnline documentation is available at http://django-groups-manager.readthedocs.org/.\n\n### Note\n\nVersion `1.1.0` changed the default slugify function from `awesome-slugify` to `django.utils.text.slugify`.\nTo keep using `awesome-slugify` you need to install it separately, and then\n[customize the settings](https://django-groups-manager.readthedocs.io/en/latest/settings.html#slugify-function):\n\n```python\nfrom slugify import slugify\nGROUPS_MANAGER = {\n    # ... other settings\n    'SLUGIFY_FUNCTION': lambda s: slugify(s, to_lower=True),\n    'SLUGIFY_USERNAME_FUNCTION': lambda s: slugify(s, to_lower=True, separator=\"_\")\n}\n```\n\n## Requirements\n\n    - Python >= 3.8\n    - Django >= 3.2\n    - django-guardian for user permissions\n    - jsonfield == 3.1.0\n\nFor older versions of Python or Django, please look at 1.2.0 (Django <3.2, Python < 3.8>) or 0.6.2 version (Django 1.x, Python < 3.5).\n\n## Installation\n\nUse pip to install `django-groups-manager`:\n\n```bash\npip install django-groups-manager\n```\n\nTo use per-object permissions related features, `django-guardian` is required as well:\n\n```bash\npip install django-guardian\n```\n\n### Django Configuration\n\n1. Add `groups_manager` into your `INSTALLED_APPS`:\n\n   ```python\n   INSTALLED_APPS = (\n      ...\n      # 'guardian', # add as well to use permissions related features\n      'groups_manager',\n   )\n   ```\n\n2. Create models with `migrate`:\n\n   ```bash\n   python manage.py migrate groups_manager\n   ```\n\n   Note: for users that are upgrading from <0.4.2, launch:\n\n   ```bash\n   python manage.py migrate groups_manager 0001 --fake\n   python manage.py migrate groups_manager\n   ```\n\n3. To enable django `auth.models` synchronization, add to the settings module:\n\n   ```python\n   GROUPS_MANAGER = {\n       'AUTH_MODELS_SYNC': True,\n   }\n   ```\n\n## Basic usage\n\nThe common case is to create a simple parent-son relation:\n\n```python\nfrom groups_manager.models import Group, Member\nfc_internazionale = Group.objects.create(name='F.C. Internazionale Milan')\nstaff = Group.objects.create(name='Staff', parent=fc_internazionale)\nplayers = Group.objects.create(name='Players', parent=fc_internazionale)\nthohir = Member.objects.create(first_name='Eric', last_name='Thohir')\nstaff.add_member(thohir)\npalacio = Member.objects.create(first_name='Rodrigo', last_name='Palacio')\nplayers.add_member(palacio)\n```\n\nPer-object permissions handling is done by `django-guardian`. The Group/Member relation can be used to assing objects:\n\n```python\nfrom football.models import TeamBudget\nsmall_budget = TeamBudget.objects.create(euros='1000')\nthohir.assign_object(staff, small_budget)\nthohir.has_perm('change_teambudget', small_budget)  # True\npalacio.has_perm('change_teambudget', small_budget)  # False\n# or via group\nmid_budget = TeamBudget.objects.create(euros='3000')\nstaff.assign_object(mid_budget)\nthohir.has_perm('change_teambudget', mid_budget)  # True\npalacio.has_perm('change_teambudget', mid_budget)  # False\n```\n\nOwner/Group members policies can be defined via `PERMISSIONS` setting, as a dictionary of `GROUPS_MANAGER`, but can also be overwritten via `custom_permissions` `kwarg`:\n\n```python\nfrom football.models import Match\nfc_barcelona = Group.objects.create(name='FC Barcelona')\nfriendly_match = Match.objects.create(home=fc_internazionale, away=fc_barcelona)\npalacio.assign_match(players, friendly_match, custom_permissions={'group': ['play']})\nthohir.has_perm('play_match', friendly_match)  # False\npalacio.has_perm('play_match', friendly_match)  # True\n```\n\nFor more complex cases, see documentation.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django groups manager through django-mptt.",
    "version": "1.3.0",
    "project_urls": {
        "Homepage": "https://github.com/vittoriozamboni/django-groups-manager"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fbc51ab733e6541b9e0830c50f2bdb9da51586bc2e3eb97891bf7df2fa2799e6",
                "md5": "6a3845c94d2333d07c78c44d97729ba2",
                "sha256": "2588ec3e93ea89559f9f2f77563b18e40e414895b810ab80e9641e3e8bc41ff3"
            },
            "downloads": -1,
            "filename": "django_groups_manager-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6a3845c94d2333d07c78c44d97729ba2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 68721,
            "upload_time": "2023-06-15T09:52:06",
            "upload_time_iso_8601": "2023-06-15T09:52:06.305387Z",
            "url": "https://files.pythonhosted.org/packages/fb/c5/1ab733e6541b9e0830c50f2bdb9da51586bc2e3eb97891bf7df2fa2799e6/django_groups_manager-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6473420f49d6316cb194e9ad26e3490573791f0829d24ba6a5913c3c8849818",
                "md5": "f3242097030b8d90aae2b284cc2203bc",
                "sha256": "fcc099ac8ce8efc1a620f679728d26de1f9cc8068482b9cfb06bfef1d08ad3a8"
            },
            "downloads": -1,
            "filename": "django-groups-manager-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f3242097030b8d90aae2b284cc2203bc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 61671,
            "upload_time": "2023-06-15T09:52:08",
            "upload_time_iso_8601": "2023-06-15T09:52:08.852525Z",
            "url": "https://files.pythonhosted.org/packages/a6/47/3420f49d6316cb194e9ad26e3490573791f0829d24ba6a5913c3c8849818/django-groups-manager-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-15 09:52:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vittoriozamboni",
    "github_project": "django-groups-manager",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "tox": true,
    "lcname": "django-groups-manager"
}
        
Elapsed time: 0.09271s