Skip to content

Commit

Permalink
fixed flake8 violations and fixed build for newer sqlalchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
miki725 committed Jan 26, 2017
1 parent bed1c5d commit 434886e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pip-log.txt
.cache
.coverage
.tox
.venv
nosetests.xml
htmlcov

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ check: lint clean-build clean-pyc clean-test test

release: clean
python setup.py sdist upload
python setup.py bdist_wheel upload

dist: clean
python setup.py sdist
python setup.py bdist_wheel
ls -l dist
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def read(fname):
]

test_requirements = (
read('requirements.txt').splitlines()
+ read('requirements-dev.txt').splitlines()[1:]
read('requirements.txt').splitlines() +
read('requirements-dev.txt').splitlines()[1:]
)

setup(
Expand Down
5 changes: 3 additions & 2 deletions tests/backends/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def test_filter(self, alchemy_db):

filtered = backend.filter()

assert six.text_type(filtered) == (
sql = six.text_type(filtered)
assert sql == (
'SELECT one_to_one_place.id AS one_to_one_place_id, '
'one_to_one_place.name AS one_to_one_place_name, '
'one_to_one_place.address AS one_to_one_place_address \n'
Expand All @@ -76,7 +77,7 @@ def test_filter(self, alchemy_db):
'ON one_to_one_restaurant.place_id = one_to_one_place.id '
'JOIN one_to_one_waiter '
'ON one_to_one_waiter.restaurant_id = one_to_one_restaurant.place_id '
'\nWHERE one_to_one_waiter.name = :name_1'
'\nWHERE one_to_one_waiter.name ={}'.format(sql.rsplit('=', 1)[-1])
)

def _test_build_clause(self, alchemy_db, name, lookup, value, expected, is_negated=False):
Expand Down
1 change: 1 addition & 0 deletions url_filter/filtersets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class FilterKeyValidator(RegexValidator):
'It must be `name[__<relation>]*[__<lookup_method>][!]`.'
)


filter_key_validator = FilterKeyValidator()


Expand Down
12 changes: 7 additions & 5 deletions url_filter/filtersets/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@
__all__ = ['SQLAlchemyModelFilterSet']


_STRING = lambda field, column: forms.CharField(max_length=column.type.length)
def _string(field, column):
return forms.CharField(max_length=column.type.length)


SQLALCHEMY_FIELD_MAPPING = SubClassDict({
BIGINT: forms.IntegerField,
BigInteger: forms.IntegerField,
Integer: forms.IntegerField,
Boolean: partial(forms.BooleanField, required=False),
CHAR: _STRING,
CLOB: _STRING,
CHAR: _string,
CLOB: _string,
DATE: forms.DateTimeField,
Date: forms.DateField,
DateTime: forms.DateTimeField,
Expand All @@ -52,9 +54,9 @@
INTEGER: forms.IntegerField,
Numeric: forms.IntegerField,
SMALLINT: forms.IntegerField,
String: _STRING,
String: _string,
TIMESTAMP: forms.DateTimeField,
VARCHAR: _STRING,
VARCHAR: _string,
})


Expand Down
16 changes: 12 additions & 4 deletions url_filter/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,34 @@ class MinLengthValidator(_MinLengthValidator):
"""
Customer Django min length validator with better-suited error message
"""
compare = lambda self, a, b: a < b
clean = lambda self, x: len(x)
code = 'min_length'
message = ungettext_lazy(
'Ensure this value has at least %(limit_value)d items (it has %(show_value)d).',
'Ensure this value has at least %(limit_value)d items (it has %(show_value)d).',
'limit_value'
)

def compare(self, a, b):
return a < b

def clean(self, x):
return len(x)


@deconstructible
class MaxLengthValidator(_MaxLengthValidator):
"""
Customer Django max length validator with better-suited error message
"""
compare = lambda self, a, b: a > b
clean = lambda self, x: len(x)
code = 'max_length'
message = ungettext_lazy(
'Ensure this value has at most %(limit_value)d items (it has %(show_value)d).',
'Ensure this value has at most %(limit_value)d items (it has %(show_value)d).',
'limit_value'
)

def compare(self, a, b):
return a > b

def clean(self, x):
return len(x)

0 comments on commit 434886e

Please sign in to comment.