Monday, April 21, 2014

Customizable SubmitInsert actions

Uff! I feel (a bit) as if Lino had resurrected from death.

Since Friday I had been fiddling in the JavaScript part of the new customizable implementation for SubmitInsert actions. weblino.js is really very tricky. Now it is a bit cleaner. There should be no visible changes, neither in user interface nor in the API.

Checked in so that others may test it. Thanks in advance for any bug reports.

The last part will be again in Python and thus much easier: imagine an API for rewriting a SubmitInsert and write the first use case: test for duplicates before creating new client, with interactive confirmation if necessary.

Sphinx-apidoc

Wes Turner wrote a new command-line option for sphinx-apidoc that implements an idea apidoc output format <https://groups.google.com/forum/#!topic/sphinx-users/Bm4w7OQcWYM> which I posted in January to sphinx-users. I adapted my fab api command in atelier.fablib to use this option.

Customizable SubmitInsert actions (continued)

Instead of writing ar.response.update(foo=X) we now recommend ar.set_response(foo=X). This has the advantage of raising (immediately) an exception when you specify an invalid keyword.

Started a documentation page about https://www.lino-framework.org/dev/actions.html for developers.

The new action SubmitInsertClient is the first example on how to use the new feature in application code. The application developer writes a new Action:

from lino.core.actions import SubmitInsert

class SubmitInsertClient(SubmitInsert):
    def run_from_ui(self, ar, **kw):
        obj = ar.create_instance_from_request()

        def ok(ar2):
            self.save_new_instance(ar2, obj)

        if obj.first_name == 'Foo':
            ar.confirm(ok, _("Is that true? Your name is 'Foo'?"))
        else:
            ok(ar)

And then overrides the default submit_insert action (either on the Model or on a Table) with an instance of this class:

class Client(dd.model):
    ...
    submit_insert = SubmitInsertClient()

An unexpected subtlety was that SubmitInsertClient, like every submit_insert action must set data_record. And this must be in the callback request (“ar2”), not in the original action request “ar”. But the callback request until now was just a BaseRequest, without methods like create_instance (i.e. the methods to create an instance and to fill data_record). So the callback request (created by lino.core.kernel.Kernel.run_callback()) had to become a more close clone of the original request.

Checkin after midnight and without thorough testing. But

TODO:

During testing I discovered a bug which was already there for some time: the “Must read eID card” action link in newcomers.NewClients doesn’t work. It causes an Internal Server Error:

ParameterStore of LayoutHandle for ParamsLayout on pcsw.Clients expected a list of 12 values, but got [u'21.03.2014', u'false', u'false', u'']

This is because the action is being called using pcsw/Clients instead of pcsw/NewClients as URI.