Skip to content

Commit

Permalink
http://luc.lino-framework.org/blog/2015/0724.html
Browse files Browse the repository at this point in the history
  • Loading branch information
lsaffre committed Jul 24, 2015
1 parent 4dea5f9 commit 413fba0
Show file tree
Hide file tree
Showing 19 changed files with 384 additions and 236 deletions.
16 changes: 9 additions & 7 deletions docs/tested/cv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ Career module (tested)

.. How to test only this document:
$ python setup.py test -s tests.DocsTests.test_cv
>>> from __future__ import print_function
>>> import os
>>> os.environ['DJANGO_SETTINGS_MODULE'] = \
... 'lino.projects.docs.settings.demo'
>>> from lino.api.doctest import *
$ python setup.py test -s tests.DocsTests.test_cv
doctest init:
>>> from __future__ import print_function
>>> import os
>>> os.environ['DJANGO_SETTINGS_MODULE'] = \
... 'lino.projects.docs.settings.demo'
>>> from lino.api.doctest import *
.. contents::
:local:
Expand Down
104 changes: 104 additions & 0 deletions docs/tested/households.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
.. _lino.specs.households:

=====================
The Households module
=====================

.. How to test only this document:
$ python setup.py test -s tests.DocsTests.test_households
doctest init:
>>> from __future__ import print_function
>>> import os
>>> os.environ['DJANGO_SETTINGS_MODULE'] = \
... 'lino.projects.docs.settings.demo'
>>> from lino.api.doctest import *
The :mod:`lino.modlib.households` module adds functionality for
managing households (i.e. groups of humans who live together in a same
house).

.. contents::
:local:
:depth: 2


Configuration
=============

>>> rt.show(households.Types)
==== ==================== ========================= ====================== ==================== ==================== ===================== ====================
ID Designation Designation (de) Designation (fr) Designation (et) Designation (nl) Designation (pt-br) Designation (es)
---- -------------------- ------------------------- ---------------------- -------------------- -------------------- --------------------- --------------------
1 Married Ehepartner Marié Married Married Married Married
2 Divorced Geschieden Divorcé Divorced Divorced Divorced Divorced
3 Factual household Faktischer Haushalt Cohabitation de fait Factual household Factual household Factual household Factual household
4 Legal cohabitation Legale Wohngemeinschaft Cohabitation légale Legal cohabitation Legal cohabitation Legal cohabitation Legal cohabitation
5 Isolated Getrennt Isolé Isolated Isolated Isolated Isolated
6 Other Sonstige Autre Other Other Other Other
==== ==================== ========================= ====================== ==================== ==================== ===================== ====================
<BLANKLINE>

>>> rt.show(households.MemberRoles)
======= ============ ===================
value name text
------- ------------ -------------------
01 head Head of household
02 spouse Spouse
03 partner Partner
04 cohabitant Cohabitant
05 child Child
06 relative Relative
07 adopted Adopted child
10 other Other
======= ============ ===================
<BLANKLINE>


SiblingsByPerson
================

:class:`lino.modlib.households.models.SiblingsByPerson` works only
when it can determine the "one and only" current household.

Usually this is the membership marked as `primary`.

But even when a person has multiple household memberships and none of
them is primary, it can look at the `end_date`.

