Mutually Exclusive form field wigets for Django
Project description
# Mutually Exclusive Form Fields
[](https://travis-ci.org/dschep/django-xor-formfields)
Easily add mutually exclusive fields to Django forms.
## Install
### PyPI
```
pip install django-xor-formfields
```
### Source
```
python setup.py install
```
## Example mutually exclusive form field (TextInput & Select):
```
# with a widget inference
MutuallyExclusiveValueField(
fields=(forms.TypedChoiceField(choices=[(1,1), (2,2)], coerce=int),
forms.IntegerField()))
# manual widget creation (allows for the placeholder attr & other customization)
MutuallyExclusiveValueField(
fields=(forms.IntegerField(), forms.IntegerField()),
widget=MutuallyExclusiveRadioWidget(widgets=[
forms.Select(choices=[(1,1), (2,2)]),
forms.TextInput(attrs={'placeholder': 'Enter a number'}),
]))
```
## Using FileOrUrlField
This library also includes a more complete field that inherits from
`MutuallyExclusiveValueField` that allows users to upload files via an URL or a
file upload. The field accepts a `to` parameter accepting the following values:
`None, 'url', 'file'`. This value causes the field to perform either no
normalization, normalizatoin to an url (by storing uploaded files as media) or
to a file (by downloading urls to an `InMemoryUploadedFile`).
### Example:
```
FileOrUrlField(None) # returns UploadedFile objects or URL based on user input
FileOrUrlField(to='file') # always validates to an UploadedFile
FileOrUrlField(to='url', upload_to='foobar') # always validates to an URL
```
#### AWS note:
The `FileOrUrlField` supports a they keyword argument `no_aws_qs` which
disables aws querystring authorization if using AWS via `django-storages`
## Tests & coverage!
to run the tests simply run:
```
DJANGO_SETTINGS_MODULE=xorformfields.test_settings django-admin.py test xorformfields
```
Coverage results are available here: https://dschep.github.io/django-xor-formfields/htmlcov/
[](https://travis-ci.org/dschep/django-xor-formfields)
Easily add mutually exclusive fields to Django forms.
## Install
### PyPI
```
pip install django-xor-formfields
```
### Source
```
python setup.py install
```
## Example mutually exclusive form field (TextInput & Select):
```
# with a widget inference
MutuallyExclusiveValueField(
fields=(forms.TypedChoiceField(choices=[(1,1), (2,2)], coerce=int),
forms.IntegerField()))
# manual widget creation (allows for the placeholder attr & other customization)
MutuallyExclusiveValueField(
fields=(forms.IntegerField(), forms.IntegerField()),
widget=MutuallyExclusiveRadioWidget(widgets=[
forms.Select(choices=[(1,1), (2,2)]),
forms.TextInput(attrs={'placeholder': 'Enter a number'}),
]))
```
## Using FileOrUrlField
This library also includes a more complete field that inherits from
`MutuallyExclusiveValueField` that allows users to upload files via an URL or a
file upload. The field accepts a `to` parameter accepting the following values:
`None, 'url', 'file'`. This value causes the field to perform either no
normalization, normalizatoin to an url (by storing uploaded files as media) or
to a file (by downloading urls to an `InMemoryUploadedFile`).
### Example:
```
FileOrUrlField(None) # returns UploadedFile objects or URL based on user input
FileOrUrlField(to='file') # always validates to an UploadedFile
FileOrUrlField(to='url', upload_to='foobar') # always validates to an URL
```
#### AWS note:
The `FileOrUrlField` supports a they keyword argument `no_aws_qs` which
disables aws querystring authorization if using AWS via `django-storages`
## Tests & coverage!
to run the tests simply run:
```
DJANGO_SETTINGS_MODULE=xorformfields.test_settings django-admin.py test xorformfields
```
Coverage results are available here: https://dschep.github.io/django-xor-formfields/htmlcov/
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
Built Distribution
Close
Hashes for django-xor-formfields-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43210e6f465e7f5e4433dba80311ab1e7cdb3044b8bc1dd621bfbe96c9d518fb |
|
MD5 | b4b95a20caf88a6dd70d1745a8d99aba |
|
BLAKE2b-256 | 14a55467e0faf2f1a339ee2a43fa056aac1629209252e9140fb77fcae7f8dd00 |
Close
Hashes for django_xor_formfields-0.1.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 259415366062ee3b790e7ac7ddbec7606c68e507d422fb565cf3d01aa3cf4e48 |
|
MD5 | c04e213289e7fbd72dfc252176bbe1b6 |
|
BLAKE2b-256 | 7a8f43b04a24b006689c04240d399decc46ce904e1a824cc9fc80bc236e19490 |