Settings¶
The application can be configured via settings with GROUPS_MANAGER
dictionary.
Valid keys and values are described below.
Auth model synchronization¶
"AUTH_MODELS_SYNC"
: enables Group, Member and GroupMember synchronization with django’s Group and User (default:False
);"AUTH_MODELS_GET_OR_CREATE"
: useget_or_create
method instead ofcreate
for django’s Group and User models when associating to Group or Member (default:True
);"GROUP_NAME_PREFIX"
: prefix used for autogenerated django Group’s name (default:"DGN_"
)"GROUP_NAME_SUFFIX"
: suffix used for autogenerated django Group’s name. The special value"_$$random"
can be used for generate a pseudo-unique suffix of length 8 (the first block of an UUID4) (default:"_$$random"
)"USER_USERNAME_PREFIX"
: prefix used for autogenerated django User’s username (default:"DGN_"
)"USER_USERNAME_SUFFIX"
: suffix used for autogenerated django User’s username. The special value"_$$random"
can be used (default:"_$$random"
)
Permissions¶
"PERMISSIONS"
dictionary: this setting controls theassign_object
method of aGroupMember
instance.- Each key controls a specific group type. Values are lists (or, in case of
"owner"
, also a dictionary) with a combination of permissions’ prefixes"view"
(view),"change"
(change),"delete"
(delete) characters. Obviously, a"view_modelname"
permission must be added to the model permissions. You can also add your custom permissions in form of<prefix>
where your permission is<prefix>_modelname
.
Valid keys are:
"owner"
: a list or a dictionary (with keys as roles’ codename attribute). This object-permissions are assigned directly to the user (default:['view', 'change', 'delete']
)"group"
: a string. This object-permissions are assigned to the related group (default:['view', 'change']
)"groups_upstream"
: a string. This object-permissions are assigned to the ancestors groups (default:['view']
)"groups_downstream"
: a string. This object-permissions are assigned to the descendants groups (default:[]
)"groups_siblings"
: a string. This object-permissions are assigned to the siblings groups (default:['view']
)
Note
The four special permission names "add"
, "view"
, "change"
, and "delete"
are translated to <permission>_<model_name>
string during permission’s name lookup.
This allows to use a standard permission policy (view, change, delete) but also allows to use custom permissions.
An example of permissions assigned by role can be found on use cases.
Templates¶
TEMPLATE_STYLE
: name of the templates folder inside “groups_manager”. By default is"bootstrap3"
, this means that templates are searched inside folder “groups_manager/bootstrap3”
Slugify function¶
SLUGIFY_FUNCTION
: function used to slugify codenames;SLUGIFY_USERNAME_FUNCTION
: function used to slugify auto-created usernames.
Note
Prior to 1.1.0, the default function was awesome-slugify. Due to its licence, it cannot be distributed with django-groups-manager.
By default Django’s slugify is used, with conversion to lower and, only for username, _ as separator.
To use a different function with it’s own parameters, you can define a lambda function in settings (i.e. using awesome-slugify):
from slugify import slugify
GROUPS_MANAGER = {
'SLUGIFY_FUNCTION': lambda s: slugify(s, to_lower=True),
'SLUGIFY_USERNAME_FUNCTION': lambda s: slugify(s, to_lower=True, separator="_")
}
Defaults¶
Default values are:
GROUPS_MANAGER = {
# User and Groups sync settings
'AUTH_MODELS_SYNC': False,
'GROUP_NAME_PREFIX': 'DGM_',
'GROUP_NAME_SUFFIX': '_$$random',
'USER_USERNAME_PREFIX': 'DGM_',
'USER_USERNAME_SUFFIX': '_$$random',
# Permissions
'PERMISSIONS': {
'owner': ['view', 'change', 'delete'],
'group': ['view', 'change'],
'groups_upstream': ['view'],
'groups_downstream': [],
'groups_siblings': ['view'],
},
# Templates
'TEMPLATE_STYLE': "bootstrap3",
'SLUGIFY_FUNCTION': lambda s: slugify(s).lower(),
'SLUGIFY_USERNAME_FUNCTION': lambda s: slugify(s).lower().replace('-', '_'),
}