Layrz forms and tools for Python
Project description
Form tools - Layrz
Managed by Golden M, Inc.
Motivation
This project is a collection of tools that we use to make django developers life easier. I hope you find them useful too.
Usage
The idea is simple, replace the django forms to a more easier way to use them. Also provide the ability to return the errors key to support i18n.
import layrz_forms as forms
class ExampleForm(forms.Form):
""" Example form """
id_test = forms.IdField(required=True)
email_text = forms.EmailField(required=True)
json_list_test = forms.JsonField(required=True, datatype=list)
json_dict_test = forms.JsonField(required=True, datatype=dict)
int_test = forms.NumberField(required=True, datatype=int, min_value=0, max_value=5)
float_test = forms.NumberField(required=True, datatype=float, min_value=0, max_value=5)
bool_test = forms.BooleanField(required=True)
plain_text_test = forms.CharField(required=True, empty=False)
empty_text_test = forms.CharField(required=True, empty=True)
range_text_test = forms.CharField(required=True, empty=False, min_length=5, max_length=10)
def clean_func1(self):
""" Print clean """
self.add_errors(key='clean1', code='error1')
self.add_errors(key='clean1', code='error2')
def clean_func2(self):
self.add_errors(key='clean2', code='error1')
if __name__ == '__main__':
obj = {
'id_test': 1,
'email_text': 'example@goldenmcorp.com',
'json_dict_test': {
'hola': 'mundo'
},
'json_list_test': ['hola mundo'],
'int_test': 5,
'float_test': 4.5,
'bool_test': True,
'plain_text_test': 'hola mundo',
'empty_text_test': 'hola',
'range_text_test': 'hola'
}
form = ExampleForm(obj)
print('form.is_valid():', form.is_valid())
#> form.is_valid(): None
print('form.errors():', form.errors())
#> form.errors(): {'rangeTextTest': [{'code': 'minLength', 'expected': 5, 'received': 4}], 'clean1': [{'code': 'error1'}, {'code': 'error2'}], 'clean2': [{'code': 'error1'}]}
Work with us
Golden M is a software/hardware development company what is working on a new, innovative and disruptive technologies.
For more information, contact us at sales@goldenm.com
License
This project is under MIT License, for more information, check out the LICENCE
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
Built Distribution
File details
Details for the file layrz-forms-2.0.1.tar.gz
.
File metadata
- Download URL: layrz-forms-2.0.1.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ecc260e7aa1c30378cbf3c72cd850533b68b45bfbd2ead4b8264995c99b4c0a |
|
MD5 | 4f37778747a54fdfffcba08b9593a393 |
|
BLAKE2b-256 | 91fe23587c5b17055a9a9391f86c027d7aacd641cdb7763d3140c43b6f473278 |
File details
Details for the file layrz_forms-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: layrz_forms-2.0.1-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a79264e57166c0d5b3e95e68e0f77656e8c7f41d82aa3bb55ccd011b9a855e5 |
|
MD5 | 2ebb546d05a40f4c10e84fde1dc892e2 |
|
BLAKE2b-256 | 82a92939b983d7efcec89e73a5c15a610e53500c79517ed4bc7086ba690bbdee |