# DFPermission
### Installation
```text
pip install df-permission
```
### Configuration
```pycon
INSTALLED_APPS = [
...,
'df_permission'
]
```
### Generate permissions
For model fields:
```text
./manage.py generate_model_field_permissions
```
For serializer fields (not include model fields):
```text
./manage.py generate_serializer_field_permissions
```
### Attributes
`df_method`
- Method of action
- Valid values are `create`, `update`, `retrieve`, `list`, `destroy`
```pycon
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_method = 'create'
...
```
or
```pycon
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_method = DFMethods.CREATE
...
```
`df_model`
- Model
```pycon
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_model = MyModel
...
```
`df_fields`
- Fields
```pycon
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_fields = ['field1', 'field2', ...]
...
```
`df_permissions`
- Permissions
- type: `string`, `list`, `tuple`
```pycon
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_permissions = ['permission1', 'permission2', ...]
...
```
or
```pycon
class MyView(CreateAPIView):
permission_classes = [DFPermission]
df_permissions = 'permission1'
...
```
`df_allow_superuser`
- Allow superuser if value is True
- Type: `boolean`
- Default: `False`
### Methods
`get_df_permissions`
- Customize df_permissions
```pycon
class MyView(CreateAPIView):
permission_classes = [DFPermission]
def get_df_permissions(self):
# write your logic code
return # single permission or permissions
```
### How does it work?
First, find `df_permissions` attribute. If it
does not exist, find `get_df_permissions` method.
If it does not exist too, generate permissions.
First for this, collect fields that are permission
required. Find `df_fields`, if it exist. Else get
serializer class to get fields and get intersection
with model fields.
Then, generate required perms using fields and `df_method`.
Finally, user's permissions are checked.
Raw data
{
"_id": null,
"home_page": "",
"name": "df-permission",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "python,field,permission,field permission,django field",
"author": "Maxmudov Asliddin",
"author_email": "<asliddin750750@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/93/1c/45889dec3c5dcb35fe49c098ce406fef26a7c95c8ec18cc78125c1bae810/df-permission-0.1.9.tar.gz",
"platform": null,
"description": "# DFPermission\n\n### Installation\n```text\npip install df-permission\n```\n\n### Configuration\n```pycon\nINSTALLED_APPS = [\n ...,\n 'df_permission'\n]\n```\n\n### Generate permissions\nFor model fields:\n```text\n./manage.py generate_model_field_permissions\n```\n\nFor serializer fields (not include model fields):\n```text\n./manage.py generate_serializer_field_permissions\n```\n\n### Attributes\n\n`df_method`\n- Method of action\n- Valid values are `create`, `update`, `retrieve`, `list`, `destroy`\n\n```pycon\nclass MyView(CreateAPIView):\n permission_classes = [DFPermission]\n df_method = 'create'\n ...\n```\n\nor\n\n```pycon\nclass MyView(CreateAPIView):\n permission_classes = [DFPermission]\n df_method = DFMethods.CREATE\n ...\n```\n\n`df_model`\n- Model\n\n```pycon\nclass MyView(CreateAPIView):\n permission_classes = [DFPermission]\n df_model = MyModel\n ...\n```\n\n`df_fields`\n- Fields\n\n```pycon\nclass MyView(CreateAPIView):\n permission_classes = [DFPermission]\n df_fields = ['field1', 'field2', ...]\n ...\n```\n\n`df_permissions`\n- Permissions\n- type: `string`, `list`, `tuple`\n\n```pycon\nclass MyView(CreateAPIView):\n permission_classes = [DFPermission]\n df_permissions = ['permission1', 'permission2', ...]\n ...\n```\n\nor\n\n```pycon\nclass MyView(CreateAPIView):\n permission_classes = [DFPermission]\n df_permissions = 'permission1'\n ...\n```\n\n`df_allow_superuser`\n- Allow superuser if value is True\n- Type: `boolean`\n- Default: `False`\n\n### Methods\n\n`get_df_permissions`\n- Customize df_permissions\n\n```pycon\nclass MyView(CreateAPIView):\n permission_classes = [DFPermission]\n \n def get_df_permissions(self):\n # write your logic code\n return # single permission or permissions\n```\n\n### How does it work?\nFirst, find `df_permissions` attribute. If it \ndoes not exist, find `get_df_permissions` method. \nIf it does not exist too, generate permissions.\n\nFirst for this, collect fields that are permission \nrequired. Find `df_fields`, if it exist. Else get \nserializer class to get fields and get intersection\nwith model fields.\n\nThen, generate required perms using fields and `df_method`.\n\nFinally, user's permissions are checked.\n",
"bugtrack_url": null,
"license": "",
"summary": "Django field permission package",
"version": "0.1.9",
"split_keywords": [
"python",
"field",
"permission",
"field permission",
"django field"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "242c9a3409ecb9d375103cd3e168e9523fefe9caf4fc6456f2824fee53dc4bb8",
"md5": "4494858b37ef5ab8ff598651df4879b0",
"sha256": "8e9645813edbd424a494f54ccd2ef41aad4e02ca14a22ec9e4020701877a035a"
},
"downloads": -1,
"filename": "df_permission-0.1.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4494858b37ef5ab8ff598651df4879b0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7426,
"upload_time": "2023-04-09T11:35:05",
"upload_time_iso_8601": "2023-04-09T11:35:05.040271Z",
"url": "https://files.pythonhosted.org/packages/24/2c/9a3409ecb9d375103cd3e168e9523fefe9caf4fc6456f2824fee53dc4bb8/df_permission-0.1.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "931c45889dec3c5dcb35fe49c098ce406fef26a7c95c8ec18cc78125c1bae810",
"md5": "5e49494de8866bcda729f3f97632c174",
"sha256": "3226619641b7eddc8ee66ea710b434932d7fb83e6da8ca8847ed7ea9863cfda6"
},
"downloads": -1,
"filename": "df-permission-0.1.9.tar.gz",
"has_sig": false,
"md5_digest": "5e49494de8866bcda729f3f97632c174",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5804,
"upload_time": "2023-04-09T11:35:07",
"upload_time_iso_8601": "2023-04-09T11:35:07.169941Z",
"url": "https://files.pythonhosted.org/packages/93/1c/45889dec3c5dcb35fe49c098ce406fef26a7c95c8ec18cc78125c1bae810/df-permission-0.1.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-09 11:35:07",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "df-permission"
}