# For django projects
## _Classes and functions to create django projects with Bootstrap Css Framework_
[](https://devarech.me)
## Installation
Requires [Django](https://www.djangoproject.com/) v2.2+ and [Python](https://www.python.org/) v3.6+ to run.
Add apps in INSTALLED_APPS:
```sh
INSTALLED_APPS = [
...
'for_django_projects.form_utils',
'for_django_projects.pwa'
...
]
```
Add in settings.py:
```sh
SIMBOLO_MONEDA = '$'
URL_GENERAL = 'http://your_domain.com'
CONSTRAINT_MSG = {} #dict of name of constraints as key and error message as value
```
# Classes
#### _CustomValueDb_
Inherited from `django.db.models.Value`, automatically adds data type in output_field attribute.
#### _NormalModel_
Inherited from `django.db.models.Model`, adds fields **(in all models inheriting from NormalModel)** according to the field type.
Example: If there is a field of type BooleanField with the name `is_enabled`, then the `is_enabled_boolhtml` attribute will be added with a [Fontawesome](https://fontawesome.com/search?m=free) icon named **fa-check-circle**, otherwise **fa-times-circle** is added.
### Attributes to be added in objects inherited from _NormalModel_ according to field type:
#### django.db.models.BooleanField:
- `fieldname_boolhtml` ➝ [SafeString](https://docs.djangoproject.com/es/2.2/_modules/django/utils/safestring/#mark_safe): Return `<i class="fas fas fa-clock text-info"></i>` if `fieldname` value is `None`, `<i class="fas fa-check-circle text-success"></i>` if is `True` or `<i class="fas fa-times-circle text-secondary"></i>` if is `False`.
<br><br>
- `fieldname_texthtml ➝ str`: Return `HABILITADO` if `fieldname` value is `True`, else return `DESHABILITADO`.
<br><br>
- `fieldname_yesorno ➝ str`: Return `Sí` if `fieldname` value is `True`, else return `No`.
#### django.db.models.DecimalField:
- `fieldname_unlocalize ➝ str`: Returns the same value but replacing the comma `,` character with dot `.`.
<br><br>
- `fieldname_money ➝ str`: Return `fieldname_unlocalize` with `settings.SIMBOLO_MONEDA`, example `$10.50`.
<br><br>
- `fieldname_integer ➝ int`: Return the `fieldname` value rounded.
#### django.db.models.FileField:
- `fieldname_icon` ➝ [SafeString](https://docs.djangoproject.com/es/2.2/_modules/django/utils/safestring/#mark_safe): Returns [Fontawesome](https://fontawesome.com/search?m=free) icon according to file extension.
<br><br>
- `fieldname_a_tag` ➝ [SafeString](https://docs.djangoproject.com/es/2.2/_modules/django/utils/safestring/#mark_safe): Returns `<a target="_blank" href="URL">{fieldname_icon} descargar</a>`.
<br><br>
- `fieldname_is_image ➝ bool`.
<br><br>
- `fieldname_extension ➝ str`.
#### _ModeloBase_
Inherited from `NormalModel`, add new fields in model as `fecha_registro -> models.DateTimeField` and `sin_eliminar -> models.BooleanField`.
#### _FormException_
Custom exception that is used to handle errors in forms in a Django application.
The class constructor accepts three parameters: `form`, `prefix`, and `suffix`. form can be a Django form object or a list/tuple of Django form objects. prefix and suffix are used to add a prefix and suffix respectively to the form field names in case a specific field needs to be identified that has generated an error.
In the constructor, the superclass `Exception` constructor is called to initialize the error message. Then, a check is performed to determine whether form is a list/tuple or a single Django form object.
If form is a list/tuple, each form object is looped over and information about the errors for each field is collected and added to a list called self.errors.
If form is a single Django form object, information about the field errors is collected and added to the self.errors list. In both cases, the provided prefix and suffix are used to identify the specific field that has generated the error.
Then, a dictionary self.dict_error is created that contains information about the form error. This dictionary has the following keys:
- `error`: a boolean value indicating whether there has been an error in the form.
- `form`: a list of dictionaries containing information about the form field errors. Each dictionary has two keys: the field name and an error message.
- `message`: a general error message that is displayed in case a specific field that has generated an error cannot be identified.
- `alerta`: an HTML text string containing custom alert messages. These messages are displayed in case specific errors that are defined in a dictionary called `settings.CONSTRAINT_MSG` in the Django application configurations are detected.
## License
MIT
**Free Software, Hell Yeah!**
Raw data
{
"_id": null,
"home_page": "https://github.com/jasmanysanchez/for-django-projects",
"name": "for-django-projects",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Jasmany Sanchez Mendez",
"author_email": "jasmanysanchez97@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/2f/a8/f6f6d76add50a854dd7ed32446b26a0f49764e52671168629f14392270f6/for-django-projects-1.3.1.tar.gz",
"platform": null,
"description": "# For django projects\r\n## _Classes and functions to create django projects with Bootstrap Css Framework_\r\n\r\n[](https://devarech.me)\r\n\r\n## Installation\r\n\r\nRequires [Django](https://www.djangoproject.com/) v2.2+ and [Python](https://www.python.org/) v3.6+ to run.\r\n\r\nAdd apps in INSTALLED_APPS:\r\n\r\n```sh\r\nINSTALLED_APPS = [\r\n ...\r\n 'for_django_projects.form_utils',\r\n 'for_django_projects.pwa'\r\n ...\r\n]\r\n```\r\n\r\nAdd in settings.py:\r\n\r\n```sh\r\nSIMBOLO_MONEDA = '$'\r\nURL_GENERAL = 'http://your_domain.com'\r\nCONSTRAINT_MSG = {} #dict of name of constraints as key and error message as value \r\n```\r\n\r\n# Classes\r\n#### _CustomValueDb_\r\nInherited from `django.db.models.Value`, automatically adds data type in output_field attribute.\r\n\r\n#### _NormalModel_\r\nInherited from `django.db.models.Model`, adds fields **(in all models inheriting from NormalModel)** according to the field type.\r\nExample: If there is a field of type BooleanField with the name `is_enabled`, then the `is_enabled_boolhtml` attribute will be added with a [Fontawesome](https://fontawesome.com/search?m=free) icon named **fa-check-circle**, otherwise **fa-times-circle** is added.\r\n### Attributes to be added in objects inherited from _NormalModel_ according to field type:\r\n#### django.db.models.BooleanField:\r\n- `fieldname_boolhtml` \u279d [SafeString](https://docs.djangoproject.com/es/2.2/_modules/django/utils/safestring/#mark_safe): Return `<i class=\"fas fas fa-clock text-info\"></i>` if `fieldname` value is `None`, `<i class=\"fas fa-check-circle text-success\"></i>` if is `True` or `<i class=\"fas fa-times-circle text-secondary\"></i>` if is `False`.\r\n<br><br>\r\n- `fieldname_texthtml \u279d str`: Return `HABILITADO` if `fieldname` value is `True`, else return `DESHABILITADO`.\r\n<br><br>\r\n- `fieldname_yesorno \u279d str`: Return `S\u00ed` if `fieldname` value is `True`, else return `No`.\r\n\r\n#### django.db.models.DecimalField:\r\n- `fieldname_unlocalize \u279d str`: Returns the same value but replacing the comma `,` character with dot `.`.\r\n<br><br>\r\n- `fieldname_money \u279d str`: Return `fieldname_unlocalize` with `settings.SIMBOLO_MONEDA`, example `$10.50`.\r\n<br><br>\r\n- `fieldname_integer \u279d int`: Return the `fieldname` value rounded.\r\n\r\n#### django.db.models.FileField:\r\n- `fieldname_icon` \u279d [SafeString](https://docs.djangoproject.com/es/2.2/_modules/django/utils/safestring/#mark_safe): Returns [Fontawesome](https://fontawesome.com/search?m=free) icon according to file extension.\r\n<br><br>\r\n- `fieldname_a_tag` \u279d [SafeString](https://docs.djangoproject.com/es/2.2/_modules/django/utils/safestring/#mark_safe): Returns `<a target=\"_blank\" href=\"URL\">{fieldname_icon} descargar</a>`.\r\n<br><br>\r\n- `fieldname_is_image \u279d bool`.\r\n<br><br>\r\n- `fieldname_extension \u279d str`.\r\n\r\n#### _ModeloBase_\r\nInherited from `NormalModel`, add new fields in model as `fecha_registro -> models.DateTimeField` and `sin_eliminar -> models.BooleanField`.\r\n\r\n#### _FormException_\r\nCustom exception that is used to handle errors in forms in a Django application.\r\n\r\nThe class constructor accepts three parameters: `form`, `prefix`, and `suffix`. form can be a Django form object or a list/tuple of Django form objects. prefix and suffix are used to add a prefix and suffix respectively to the form field names in case a specific field needs to be identified that has generated an error.\r\n\r\nIn the constructor, the superclass `Exception` constructor is called to initialize the error message. Then, a check is performed to determine whether form is a list/tuple or a single Django form object.\r\n\r\nIf form is a list/tuple, each form object is looped over and information about the errors for each field is collected and added to a list called self.errors.\r\n\r\nIf form is a single Django form object, information about the field errors is collected and added to the self.errors list. In both cases, the provided prefix and suffix are used to identify the specific field that has generated the error.\r\n\r\nThen, a dictionary self.dict_error is created that contains information about the form error. This dictionary has the following keys:\r\n\r\n- `error`: a boolean value indicating whether there has been an error in the form.\r\n- `form`: a list of dictionaries containing information about the form field errors. Each dictionary has two keys: the field name and an error message.\r\n- `message`: a general error message that is displayed in case a specific field that has generated an error cannot be identified.\r\n- `alerta`: an HTML text string containing custom alert messages. These messages are displayed in case specific errors that are defined in a dictionary called `settings.CONSTRAINT_MSG` in the Django application configurations are detected.\r\n\r\n## License\r\n\r\nMIT\r\n\r\n**Free Software, Hell Yeah!**\r\n\r\n\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Package of libraries for Django projects",
"version": "1.3.1",
"project_urls": {
"Homepage": "https://github.com/jasmanysanchez/for-django-projects"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2fa8f6f6d76add50a854dd7ed32446b26a0f49764e52671168629f14392270f6",
"md5": "27c1b1b437446d1f0dec7fec26b563d0",
"sha256": "1e38c4d28d4700b56494c776270d3b40fccfd650791ae2bcb9e0ae81b159757f"
},
"downloads": -1,
"filename": "for-django-projects-1.3.1.tar.gz",
"has_sig": false,
"md5_digest": "27c1b1b437446d1f0dec7fec26b563d0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 456854,
"upload_time": "2024-08-15T19:24:06",
"upload_time_iso_8601": "2024-08-15T19:24:06.568684Z",
"url": "https://files.pythonhosted.org/packages/2f/a8/f6f6d76add50a854dd7ed32446b26a0f49764e52671168629f14392270f6/for-django-projects-1.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-15 19:24:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jasmanysanchez",
"github_project": "for-django-projects",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "for-django-projects"
}