Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
http://luc.lino-framework.org/blog/2017/0904.html
Browse files Browse the repository at this point in the history
  • Loading branch information
lsaffre committed Sep 4, 2017
1 parent e2754ea commit 86eee4f
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 129 deletions.
21 changes: 20 additions & 1 deletion docs/dev/actions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,22 @@ The :class:`Action` class

Abstract base class for all actions.

The first argument is the optional `label`, other arguments should
be specified as keywords and can be any of the existing class
attributes.


.. attribute:: label

The label of this action. A short descriptive text in user
language. Used e.g. on menu items. Also on toolbar buttons if
they have neither :attr:`icon_name` nor :attr:`button_text`

.. method:: get_label(self)

Return the `label` of this action, or the `action_name` if the
action has no explicit label.

.. attribute:: button_text

The text to appear on buttons for this action. If this is not
Expand Down Expand Up @@ -403,7 +412,17 @@ The :class:`Action` class
Name of a Javascript function to be invoked on the web client when
this action is called.


.. method:: attach_to_actor(self, owner, name):

Called once per Actor per Action on startup before a
BoundAction instance is being created. If this returns False,
then the action won't be attached to the given actor.

The owner is the object which "defines" the action, i.e. uses
that instance for the first time. Subclasses of the owner may
re-use the same instance without becoming the owner.



