# Django Utilitybox
![Logo](https://i.imgur.com/KXosc2D.png)
Managment software by 'On road Rescues': Stable Version.
## Installation
```bash
pip install django-utilitybox
```
## Usage
### Raise Exception
```python
from django_utilitybox.response import raise_response as rres
```
This utility makes it easier to return errors in DRF.
Giving a default message and a status.
The options are as follows.
| Class | Status | Message | Use cases |
| :-------- | :------- | :------- | :------- |
| `QueryParamNotFound` | 400 | `Queryparam '{field}' is required` | Used when a query param is not found in the url |
| `KwargNotFound ` | 400 | `Kwarg '{field}' is required` | Used when a kwarg is not found |
| `ModelNotFound` | 400 | `{field} don't exist` | Used when a model is not found |
| `CustomRaise` | 400 | ` ` | Se usa cuando se quiere mandar un mensaje personalizado |
#### Use cases
```python
class ResponseTest(APIView):
def get(self, *args, **kwargs):
data:dict = self.request.GET
param = data.get('case')
match param:
case '1': rres.QueryParamNotFound('id')
case '2': rres.KwargNotFound ('data')
case '3': rres.ModelNotFound('Rescue')
case '4': rres.CustomRaise('Custom message')
return Response({'message': 'Successful.'}, status=st.HTTP_200_OK)
```
### Returns
| Class | Status | Message |
| :-------- | :------- | :------- |
| `QueryParamNotFound` | 400 | `Queryparam 'id' is required` |
| `KwargNotFound ` | 400 | `Kwarg 'data' is required` |
| `ModelNotFound` | 400 | `Rescue don't exist` |
| `CustomRaise` | 400 | `Custom message` |
### Json returned
```json
HTTP 400 Bad Request
{
"status": "{message}"
}
```
### Modifiable parameters
WIP
***
## Used By
This project is used by the following companies:
- AETO Software
Raw data
{
"_id": null,
"home_page": "https://github.com/Josecolin99/...",
"name": "django-utilitybox",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Jose Angel Colin Najera",
"author_email": "josecolin99@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d9/5d/6eb2566b237c74eeeeaab2fefeb5e2fea3f3412e89569058aa2381f45636/django_utilitybox-0.0.2.tar.gz",
"platform": null,
"description": "# Django Utilitybox\r\n![Logo](https://i.imgur.com/KXosc2D.png)\r\n\r\n\r\nManagment software by 'On road Rescues': Stable Version.\r\n\r\n## Installation\r\n\r\n```bash\r\n pip install django-utilitybox\r\n```\r\n\r\n## Usage\r\n\r\n### Raise Exception\r\n\r\n```python\r\n from django_utilitybox.response import raise_response as rres\r\n```\r\n\r\nThis utility makes it easier to return errors in DRF.\r\nGiving a default message and a status.\r\nThe options are as follows.\r\n\r\n\r\n| Class | Status | Message | Use cases |\r\n| :-------- | :------- | :------- | :------- |\r\n| `QueryParamNotFound` | 400 | `Queryparam '{field}' is required` | Used when a query param is not found in the url |\r\n| `KwargNotFound ` | 400 | `Kwarg '{field}' is required` | Used when a kwarg is not found |\r\n| `ModelNotFound` | 400 | `{field} don't exist` | Used when a model is not found |\r\n| `CustomRaise` | 400 | ` ` | Se usa cuando se quiere mandar un mensaje personalizado |\r\n#### Use cases\r\n\r\n```python\r\n\t class ResponseTest(APIView):\r\n\t\tdef get(self, *args, **kwargs):\r\n\t\tdata:dict = self.request.GET\r\n\t\tparam = data.get('case')\r\n\t\tmatch param:\r\n\t\t\tcase '1': rres.QueryParamNotFound('id')\r\n\t\t\tcase '2': rres.KwargNotFound ('data')\r\n\t\t\tcase '3': rres.ModelNotFound('Rescue')\r\n\t\t\tcase '4': rres.CustomRaise('Custom message')\r\n\t\treturn Response({'message': 'Successful.'}, status=st.HTTP_200_OK)\r\n```\r\n### Returns\r\n| Class | Status | Message |\r\n| :-------- | :------- | :------- | \r\n| `QueryParamNotFound` | 400 | `Queryparam 'id' is required` |\r\n| `KwargNotFound ` | 400 | `Kwarg 'data' is required` |\r\n| `ModelNotFound` | 400 | `Rescue don't exist` |\r\n| `CustomRaise` | 400 | `Custom message` |\r\n\r\n### Json returned\r\n```json\r\nHTTP 400 Bad Request\r\n{\r\n\t\"status\": \"{message}\"\r\n}\r\n```\r\n### Modifiable parameters\r\n\r\nWIP\r\n\r\n***\r\n## Used By\r\n\r\nThis project is used by the following companies:\r\n\r\n- AETO Software\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "...",
"version": "0.0.2",
"project_urls": {
"Homepage": "https://github.com/Josecolin99/..."
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d95d6eb2566b237c74eeeeaab2fefeb5e2fea3f3412e89569058aa2381f45636",
"md5": "52e3357d232cef328af041b650ed61d3",
"sha256": "5017ebdffcdb7a92761efe599b5b9c720d4b031d815014908c6de6bbb977c4f3"
},
"downloads": -1,
"filename": "django_utilitybox-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "52e3357d232cef328af041b650ed61d3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5617,
"upload_time": "2024-05-08T21:41:45",
"upload_time_iso_8601": "2024-05-08T21:41:45.450606Z",
"url": "https://files.pythonhosted.org/packages/d9/5d/6eb2566b237c74eeeeaab2fefeb5e2fea3f3412e89569058aa2381f45636/django_utilitybox-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-08 21:41:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Josecolin99",
"github_project": "...",
"github_not_found": true,
"lcname": "django-utilitybox"
}