Skip to content

Commit 121ecd0

Browse files
authored
Merge pull request #25 from mehdipourfar/master
Use psycopg2-binary in order to remove Django warnings and fix a typo in docs
2 parents 10ed046 + 4f94272 commit 121ecd0

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
matrix:
1313
- DJANGO='1.11'
1414
- DJANGO='2.0'
15+
- DJANGO='2.1'
1516

1617
matrix:
1718
include:

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Define a type and add it to a model:
2222

2323
```python
2424
from django.db import models
25-
from postgres_composite_type import CompositeType
25+
from postgres_composite_types import CompositeType
2626

2727
class Address(CompositeType):
2828
"""An address."""
@@ -144,6 +144,17 @@ Lookups and indexes are not implemented yet
144144
([bug #9](https://github.com/danni/django-postgres-composite-types/issues/9),
145145
[bug #10](https://github.com/danni/django-postgres-composite-types/issues/10)).
146146

147+
Running Tests
148+
-------------------
149+
Clone the repository, go to it's base directory and run the following commands.
150+
151+
pip install tox
152+
tox
153+
154+
Or if you want a specific environment
155+
156+
tox -e py35-dj2.0
157+
147158
Authors
148159
-------
149160

postgres_composite_types/forms.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@
3636
import logging
3737
from collections import OrderedDict
3838

39-
from django import forms
39+
from django import VERSION, forms
4040
from django.contrib.postgres.utils import prefix_validation_error
4141
from django.utils.translation import ugettext as _
4242

4343
from . import CompositeType
4444

4545
LOGGER = logging.getLogger(__name__)
4646

47+
DJANGO21 = VERSION >= (2, 1)
48+
4749

4850
class CompositeBoundField(forms.BoundField):
4951
"""
@@ -144,9 +146,13 @@ def clean(self, value):
144146
try:
145147
cleaned_data[name] = field.clean(value.get(name))
146148
except forms.ValidationError as error:
149+
if DJANGO21:
150+
prefix = '%(label)s:'
151+
else:
152+
prefix = '%(label)s: '
147153
errors.append(prefix_validation_error(
148154
error, code='field_invalid',
149-
prefix='%(label)s: ', params={'label': field.label}))
155+
prefix=prefix, params={'label': field.label}))
150156
if errors:
151157
raise forms.ValidationError(errors)
152158
value = self.model(**cleaned_data)
@@ -218,6 +224,10 @@ def value_from_datadict(self, data, files, name):
218224
for subname, widget in self.widgets.items()
219225
}
220226

227+
def value_omitted_from_data(self, data, files, name):
228+
prefix = '{}-'.format(name)
229+
return not any(key.startswith(prefix) for key in data)
230+
221231
def id_for_label(self, id_):
222232
"""
223233
Wrapper around the field widget's `id_for_label` method.

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Django >= 1.11
2-
psycopg2
2+
psycopg2-binary

tests/test_forms.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ def test_null_initial_data(self):
122122
""",
123123
str(form['simple_field']))
124124

125+
def test_value_omission_check_inside_widget(self):
126+
"""
127+
Assert that CompositeTypeWidget.value_omitted_from_data function
128+
will return False when passing valid data.
129+
"""
130+
form = self.SimpleForm()
131+
widget = form.fields['simple_field'].widget
132+
self.assertFalse(
133+
widget.value_omitted_from_data(
134+
data=self.simple_valid_data,
135+
files=[],
136+
name='simple_field',
137+
)
138+
)
139+
125140
# pylint:disable=invalid-name
126141
def assertHTMLContains(self, text, content, count=None, msg=None):
127142
"""

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
skipsdist = True
33
envlist =
4-
py{35,36}-dj{1.11,2.0}
4+
py{35,36}-dj{1.11,2.0,2.1}
55
pycodestyle,isort,pylint
66

77
[testenv]
@@ -15,6 +15,7 @@ deps =
1515
-rtest_requirements.in
1616
dj1.11: Django~=1.11.0
1717
dj2.0: Django~=2.0.0
18+
dj2.1: Django~=2.1.0
1819

1920
[testenv:flake8]
2021
usedevelop = True

0 commit comments

Comments
 (0)