The :func:`action` decorator
============================
Expand Down
4 changes: 2 additions & 2 deletions docs/dev/polls/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ is easy and fun because you can write fixtures in Python.
>>> # test_client.get("123")
>>> walk_menu_items()
- Polls --> Questions : 4
- Polls --> Choices : 11
- Polls --> Questions : 3
- Polls --> Choices : 10
<BLANKLINE>
TODO: above snippet should show 5 questions (4+1 for the phantom
Expand Down
4 changes: 2 additions & 2 deletions docs/specs/ajax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Refusing permission to an anonymous request

.. to test only this document:
$ python setup.py test -s tests.SpecsTests.test_ajax
$ doctest docs/specs/ajax.rst
doctest init:
Expand Down Expand Up @@ -78,7 +78,7 @@ will do the following AJAX call to get its data:
>>> print(json.dumps(sorted(r.keys())))
["count", "no_data_text", "param_values", "rows", "success", "title"]
>>> len(r['rows'])
26
25

Now imagine that the user gets a break and leaves her browser open,
the server meanwhile did a dump and a reload. So the sessions have
Expand Down
3 changes: 2 additions & 1 deletion docs/specs/avanti/avanti.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ Clients in Lino Avanti

.. How to test just this document:
$ python setup.py test -s tests.SpecsTests.test_avanti_avanti
$ doctest docs/specs/avanti/avanti.rst
doctest init:
>>> import lino
>>> lino.startup('lino_book.projects.adg.settings.doctests')
>>> from lino.api.doctest import *
This document describes the :mod:`lino_avanti.lib.avanti` plugin.

.. contents::
:local:
Expand Down
18 changes: 9 additions & 9 deletions docs/specs/bevats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Special Belgian VAT declarations

.. to run only this test:
$ python setup.py test -s tests.SpecsTests.test_bevats
$ doctest docs/specs/bevats.rst
doctest init
Expand Down Expand Up @@ -121,14 +121,14 @@ Here are the VAT declarations in our demo database:

>>> jnl = rt.models.ledger.Journal.get_by_ref('VAT')
>>> rt.show('bevats.DeclarationsByJournal', jnl)
======= ============ ============== ============ =================== ============== ====== ====== ============== ================
No. Entry date Start period End period Accounting period [80] [81] [82] [83] Workflow
------- ------------ -------------- ------------ ------------------- -------------- ------ ------ -------------- ----------------
3 28/03/2015 2015-03 2015-03 907,31 907,31 **Registered**
2 28/02/2015 2015-02 2015-02 907,44 907,44 **Registered**
1 31/01/2015 2015-01 2015-01 907,07 907,07 **Registered**
**6** **2 721,82** **2 721,82**
======= ============ ============== ============ =================== ============== ====== ====== ============== ================
==================== ============ ============== ============ =================== ============== ====== ====== ============== ================
No. Entry date Start period End period Accounting period [80] [81] [82] [83] Workflow
-------------------- ------------ -------------- ------------ ------------------- -------------- ------ ------ -------------- ----------------
3/2015 28/03/2015 2015-03 2015-03 907,31 907,31 **Registered**
2/2015 28/02/2015 2015-02 2015-02 907,44 907,44 **Registered**
1/2015 31/01/2015 2015-01 2015-01 907,07 907,07 **Registered**
**Total (3 rows)** **2 721,82** **2 721,82**
==================== ============ ============== ============ =================== ============== ====== ====== ============== ================
<BLANKLINE>

There is usually one declaration per accounting period.
Expand Down
15 changes: 7 additions & 8 deletions docs/specs/cosi/apc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The apc demo project
.. This document is part of the Lino Così test suite. To run only this
test:
$ python setup.py test -s tests.SpecsTests.test_apc
$ doctest docs/specs/cosi/apc.rst
doctest init:
Expand Down Expand Up @@ -60,7 +60,7 @@ Robin is the system administrator, he has a complete menu:
- Create invoices
- Office : My Excerpts
- Reports :
- Accounting : Situation, General Accounts Balances, Customer Accounts Balances, Supplier Accounts Balances, Debtors, Creditors, Purchase journal, Due invoices, Sales invoice journal
- Accounting : Situation, General Accounts Balance, Customer Accounts Balance, Supplier Accounts Balance, Debtors, Creditors, Purchase journal, Due invoices, Sales invoice journal
- Configure :
- System : Site Parameters, Help Texts, Users
- Places : Countries, Places
Expand Down Expand Up @@ -125,7 +125,7 @@ This demo database contains exactly 48 entries:
200
>>> result = json.loads(res.content)
>>> print(len(result['rows']))
16
15

The 16 is because Lino has a hard-coded default value of
returning only 15 rows when no limit has been specified
Expand All @@ -150,24 +150,23 @@ Here we override it on the living object:

>>> countries.PlacesByCountry.preview_limit = 25

Same request returns now 26 data rows:
Same request returns now 25 data rows:

>>> res = test_client.get(url, REMOTE_USER='robin')
>>> result = json.loads(res.content)
>>> print(len(result['rows']))
26
25

To remove the limit altogether, you can say:

>>> countries.PlacesByCountry.preview_limit = None

and the same request now returns all 49 data rows (48 + the phantom
row):
and the same request now returns all 48 data rows:

>>> res = test_client.get(url,REMOTE_USER='robin')
>>> result = json.loads(res.content)
>>> print(len(result['rows']))
49
48



Expand Down
11 changes: 11 additions & 0 deletions docs/specs/cosi/ledger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,17 @@ Model mixins
end_period to the parameter fields.


.. class:: ItemsByVoucher

Shows the items of this voucher.

This is used as base class for slave tables in
:mod:`lino_xl.lib.finan`,
:mod:`lino_xl.lib.vat`,
:mod:`lino_xl.lib.vatless`,
:mod:`lino_xl.lib.ana`, ...


Utilities
=========

Expand Down
4 changes: 2 additions & 2 deletions docs/specs/invalid_requests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Answering to invalid requests

.. to run only this test:
$ python setup.py test -s tests.SpecsTests.test_invalid_requests
$ doctest docs/specs/invalid_requests.rst
doctest init:
Expand Down Expand Up @@ -36,7 +36,7 @@ Here is a valid request:
200
>>> d = AttrDict(json.loads(res.content))
>>> d.count
1
0
>>> print(d.title)
Contact for of Mr Hans Altenberg

Expand Down
4 changes: 2 additions & 2 deletions docs/specs/noi/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Lino Noi Overview

.. How to test just this document:
$ python setup.py test -s tests.SpecsTests.test_general
$ doctest docs/specs/noi/general.rst
doctest init:
Expand Down Expand Up @@ -151,7 +151,7 @@ Countries
>>> json_fields = 'count rows title success no_data_text'
>>> kwargs = dict(fmt='json', limit=10, start=0)
>>> demo_get('robin', 'api/countries/Countries', json_fields, 9, **kwargs)
>>> demo_get('robin', 'api/countries/Countries', json_fields, 8, **kwargs)
Expand Down
87 changes: 85 additions & 2 deletions docs/specs/polls.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
.. _tested.polly:
.. _book.specs.polls:

The Polls plugin
================

.. doctest init:
.. how to test just this page:
$ doctest docs/specs/polls.rst
doctest init:
>>> import lino
>>> lino.startup('lino_book.projects.polly.settings.demo')
>>> from lino.api.shell import *
>>> from lino.api.doctest import *
This document describes the :mod:`lino_xl.lib.polls` plugin which
adds database models and functionality for managing polls.
Expand Down Expand Up @@ -223,3 +228,81 @@ Example fixtures
- :mod:`lino_xl.lib.polls.fixtures.bible`
- :mod:`lino_xl.lib.polls.fixtures.feedback`
- :mod:`lino_xl.lib.polls.fixtures.compass`


Miscellaneous tests
===================

>>> print(settings.SETTINGS_MODULE)
lino_book.projects.polly.settings.demo

>>> pk = 2
>>> obj = polls.Response.objects.get(pk=pk)
>>> print(obj)
Robin Rood's response to Participant feedback

>>> rt.login(obj.user.username).show(polls.AnswersByResponse, obj)
Question 23/10/2014
<BLANKLINE>
1) There was enough to eat. **1** **2** **3** **4** **5** (**Remark**)
<BLANKLINE>
2) The stewards were nice and attentive. **1** **2** **3** **4** **5** (**Remark**)
<BLANKLINE>
3) The participation fee was worth the money. **1** **2** **3** **4** **5** (**Remark**)
<BLANKLINE>
4) Next time I will participate again. **1** **2** **3** **4** **5** (**Remark**)

