mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-04-11 17:11:00 +00:00
Resolved #209 -- Added pagination
This commit is contained in:
parent
9d1bcfee6a
commit
b0d2325c43
3 changed files with 35 additions and 5 deletions
|
|
@ -9,12 +9,15 @@ $(function () {
|
|||
term: params.term,
|
||||
page: params.page,
|
||||
field_id: field_id
|
||||
};
|
||||
}
|
||||
},
|
||||
processResults: function (data, page) {
|
||||
return {
|
||||
results: data.results
|
||||
};
|
||||
return {
|
||||
results: data.results,
|
||||
pagination: {
|
||||
more: data.more
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ class AutoResponseView(BaseListView):
|
|||
'text': "foo",
|
||||
'id': 123
|
||||
}
|
||||
]
|
||||
],
|
||||
'more': true
|
||||
}
|
||||
|
||||
"""
|
||||
|
|
@ -48,6 +49,7 @@ class AutoResponseView(BaseListView):
|
|||
}
|
||||
for obj in context['object_list']
|
||||
],
|
||||
'more': context['page_obj'].has_next()
|
||||
})
|
||||
|
||||
def get_queryset(self):
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ from django.core import signing
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.utils.encoding import smart_text
|
||||
|
||||
from django_select2.forms import ModelSelect2Widget
|
||||
from tests.testapp.forms import AlbumModelSelect2WidgetForm
|
||||
from tests.testapp.models import Genre
|
||||
|
||||
|
||||
class TestAutoResponseView(object):
|
||||
|
|
@ -41,3 +43,26 @@ class TestAutoResponseView(object):
|
|||
url = reverse('django_select2-json')
|
||||
response = client.get(url, {'field_id': field_id, 'term': artist.title})
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_pagination(self, genres, client):
|
||||
url = reverse('django_select2-json')
|
||||
widget = ModelSelect2Widget(
|
||||
max_results=10,
|
||||
model=Genre,
|
||||
search_fields=['title__icontains']
|
||||
)
|
||||
widget.render('name', None)
|
||||
field_id = signing.dumps(id(widget))
|
||||
|
||||
response = client.get(url, {'field_id': field_id, 'term': ''})
|
||||
assert response.status_code == 200
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
assert data['more'] is True
|
||||
|
||||
response = client.get(url, {'field_id': field_id, 'term': '', 'page': 1000})
|
||||
assert response.status_code == 404
|
||||
|
||||
response = client.get(url, {'field_id': field_id, 'term': '', 'page': 'last'})
|
||||
assert response.status_code == 200
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
assert data['more'] is False
|
||||
|
|
|
|||
Loading…
Reference in a new issue