Delayed values

This topic guide explains what a delayed value is.

This is a tested document. The following instructions are used for initialization:

>>> from lino import startup
>>> startup('lino_book.projects.noi1r.settings')
>>> from lino.api.doctest import *
delayed value

A value of a store field that is not computed immediately and for which Lino returns a DelayedValue object instead, which basically just tells the client to emit another AJAX request if it wants to know that value.

Lino currently uses a delayed value when rendering the summary of a slave table of a detail page.

About the name

A slave table can be a valid data element of a detail layout, and it is named foos.Foos (i.e. with a dot). But the corresponding store field will be named foos_Foos because we want the names of store fields to be valid Python attribute names.

>>> # ses = rt.login("robin", renderer=settings.SITE.kernel.default_renderer)
>>> t1 = tickets.Ticket.objects.get(pk=1)
>>> dv = tickets.AllTickets
>>> ar = dv.request(user=rt.login("robin").get_user())
>>> store = dv.get_handle().store
>>> pprint(store.row2dict(ar, t1))
... 
{'DuplicatesByTicket': <Element table at ...>,
 'assigned_to': None,
 'assigned_toHidden': None,
 'comments.CommentsByMentioned': DelayedValue(values/tickets/AllTickets/1/comments.CommentsByMentioned),
 'comments.CommentsByRFC': DelayedValue(values/tickets/AllTickets/1/comments.CommentsByRFC),
 'created': datetime.datetime(..., tzinfo=<UTC>),
 'deadline': None,
 'description': '',
 'disable_editing': False,
 'disabled_fields': {'DuplicatesByTicket': True,
                     'created': True,
                     'end_session': True,
                     'fixed_since': True,
                     'id': True,
                     'mark_refused': True,
                     'modified': True},
 'duplicate_of': None,
 'duplicate_ofHidden': None,
 'end_user': 'Andreas Arens',
 'end_userHidden': 112,
 'extra_hours': None,
 'fixed_since': None,
 'free_hours': None,
 'id': 1,
 'modified': datetime.datetime(..., tzinfo=<UTC>),
 'overview': <Element div at ...>,
 'planned_time': None,
 'priority': 30,
 'private': False,
 'quick_assign_to': <Element p at ...>,
 'ref': None,
 'regular_hours': None,
 'site': 'welket',
 'siteHidden': 1,
 'state': 'New',
 'stateHidden': '10',
 'summary': 'Föö fails to bar when baz',
 'ticket_type': 'Bugfix',
 'ticket_typeHidden': 1,
 'tickets.LinksByTicket': DelayedValue(values/tickets/AllTickets/1/tickets.LinksByTicket),
 'upgrade_notes': '',
 'uploads.UploadsByController': DelayedValue(values/tickets/AllTickets/1/uploads.UploadsByController),
 'user': 'Jean',
 'userHidden': 7,
 'workflow_buttons': <Element span at ...>,
 'working.SessionsByTicket': DelayedValue(values/tickets/AllTickets/1/working.SessionsByTicket)}

Don't read on

The following would probably have covered #4222. (TODO: test whether this is true).

>>> url = '/values/tickets/AllTickets/1/tickets.LinksByTicket'
>>> test_client.force_login(rt.login('robin').user)
>>> res = test_client.get(url, REMOTE_USER='robin')
>>> pprint(json.loads(res.content.decode()))
... 
{'data': '<div><ul><li>Requires: <a href="javascript:window.App.runAction({ '
         ...
         'new Dependency.">Duplicate of</a></span></div>'}
>>> ses = rt.login("robin")
>>> ses.show('tickets.AllTickets.detail', selected_pks=[1])
... 
GeneralMoreLinksFöö fails to bar when bazProjectEnd userTicket typeluc, romainPrivatePriorityPlanned timeDeadlineRegularExtraFreeTotal 0:00 hours.Active sessions: Luc since 09:00:00 ■[✋] [▶] ⚹ New → [☾] [☎] [☉] [⚒] [☐] [☑]New... by rolf (1 reply) :
WhoWhatDone?HimBar HerFoo the BarxThemFloop the pigx... by jean (4 replies) : breaking ...StateAssigned toDuplicate ofSource document: NewDescription Resolution Checks of #1 (⚹ Föö fails to bar when baz)No data to displayIDReferenceSummaryAuthorCreatedModifiedFixed sinceRequires: #2