>>> mt = contenttypes.ContentType.objects.get_for_model(obj.__class__).id
>>> url = '/api/polls/AnswersByResponse?rp=ext-comp-1351&fmt=json&mt=%d&mk=%d' % (mt, pk)
>>> test_client.force_login(obj.user)
>>> res = test_client.get(url, REMOTE_USER=obj.user.username)


>>> print(res.status_code)
200
>>> d = json.loads(res.content)

>>> len(d['rows'])
4

>>> print(d['rows'][0][0])
<span class="htmlText">1) There was enough to eat.</span>


The "My answer" column for the first row has 5 links:

>>> soup = BeautifulSoup(d['rows'][0][1], 'lxml')
>>> links = soup.find_all('a')
>>> len(links)
5

The first of them displays a "1":

>>> print(links[0].string)
... #doctest: +NORMALIZE_WHITESPACE
1

And clicking on it would run the following Javascript code:

>>> print(links[0].get('href'))
javascript:Lino.polls.Responses.toggle_choice("ext-comp-1351",false,2,{ "fv": [ 9, 17 ] })

The 2 is the id of the Response we are acting on:

>>> polls.Response.objects.get(pk=2)
Response #2 ("Robin Rood's response to Participant feedback")


"fv" stands for "field values".
It refers to the two `parameters` of the
:class:`lino.modlib.polls.models.ToggleChoice` action.
The 9 is the id of a `polls.Question`,
the 17 is the id of a `polls.Choice`.

>>> polls.Question.objects.get(pk=9)
Question #9 ('1) There was enough to eat.')

>>> polls.Choice.objects.get(pk=17)
Choice #17 ('1')


4 changes: 2 additions & 2 deletions docs/specs/projects/belref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ of :mod:`lino.modlib.extjs`
>>> data.keys()
[u'count', u'rows', u'success', u'no_data_text', u'title']
>>> data['count']
14
13
>>> data['rows'][0]
[u'Institut National de Statistique', u'Nationaal Instituut voor Statistiek', u'Nationales Institut f\xfcr Statistik', 1, u'INS', u'NIS', u'NIS', {u'id': True}, {}, False]

Expand All @@ -82,7 +82,7 @@ Get the list of places in Belgium:
200
>>> data = json.loads(res.content)
>>> data['count']
2878
2877
>>> data['rows'][0]
[u'Belgique', u'BE', u"'s Gravenvoeren", u'', u'', u'Ville', u'50', u'3798', None, None, 2147, False, u'73109', u'<p />', u'<div><a href="javascript:Lino.countries.Places.detail.run(null,{ &quot;record_id&quot;: 2147 })">\'s Gravenvoeren</a></div>', u'<a href="javascript:Lino.countries.Places.detail.run(null,{ &quot;record_id&quot;: 2147 })">\'s Gravenvoeren</a>', u'<div><a href="javascript:Lino.countries.Places.detail.run(null,{ &quot;record_id&quot;: 2147 })">\'s Gravenvoeren</a></div>', u'<span />', {u'id': True}, {}, False]

Expand Down
5 changes: 2 additions & 3 deletions docs/team/prerequisites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ HTML, CSS and Javascript

- You understand the meaning of tags like
``<body>``, ``<ul>``, ``<li>`` ...
- You understand how Lino uses the Sencha ExtJS Javascript library
- You know what an AJAX request is.

Databases
Expand All @@ -90,6 +89,6 @@ Lino is a part of Django and therefore uses relational databases
(SQL). You don't usually need to write SQL yourself when using Lino,
but it is of course important to understand the concepts behind a
database. And on a production server you will have to deal with
database servers like MySQL or PostgreSQL (according to the
:setting:`DATABASES` setting).
database servers like MySQL or PostgreSQL when doing database
snapshots or running migrations.

1 change: 0 additions & 1 deletion docs/tested/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ which are part of the test suite.
:maxdepth: 1

test_i18n
polly
core_utils
dynamic
e006
Expand Down
Loading

0 comments on commit 86eee4f

Please sign in to comment.