Skip to content

Readme improvements and fixed typos #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
Easily add mutually exclusive fields to Django forms.
## Install
### PyPI
```
```shell
pip install django-xor-formfields
```

### Source
```
```shell
python setup.py install
```

## Example mutually exclusive form field (TextInput & Select):
```
```python
from django import forms
from xorformfields.forms import MutuallyExclusiveValueField, MutuallyExclusiveRadioWidget

# with a widget inference
MutuallyExclusiveValueField(
fields=(forms.TypedChoiceField(choices=[(1,1), (2,2)], coerce=int),
Expand All @@ -30,26 +33,28 @@ MutuallyExclusiveValueField(
]))
```

## Using FileOrUrlField
## 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
`MutuallyExclusiveValueField` that allows users to upload files via a 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
normalization, normalization to a 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
```python
from xorformfields.forms import FileOrURLField

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 a URL
```
#### AWS note:
The `FileOrUrlField` supports a they keyword argument `no_aws_qs` which
The `FileOrURLField` supports a keyword argument `no_aws_qs` which
disables aws querystring authorization if using AWS via `django-storages`

## Tests & coverage!
to run the tests simply run:
```
```shell
DJANGO_SETTINGS_MODULE=xorformfields.test_settings django-admin.py test xorformfields
```

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

version='0.1.0',

description='Mutually Exclusive form field wigets for Django',
description='Mutually Exclusive form field widgets for Django',
long_description=long_description,
long_description_content_type='text/markdown',

url='https://github.com/dschep/django-mutuallyexclusive-formfields',

Expand Down
6 changes: 3 additions & 3 deletions xorformfields/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def clean(self, value):
Only allows for exactly 1 valid value to be submitted, this is what
gets returned by compress.

example to use directy (instead of using FileOrURLField):
example to use directly (instead of using FileOrURLField):
MutuallyExclusiveValueField(
fields=(forms.TypedChoiceField(choices=[(1,1), (2,2)], coerce=int),
forms.IntegerField()))
Expand Down Expand Up @@ -108,10 +108,10 @@ class FileOrURLField(MutuallyExclusiveValueField):

def __init__(self, to=None, *args, **kwargs):
"""
Accepts EITHER a file or an URL.
Accepts EITHER a file or a URL.
The `to` parameter accepts 3 values:
None: default to_python, returns either url or file
'file': if an url is submited, download it into an inmemory object
'file': if an url is submitted, download it into an in-memory object
'url': uploads the file to default storage and returns the URL
The`upload_to` param must be set when to='url'
if using AWS, set no_aws_qs to disable querystring auth
Expand Down