Skip to content

Commit

Permalink
started docs on DataListView
Browse files Browse the repository at this point in the history
setup the test for DataListView
  • Loading branch information
mmarcos committed Aug 22, 2017
1 parent b7c05ce commit ebc6ac8
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
59 changes: 57 additions & 2 deletions docs/reference.md
Expand Up @@ -203,6 +203,7 @@ template and is able to do filtering, sorting, pagination and linking.
**Extends**

* `arctic.generics.View`
* `arctic.mixins.ListMixin`
* `django.views.generic.ListView`

**Properties**
Expand Down Expand Up @@ -272,7 +273,61 @@ list of links with the format `('name', 'url')`, not connected to the table data

### `tool_links_icon`

default is fa-wrench. an icon displayed for the dropdown of multiple tool links or, if only one tool link set, it would be use as default icon.
default is fa-wrench. an icon displayed for the dropdown of multiple tool
links or, if only one tool link set, it would be use as default icon.


## DataListView

`class arctic.generics.DataListView`

This view is similar in features to ListView but displays tabular data from an
API source instead of a django model, it includes a default template and is
able to do filtering, sorting, pagination and linking.
The biggest difference here is that DataListView requires a RemoteDataSet
instance instead of a model.

A `RemoteDataSet` is a `QuerySet`-like object that acts as a gateway between
the `DataListView` and an API at the very least it needs to implement the
following:

- `url_template` property with optional `{filters}`, `{fields}`, `{order}` or
`{paginate}` format paramenters, which in turn can be customized with their
own templates.

- `get()` method which accepts two parameters, by default `start` and `stop` or,
if using the `offset_limit` decorator then `offset` and `limit`. This method is
responsible to connect to the API with the `url_template` and fetch the data
needed to populate the list.

Example:

from arctic.utils import RemoteDataSet, offset_limit

class CountriesDataSet(RemoteDataSet):
url_template = 'http://example.com/countries-api/?{filters}{fields}{order}{paginate}'
order_template = '&order_by={}'

@offset_limit
def get(self, offset, limit):
r = urllib.request.urlopen((self.get_url(offset, limit)))
data = r.read().decode("utf-8")
return json.loads(data)

class CountryListView(DataListView):
dataset = CountriesDataSet()
...

**Extends**

* `arctic.generics.TemplateView`
* `arctic.mixins.ListMixin`

**Properties**

### `fields`



## FormView

Expand Down Expand Up @@ -396,7 +451,7 @@ will check if it returns `True` or `False`. Note that on multiple
permissions, only one permission is needed to validate a user's role.


## LayoutMixin
## FormMixin

### `layout`

Expand Down
38 changes: 38 additions & 0 deletions tests/test_generics/test_data_list_view.py
@@ -0,0 +1,38 @@
import pytest

from django.core.urlresolvers import reverse


@pytest.mark.django_db
class TestDataListView(object):
"""
Test ListView using ArticleListView from example application
"""
def _request(self, admin_client):
response = admin_client.get(reverse('countries-list'))
assert response.status_code == 200
return response

def _assert_list_items_len(self, response, length):
assert 'list_items' in response.context_data
assert len(response.context_data['list_items']) == length

# def test_paginated_items(self, admin_client):
# """
# Paginated List view
# """
# response = self._request(admin_client)
# self._assert_list_items_len(response, 250)

# assert response.context_data['page_obj'].paginator.num_pages == 20

# def test_simple_search_form(self, admin_client):
# # empty search, return all
# response = admin_client.get(reverse('countries-list'),
# {'search': ''})
# assert len(response.context_data['list_items']) == 150

# # search filled, filter content
# response = admin_client.get(reverse('countries-list'),
# {'search': 'af'})
# assert len(response.context_data['list_items']) == 3

0 comments on commit ebc6ac8

Please sign in to comment.