Skip to main content

Package of libraries for Django projects

Project description

For django projects

Classes and functions to create django projects with Bootstrap Css Framework

N|Solid

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_boolhtmlSafeString: 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.

  • fieldname_texthtml ➝ str: Return HABILITADO if fieldname value is True, else return DESHABILITADO.

  • fieldname_yesorno ➝ str: Return 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 ..

  • fieldname_money ➝ str: Return fieldname_unlocalize with settings.SIMBOLO_MONEDA, example $10.50.

  • fieldname_integer ➝ int: Return the fieldname value rounded.

django.db.models.FileField:

  • fieldname_iconSafeString: Returns Fontawesome icon according to file extension.

  • fieldname_a_tagSafeString: 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 called settings.CONSTRAINT_MSG in the Django application configurations are detected.

License

MIT

Free Software, Hell Yeah!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

for_django_projects-1.4.6.tar.gz (463.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

for_django_projects-1.4.6-py3-none-any.whl (469.3 kB view details)

Uploaded Python 3

File details

Details for the file for_django_projects-1.4.6.tar.gz.

File metadata

  • Download URL: for_django_projects-1.4.6.tar.gz
  • Upload date:
  • Size: 463.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.6

File hashes

Hashes for for_django_projects-1.4.6.tar.gz
Algorithm Hash digest
SHA256 2118a9ce4a75fd61e13265c3a634e9ca08b73dbda5b5947e568ed543a5b7351e
MD5 2fd8d2b5c7f189ff6a12feaea82f31ef
BLAKE2b-256 5a743a4a2477c605bc418d3602b0c946efe01f7e8215bc3de5116538d585f993

See more details on using hashes here.

File details

Details for the file for_django_projects-1.4.6-py3-none-any.whl.

File metadata

File hashes

Hashes for for_django_projects-1.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e0e953c2f49daa16b5f665825791fa3890dd3f278cfa0249cca0b4c1a37d7c51
MD5 ca73ecbf9762a4a985f53095d22b702f
BLAKE2b-256 2fc489953a2b8115604c91f7dc492314ed37c59147d6f8d3ebfaf2d7f97dd30b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page