Skip to content

Commit

Permalink
Merge pull request #73 from wesokes/develop
Browse files Browse the repository at this point in the history
bug fix and add paginator
  • Loading branch information
somewes authored Aug 22, 2016
2 parents e7881a0 + d12fcc4 commit e27fa4a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Requirements
------------
* Python 2.7
* Python 3.3, 3.4
* Django 1.6+
* Django 1.7+
* Postgres 9.3+

Installation
Expand Down
5 changes: 5 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Release Notes
=============

v0.13.0
-------
* Add paginator class for json queryset
* No longer change '__' to '.' in filters. Just use a '.' where needed and use django 1.9's json field support for querying json fields

v0.12.0
-------
* Run tests with django 1.10
Expand Down
15 changes: 15 additions & 0 deletions querybuilder/paginator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.core.paginator import Paginator


class QuerybuilderPaginator(Paginator):

def page(self, number):
"""
Returns a Page object for the given 1-based page number.
querybuilder expects the two numbers to be limit and offset. The limit will always be
the per_page value and the offset will be the bottom number
"""
number = self.validate_number(number)
bottom = (number - 1) * self.per_page
top = self.per_page
return self._get_page(self.object_list[bottom:top], number, self)
18 changes: 8 additions & 10 deletions querybuilder/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,22 +352,16 @@ def build_where_part(self, wheres):
operator = '='

# break apart the field name on double underscores
# TODO: do not convert the first double underscore to a .
field_parts = field_name.split('__')
if len(field_parts) > 1:
# get the operator based on the last element split from the double underscores
operator_str = field_parts[-1]
operator = self.get_condition_operator(operator_str)
if operator is None:
operator = '='
field_name = '.'.join(field_parts)
field_name = '__'.join(field_parts)
else:
field_name = '.'.join(field_parts[:-1])

# if there is more than one double underscore, make the first one a dot
trimmed_field_parts = field_name.split('.')
if len(trimmed_field_parts) > 2:
field_name = '{0}.{1}'.format(trimmed_field_parts[0], '__'.join(trimmed_field_parts[1:]))
field_name = '__'.join(field_parts[:-1])

# check if we are comparing to null
if value is None:
Expand Down Expand Up @@ -2039,8 +2033,12 @@ def filter(self, *args, **kwargs):
parts = key.split('->')
if len(parts) == 2:
field_key_parts = parts[1].split('__')
key = '{0}->>\'{1}\''.format(parts[0], field_key_parts[0])
key = '__'.join([key] + field_key_parts[1:])

if len(field_key_parts) == 1:
key = '{0}->>\'{1}\''.format(parts[0], field_key_parts[0])
else:
key = '{0}->>\'{1}\''.format(parts[0], '__'.join(field_key_parts[0:-1]))
key = '__'.join([key, field_key_parts[-1]])
value = six.u('{0}'.format(value))
if hasattr(value, 'id'):
key = '{0}_id'.format(key)
Expand Down
2 changes: 1 addition & 1 deletion querybuilder/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.12.0'
__version__ = '0.13.0'
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def get_version():
'Framework :: Django :: 1.7',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Development Status :: 5 - Production/Stable',
],
license='MIT',
Expand Down

0 comments on commit e27fa4a

Please sign in to comment.