Package of libraries for Django projects
Project description
For django projects
Classes and functions to create django projects with Bootstrap Css Framework
Installation
Requires Django v2.2+ and Python v3.6+ to run.
Add apps in INSTALLED_APPS:
INSTALLED_APPS = [
...
'for_django_projects.form_utils',
'for_django_projects.pwa'
...
]
Add in settings.py:
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 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: Return<i class="fas fas fa-clock text-info"></i>
iffieldname
value isNone
,<i class="fas fa-check-circle text-success"></i>
if isTrue
or<i class="fas fa-times-circle text-secondary"></i>
if isFalse
.fieldname_texthtml ➝ str
: ReturnHABILITADO
iffieldname
value isTrue
, else returnDESHABILITADO
.fieldname_yesorno ➝ str
: ReturnSí
iffieldname
value isTrue
, else returnNo
.
django.db.models.DecimalField:
fieldname_unlocalize ➝ str
: Returns the same value but replacing the comma,
character with dot.
.fieldname_money ➝ str
: Returnfieldname_unlocalize
withsettings.SIMBOLO_MONEDA
, example$10.50
.fieldname_integer ➝ int
: Return thefieldname
value rounded.
django.db.models.FileField:
fieldname_icon
➝ SafeString: Returns Fontawesome icon according to file extension.fieldname_a_tag
➝ SafeString: Returns<a target="_blank" href="URL">{fieldname_icon} descargar</a>
.fieldname_is_image ➝ bool
.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 calledsettings.CONSTRAINT_MSG
in the Django application configurations are detected.
License
MIT
Free Software, Hell Yeah!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file for-django-projects-1.3.1.tar.gz
.
File metadata
- Download URL: for-django-projects-1.3.1.tar.gz
- Upload date:
- Size: 456.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e38c4d28d4700b56494c776270d3b40fccfd650791ae2bcb9e0ae81b159757f |
|
MD5 | 27c1b1b437446d1f0dec7fec26b563d0 |
|
BLAKE2b-256 | 2fa8f6f6d76add50a854dd7ed32446b26a0f49764e52671168629f14392270f6 |