Wednesday, December 7, 2016

Fixed several bugs in tinymce.js which caused a JavaScript errors when calling a dialog action (which needs a ParameterActionForm) from a href action link in the dashboard (i.e. with containing_panel being null). One of them was already in refresh_with_after(), another came when trying to save because the Lino.RichTextPanel class defined there had no method getValue(), which caused a Uncaught TypeError: f.getValue is not a function in Lino.fields2array().

In lino.utils.jsgen.py2js() I had a problem with a dict containing a mixture of unicode and future.types.newstr objects. This was probably caused by my changes last week (Friday, December 2, 2016), but obvioulsy not covered by any test.

Specifying default value of a ChoiceList field

The new lino_noi.lib.noi.workflows module is an interesting example of a subtle problem. When defining workflows, it is good to have them (a) defined in a place where it makes sense and (b) have them replaceable. Keep in mind that some future application of your code might want to replace your workflow.

There is a new possibility for specifying the default default value for all ChoiceListField of a ChoiceList: by setting a lino.core.choicelists.ChoiceList.default_value. But I don’t recommend it.

I also added a new meth as_callable on the ChoiceList class (not on the Choice). Instead of saying:

state = MyStates.field(default=MyStates.foo.as_callable)

I now recommend saying:

state = MyStates.field(default=MyStates.as_callable('foo'))

The advantage is that the application code does not need to define a default items for a choicelist.

I changed the default value for lino.core.choicelists.ChoiceList.max_length from 1 to 10.

I worked on #1286: The new site attribute lino.core.site.Site.use_new_unicode_symbols enables us to easily toggle between two series of symbols.

Getting websockets to run on a production server

Hamza and I worked on #923. While the ticket seems to be solved on a development server, there is still the problem that django-channels and websockets is a lot of configuration work on a production server. It starts here, but we did not yet reach the end.

Install the Redis backend:

$ pip install -U asgi_redis

Install the redis server:

$ sudo apt-get install redis-server

Install two more supervisor jobs.

Everything seems to work, but then Apache…

$ sudo a2enmod proxy_wstunnel

We now still have Javascript errors:

WebSocket connection to 'wss://mysite.lino-framework.org/websocket/' failed: Error during WebSocket handshake: Invalid status line

Or their equivalent on the apache error.log:

[Wed Dec 07 11:03:01.966228 2016] [ssl:error] [pid 13093] [remote 194.204.31.42:443] AH01961: SSL Proxy requested for mysite.lino-framework.org:443 but not enabled [Hint: SSLProxyEngine]
[Wed Dec 07 11:03:01.966294 2016] [proxy:error] [pid 13093] AH00961: WSS: failed to enable ssl support for 194.204.31.42:443 (mysite.lino-framework.org)

py2js() and dict with newstr keys

#1300 (py2js() and dict with newstr keys) was not yet fixed. Now it seems to be fixed. Here is a script I wrote in order to understand:

# -*- coding: UTF-8 -*-
# #1300 (py2js() and dict with newstr)

from builtins import str
from future.types import newstr
import six

items = [str('c'), u'ä2', 'b', 'd', 'a1']
def sortkey(x):
    if isinstance(x, newstr):
        return six.text_type(x)
    return x
# items = sorted(items, key=sortkey)
try:
    items = sorted(items, key=sortkey)
except TypeError as e:
    raise TypeError("Failed to sort {0} : {1}".format(items, e))
print items

print isinstance(str('a'), newstr)

print isinstance(u'a', newstr)

Default button_text for workflow actions

Yet another little optimization: workflow transition actions (ChangeStateAction) now inherit the button_text of their target state.

There is at least one side effect: the workflow_actions column of a calendar event now also uses symbols and no longer the action label. For example

Notified → [Close meeting] [Cancel] [Reset]

becomes

Notified → [☑] [☉] [☐]

Checked in first draft of new workflow for Lino Noi

Before flying to Malta I wanted to have it published: I committed my first draft of the new workflow for Lino Noi. I pushed it directly to master, without defining a branch

There are some known problems:

  • Lino Welfare test suite needs to be adapted

  • we need to write a migrator before we can deploy this to our own Noi.

  • We must review lino.modlib.users.mixins.Assignable because the AssignToMe action no longer works like this. Or at least we don’t need this in Lino Care. Maybe they need it in Lino Welfare. Maybe rename Assignable to Takeable and leave only the TakeAuthorship action.