Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
cosi2
: A Lino Così for Belgium (FR)¶
Side note: Code snippets (lines starting with >>>
) in this document get
tested as part of our development workflow. The following
initialization snippet tells you which demo project is being used in
this document.
>>> from lino import startup
>>> startup('lino_book.projects.cosi2.settings.demo')
>>> from lino.api.doctest import *
>>> ses = rt.login('robin')
Used in miscellaneous tested documents, e.g.
Miscellaneous¶
Person #115 is not a Partner¶
Person #115 (‘Altenberg Hans’) is not a Partner (master_key is <django.db.models.fields.related.ForeignKey: partner>)
>>> url = '/bs3/contacts/Person/115'
>>> test_client.force_login(rt.login('robin').user)
>>> res = test_client.get(url, REMOTE_USER='robin')
>>> print(res.status_code)
200
Slave tables with more than 15 rows¶
When you look at the detail window of Belgium in Lino Così then you see a list of all places in Belgium. This demo database contains exactly 48 entries:
>>> be = countries.Country.objects.get(isocode="BE")
>>> be.place_set.count()
48
>>> countries.PlacesByCountry.request(be).get_total_count()
48
>>> url = '/api/countries/PlacesByCountry?fmt=json&start=0&mt=5&mk=BE'
>>> res = test_client.get(url,REMOTE_USER='robin')
>>> print(res.status_code)
200
>>> result = json.loads(res.content.decode('utf-8'))
>>> print(len(result['rows']))
15
The 15 is because Lino has a hard-coded default value of returning only 15 rows when no limit has been specified.
In versions after 2013-09-03 you can change that limit
for a given table by overriding the
preview_limit
parameter of your table definition.
Or you can change it globally for all your tables
by setting the
preview_limit
Site attribute to either None or some bigger value.
This parameter existed before but wasn’t tested. In your code this would simply look like this:
class PlacesByCountry(Places):
preview_limit = 30
Here we override it on the living object:
>>> countries.PlacesByCountry.preview_limit = 25
Same request returns now 25 data rows:
>>> res = test_client.get(url, REMOTE_USER='robin')
>>> result = json.loads(res.content.decode('utf-8'))
>>> print(len(result['rows']))
25
To remove the limit altogether, you can say:
>>> countries.PlacesByCountry.preview_limit = None
and the same request now returns all 49 data rows:
>>> res = test_client.get(url,REMOTE_USER='robin')
>>> result = json.loads(res.content.decode('utf-8'))
>>> print(len(result['rows']))
49