Friday, April 23, 2021

The new BabelPreviewable model mixin

For the Lino Shop project we realized that the description fields of categories and products should be previewable. Since they are also babel fields, I wrote a new mixin lino.modlib.memo.BabelPreviewable.

First use case is lino_xl.lib.products, where Product and Category now inherit from it.

In lino.modlib.memo.Previewable I renamed the fields short_preview to body_short_preview and long_preview to body_long_preview, and started to prepare the case that we want to use this mixin for models where the previewable_field is not 'body'.

But I don’t yet use this possibility here. I prefer to change the field name for the description of products and categories from “description” to “body”. Making the name of the “source” field configurable would make things uselessly complicated.

To test whether everything works, we should add, to the body of some product or category, some memo command that renders translatable text.

How should a read-only RichTextField render its content? Should it “execute” the html tags (showing their result), or should it rather “show” them?

I think I made up my mind about read-only RichText fields: let’s remove the dangerouslySetInnerHTML option again. A read-only RichTextField widget should show the “real” source text, not a preview. When we want to see the preview, we have the body_short_preview and body_full_preview fields of the Previewable mixin.

I started to play with the new feature in Lino Shop. There is now a third panel in the product detail. One book now has a body with rich text.