>>> Person = contacts.Person
>>> Member = households.Member
>>> Member.objects.filter(end_date__isnull=False)
[Member #5 (u'Mr Paul Frisch (Head of household)'), Member #11 (u'Mr Albert Adam (Head of household)'), Member #17 (u'Mr Lars Braun (Head of household)'), Member #23 (u'Mr Ilja Adam (Head of household)')]

>>> p = Person.objects.get(first_name="Lars", last_name="Braun")
>>> Member.objects.filter(person=p).count()
2
>>> rt.show(households.MembersByPerson, master_instance=p)
Mr Lars Braun is
`☐ <javascript:Lino.households.Members.set_primary(null,31,{ })>`__Head of household in *Lars & Melba Braun-Frisch*
`☐ <javascript:Lino.households.Members.set_primary(null,17,{ })>`__Head of household in *Lars & Pascale Braun-Adam*
<BLANKLINE>
Create a household : **Married** / **Divorced** / **Factual household** / **Legal cohabitation** / **Isolated** / **Other**

>>> rt.show(households.MembersByPerson, p, nosummary=True)
=========================== =================== ========= ============ ==========
Household Role Primary Start date End date
--------------------------- ------------------- --------- ------------ ----------
Lars & Melba Braun-Frisch Head of household No
Lars & Pascale Braun-Adam Head of household No 3/4/02
=========================== =================== ========= ============ ==========
<BLANKLINE>

>>> SiblingsByPerson = households.SiblingsByPerson
>>> rt.show(SiblingsByPerson, p)
================== =================== ============ ==========
Person Role Start date End date
------------------ ------------------- ------------ ----------
Mr Lars Braun Head of household
Mrs Melba Frisch Partner
================== =================== ============ ==========
<BLANKLINE>

1 change: 1 addition & 0 deletions docs/tested/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ which are part of the test suite.
core_utils
tinymce
dynamic
households
16 changes: 5 additions & 11 deletions docs/tested/polly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@ lino.projects.polly.settings.doctests
Rolf Rompen's response to Participant feedback

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

>>> client = Client()
>>> mt = contenttypes.ContentType.objects.get_for_model(obj.__class__).id
Expand Down
Binary file modified docs/tutorials/pisa/pisa.Person-1.pdf
Binary file not shown.
2 changes: 0 additions & 2 deletions docs/tutorials/watch_tutorial/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ The :mod:`lino.modlib.changes` plugin records only changes made using
the web interface. In a virgin database are no changes:

>>> rt.show(changes.Changes)
<BLANKLINE>
No data to display
<BLANKLINE>


We create a new person
Expand Down
3 changes: 2 additions & 1 deletion docs/warnings_html.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/home/luc/hgwork/lino/docs/api/lino.modlib.ledger.models.rst:29: WARNING: failed to import customize_accounts
/home/luc/hgwork/lino/docs/api/lino.core.tablerequest.rst:24: WARNING: failed to import RstTable
/home/luc/hgwork/lino/docs/api/lino.utils.xmlgen.html.rst:57: WARNING: failed to import RstTable
42 changes: 27 additions & 15 deletions lino/core/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from django.utils.translation import get_language


from lino.utils.xmlgen.html import RstTable
from lino.utils.html2rst import RstTable
from lino.utils import isiterable
from lino.utils.xmlgen.html import E
from lino.core import constants
Expand Down Expand Up @@ -93,10 +93,13 @@ def js2url(self, js):
def href(self, url, text):
return E.a(text, href=url)

def show_table(self, ar, nosummary=False, **kw):
def show_table(self, ar, nosummary=False, stripped=True, **kw):
"""Returns a HTML element representing the given action request as a
table. See :meth:`ar.show <lino.core.request.BaseRequest.show>`.
This silently ignores the parameters `nosummary` and
`stripped` since for HTML they have no meaning.
"""
if ar.actor.master is not None and not nosummary:
if ar.actor.slave_grid_format == 'summary':
Expand Down Expand Up @@ -300,8 +303,11 @@ def action_button(self, obj, ar, ba, label=None, **kw):
label = ba.action.label
return "[%s]" % label

def show_story(self, ar, story, *args, **kwargs):
"""Render the given story as an HTML element."""
def show_story(self, ar, story, stripped=True, **kwargs):
"""Render the given story as an HTML element. Ignore `stripped`
because it makes no sense in HTML.
"""
from lino.core.actors import Actor
from lino.core.tables import TableRequest
elems = []
Expand All @@ -310,12 +316,12 @@ def show_story(self, ar, story, *args, **kwargs):
elems.append(item)
elif isinstance(item, type) and issubclass(item, Actor):
ar = item.default_action.request(parent=ar)
elems.append(self.show_table(ar, *args, **kwargs))
elems.append(self.show_table(ar, **kwargs))
elif isinstance(item, TableRequest):
assert item.renderer is not None
elems.append(self.show_table(item, *args, **kwargs))
elems.append(self.show_table(item, **kwargs))
elif isiterable(item):
elems.append(self.show_story(ar, item, *args, **kwargs))
elems.append(self.show_story(ar, item, **kwargs))
# for i in self.show_story(item, *args, **kwargs):
# yield i
else:
Expand Down Expand Up @@ -359,9 +365,12 @@ def show_table(self, ar, column_names=None, header_level=None,

if ar.actor.master is not None and not nosummary:
if ar.actor.slave_grid_format == 'summary':
print(E.to_rst(
s = E.to_rst(
ar.actor.get_slave_summary(ar.master_instance, ar),
stripped=stripped))
stripped=stripped)
if stripped:
s = s.strip()
print(s)
return

fields, headers, widths = ar.get_field_info(column_names)
Expand Down Expand Up @@ -393,26 +402,29 @@ def show_table(self, ar, column_names=None, header_level=None,
t = RstTable(headers, **kwargs)
s = t.to_rst(rows)
if header_level is not None:
print(rstgen.header(header_level, ar.get_title()))
h = rstgen.header(header_level, ar.get_title())
if stripped:
h = h.strip()
print(h)
# s = E.tostring(E.h2(ar.get_title())) + s
print(s)

def show_story(self, ar, story, *args, **kwargs):
def show_story(self, ar, story, stripped=True, **kwargs):
"""Render the given story as reStructuredText to stdout."""
from lino.core.actors import Actor
from lino.core.requests import ActionRequest

for item in story:
if E.iselement(item):
print(E.to_rst(item))
print(E.to_rst(item, stripped))
elif isinstance(item, type) and issubclass(item, Actor):
ar = item.default_action.request(parent=ar)
self.show_table(ar, *args, **kwargs)
self.show_table(ar, stripped=stripped, **kwargs)
elif isinstance(item, ActionRequest):
self.show_table(item, *args, **kwargs)
self.show_table(item, stripped=stripped, **kwargs)
# print(item.table2rst(*args, **kwargs))
elif isiterable(item):
self.show_story(ar, item, *args, **kwargs)
self.show_story(ar, item, stripped, **kwargs)
# for i in self.show_story(ar, item, *args, **kwargs):
# print(i)
else:
Expand Down
2 changes: 1 addition & 1 deletion lino/core/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def doit():
# print 20150512, ar.renderer
if issubclass(ar.actor, Report):
story = ar.actor.get_story(None, ar)
return ar.renderer.show_story(self, story)
return ar.renderer.show_story(self, story, stripped=stripped)
return ar.renderer.show_table(
ar, column_names=column_names, header_level=header_level,
nosummary=nosummary, stripped=stripped)
Expand Down
1 change: 0 additions & 1 deletion lino/core/tablerequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from lino.utils.xmlgen import html as xghtml
from lino.utils.xmlgen.html import E
from lino.utils import jsgen
# from lino.utils.xmlgen.html import RstTable

from .requests import ActionRequest

Expand Down
2 changes: 1 addition & 1 deletion lino/modlib/extjs/config/extjs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
{{ ln }}
{%- endfor -%}
{# anonymous request using permalink: forward request.path as "on_login" URL #}
{%- if settings.SITE.user_model and not request.user.profile.authenticated and on_ready -%}
{%- if settings.SITE.user_model and not request.user.authenticated and on_ready -%}
{%- set on_ready = "Lino.show_login_window(" + py2js(request.path) + ")" -%}
{%- endif -%}
{# Render main window #}
Expand Down
13 changes: 7 additions & 6 deletions lino/modlib/extjs/ext_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,16 @@ def get_detail_url(self, obj, *args, **kw):
return self.plugin.build_plain_url(
'api', obj._meta.app_label, obj.__class__.__name__, str(obj.pk), *args, **kw)

def show_table(self, ar, **kw):
def show_table(
self, ar, stripped=True, nosummary=False, **kw):
"""
Returns a HTML element representing this request as a table.
Used by appy_pod rendered.
"""
if ar.actor.slave_grid_format == 'summary':
return ar.actor.get_slave_summary(ar.master_instance, ar)
else:
return ar.table2xhtml(**kw)
if ar.actor.master is not None and not nosummary:
if ar.actor.slave_grid_format == 'summary':
return ar.actor.get_slave_summary(ar.master_instance, ar)
return ar.table2xhtml(**kw)

def handler_item(self, mi, handler, help_text):
#~ handler = "function(){%s}" % handler
Expand Down Expand Up @@ -492,7 +493,7 @@ def html_page_main_window(self, on_ready, request, site):

def html_page_user(self, request, site):

# TODO: move the following to lino.modlib.users
# TODO: move the following to lino.modlib.users?
if settings.SITE.user_model is not None:

if request.user.profile.has_required_roles([SiteUser]):
Expand Down
2 changes: 2 additions & 0 deletions lino/modlib/households/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""Adds functionality for managing households (i.e. groups of humans
who live together in a same house).
Technical specification see :ref:`lino.specs.households`.
.. autosummary::
:toctree:
Expand Down
5 changes: 3 additions & 2 deletions lino/modlib/polls/fixtures/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License: BSD (see file COPYING for details)

from django.conf import settings
from lino.api import rt
from lino.api import dd, rt
from lino.utils import Cycler


Expand Down Expand Up @@ -50,4 +50,5 @@ def poll(choiceset, title, details, questions):
for p in polls.Poll.objects.exclude(questions_to_add=''):
p.after_ui_save(None, None)
yield polls.Response(
poll=p, user=USERS.pop(), state=polls.ResponseStates.draft)
poll=p, user=USERS.pop(), date=dd.today(),
state=polls.ResponseStates.draft)
2 changes: 1 addition & 1 deletion lino/projects/min2/tests/test_birth_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_this(self):
Father of *Mary* (4 years)
Father of *Joseph* (5 years)
Create relationship as **Father**/**Son** **Adoptive father**/**Adopted son** **Husband** **Partner** **Stepfather**/**Stepson** **Brother** **Cousin** **Uncle**/**Nephew** **Relative** **Other**
Create relationship as **Father**/**Son** **Adoptive father**/**Adopted son** **Husband** **Partner** **Stepfather**/**Stepson** **Brother** **Cousin** **Uncle**/**Nephew** **Relative** **Other**
""")

# Here we are just testing whether no exception is risen. The
Expand Down
10 changes: 9 additions & 1 deletion lino/projects/polly/settings/demo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from lino.projects.polly.settings import *
SITE = Site(globals(), title=Site.verbose_name + " demo")
from lino.utils import i2d


class Site(Site):
title = Site.verbose_name + " demo"
the_demo_date = i2d(20141023)

SITE = Site(globals())

#~ DEBUG=True
# the following line should always be commented out in a checked-in version
#~ DATABASES['default']['NAME'] = ':memory:'
Loading

0 comments on commit 413fba0

Please sign in to comment.