Welcome | Get started | Dive into Lino | Contribute | Topics | Reference | More

comments (comments in Avanti)

The lino.modlib.comments in Lino Avanti is configured and used to satisfy the application requirements.

This page is a tested document and the following instructions are used for initialization:

>>> from lino import startup
>>> startup('lino_book.projects.avanti1.settings')
>>> from lino.api.doctest import *

Overview

Comments in Lino Avanti are considered confidential data and can be seen only by users with appropriate permission.

See also User types in Lino Avanti.

Private comments are seen only by their respective author.

Public comments are shown to other social workers. Comments are never shown to the external supervisor.

A system administrator can see all comments (it makes no sense to hide them because a system admin can easily create or use a user account with the permissions they want).

Comments are private by default:

>>> dd.plugins.comments.private_default
True

There is only one Commentable thing in Lino Avanti: the client.

>>> list(rt.models_by_base(comments.Commentable))
[<class 'lino_avanti.lib.avanti.models.Client'>]

Tests

The demo database contains 108 comments, and they are all private.

>>> rt.models.comments.Comment.objects.all().count()
108
>>> rt.models.comments.Comment.objects.filter(private=True).count()
108

Robin can see them all.

>>> rt.login("robin").show(comments.Comments,
...     column_names="id user owner", limit=6,
...     display_mode=((None, DISPLAY_MODE_TABLE),))
... 
==== =============== ===========================================================
 ID   Author          Topic
---- --------------- -----------------------------------------------------------
 1    audrey          `BALLO Armáni (179/romain) </#/api/avanti/Clients/179>`__
 2    martina         `BALLO Armáni (179/romain) </#/api/avanti/Clients/179>`__
 3    nathalie        `BALLO Armáni (179/romain) </#/api/avanti/Clients/179>`__
 4    nelly           `BALLO Armáni (179/romain) </#/api/avanti/Clients/179>`__
 5    sandra          `BALLO Armáni (179/romain) </#/api/avanti/Clients/179>`__
 6    Laura Lieblig   `BALLO Armáni (179/romain) </#/api/avanti/Clients/179>`__
==== =============== ===========================================================

Nathalie sees only her own comments:

>>> rt.login("nathalie").show(comments.Comments,
...     column_names="id user owner", limit=6, display_mode=((None, DISPLAY_MODE_TABLE),))
... 
==== ========== ===============================================================
 ID   Author     Topic
---- ---------- ---------------------------------------------------------------
 3    nathalie   `BALLO Armáni (179/romain) </#/api/avanti/Clients/179>`__
 12   nathalie   `ALVANG Aleksándr (178/romain) </#/api/avanti/Clients/178>`__
 21   nathalie   `ABDOO Aátif (177/nathalie) </#/api/avanti/Clients/177>`__
 30   nathalie   `CHAHINE Bánji (174/nelly) </#/api/avanti/Clients/174>`__
 39   nathalie   `BELSKAIA Anton (172/rolf) </#/api/avanti/Clients/172>`__
 48   nathalie   `ABDUL Abbáád (171/romain) </#/api/avanti/Clients/171>`__
==== ========== ===============================================================
>>> rt.login("nathalie").show(comments.RecentComments)
... 
- *... ago* by **nathalie** in reply to **martina** about *KEITA Cácey (161/nathalie)* :
...
>>> rt.show(comments.Comments,
...     column_names="id user owner", limit=6)
... 
>>> rt.show(comments.RecentComments)
>>> rt.login("audrey").show(comments.RecentComments)

Summary:

>>> rows = []
>>> views = (comments.Comments, avanti.Clients)
>>> headers = ["User", "type"] + [i.__name__ for i in views]
>>> user_list = [users.User.get_anonymous_user()] + list(users.User.objects.all())
>>> for u in user_list:
...    cells = [str(u.username), u.user_type.name]
...    for dv in views:
...       qs = dv.request(user=u).data_iterator
...       cells.append(str(qs.count()))
...    rows.append(cells)
>>> print(rstgen.table(headers, rows))
... 
=========== ============= ========== =========
 User        type          Comments   Clients
----------- ------------- ---------- ---------
 anonymous   anonymous     0          29
 audrey      auditor       0          29
 martina     coordinator   0          29
 nathalie    user          12         29
 nelly       user          12         29
 sandra      secretary     0          29
 laura       teacher       0          29
 romain      admin         108        29
 rolf        admin         108        29
 robin       admin         108        29
=========== ============= ========== =========