Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

publisher : render database content as styled html

The lino.modlib.publisher plugin adds the notion of content pages used to produce the pages of websites or books.

It doesn’t add any database model, but a choicelist, a model mixin and an action. It also adds a printing build method (lino.modlib.printing.BuildMethods).

This page contains code snippets (lines starting with >>>), which are being tested during our development workflow. The following snippet initializes the demo project used throughout this page.

>>> from lino_book.projects.noi2.startup import *
>>> from django.db.models import Q

Configuration

publisher.use_markup

Whether to use markup (instead of wysiwyg) for editing content.

When this is False, the body of pages gets edited using a wysiwyg editor and stored as (bleached) html.

Content pages

content page

The basic building unit of a website or book, consisting of a title and a body.

>>> rt.show('publisher.Pages', column_names="id title publisher_tree", display_mode="grid", filter=Q(parent=None))
===== =============================== =========
 ID    Title                           Tree
----- ------------------------------- ---------
 1     Home                            index
 2     হোম                             index
 3     Startseite                      index
 4     Terms and conditions            index
 5     Terms and conditions            index
 6     Allgemeine Geschäftsbediungen   index
 7     Privacy policy                  index
 8     Privacy policy                  index
 9     Datenschutz                     index
 10    Cookie settings                 index
 11    Cookie settings                 index
 12    Cookie settings                 index
 13    Copyright                       index
 14    Copyright                       index
 15    Autorenrecht                    index
 16    About us                        index
 17    About us                        index
 18    Über uns                        index
 28    Laundry                         laundry
 54    Laundry                         laundry
 80    Laundry                         laundry
 106   Flying Circus                   circus
 117   Flying Circus                   circus
 128   Flying Circus                   circus
 139   FlyingCon                       circus
 140   Cascaded Continuous Voting      circus
 141   Liquid democracy                circus
 142   Digital vs analog               circus
 143   Software should be free         circus
 144   Synodality                      circus
===== =============================== =========
>>> home = publisher.Page.objects.get(pk=1)
>>> rt.show('publisher.TranslationsByPage', master_instance=home)
`⏏ <…>`__ | (bn) `হোম <…>`__, (de) `Startseite <…>`__
>>> rt.show('publisher.TranslationsByPage', master_instance=home, nosummary=True)
============ ========== ====
 Title        Language   ID
------------ ---------- ----
 হোম          bn         2
 Startseite   de         3
============ ========== ====

When I am on the English home page, the link to translation DE will redirect me to page #25:

>>> test_client.get("/p/1?ul=de")
<HttpResponseRedirect status_code=302, "text/html; charset=utf-8", url="/?ul=de">

The same happens when I am on the French home page:

>>> test_client.get("/p/3?ul=de")
<HttpResponse status_code=200, "text/html;charset="utf-8"">

The previous_page fields have been updated:

>>> rt.show(publisher.Pages, column_names="id title previous_page",
... display_mode="grid", filter=Q(language="en"), language="en")
...
===== ============================ =====================
 ID    Title                        Previous page
----- ---------------------------- ---------------------
 1     Home
 4     Terms and conditions
 7     Privacy policy
 10    Cookie settings
 13    Copyright
 16    About us
 19    Root pages                   Home
 22    Blog                         Root pages
 25    Calendar                     Blog
 28    Laundry
 29    Services                     Laundry
 30    Washing                      Services
 31    Drying                       Washing
 32    Air drying                   Drying
 33    Machine drying               Air drying
 34    Drying foos                  Machine drying
 35    Drying bars                  Drying foos
 36    Drying bazes                 Drying bars
 37    Ironing                      Drying bazes
 38    Prices                       Ironing
 39    Photos                       Prices
 40    New formatting               Photos
 41    Default formatting           New formatting
 42    Default formatting           Default formatting
 43    Thumbnail                    Default formatting
 44    Thumbnail left               Thumbnail
 45    Tiny thumbnail               Thumbnail left
 46    Tiny thumbnail left          Tiny thumbnail
 47    Wide                         Tiny thumbnail left
 48    Gallery                      Wide
 49    About us                     Gallery
 50    Team                         About us
 51    History                      Team
 52    Contact                      History
 53    Terms & conditions           Contact
 106   Flying Circus
 107   Places                       Flying Circus
 108   Programme                    Places
 109   Mission                      Programme
 110   Blog                         Mission
 111   Comments                     Blog
 112   About us                     Comments
 113   Team                         About us
 114   History                      Team
 115   Contact                      History
 116   Terms & conditions           Contact
 139   FlyingCon
 140   Cascaded Continuous Voting
 141   Liquid democracy
 142   Digital vs analog
 143   Software should be free
 144   Synodality
===== ============================ =====================

Classes reference

class lino.modlib.publisher.Page

The Django model that represents a content page.

class lino.modlib.publisher.PublisherBuildMethod

This deserves better documentation.

class lino.modlib.publisher.Publishable

Model mixin to add to models that are potentially publishable.

publisher_template

The name of the template to use when rendering a database row via the publisher interface.

“publisher/page.pub.html”

preview_publication

Show this database row via the publisher interface.

Icon: 🌐

class lino.modlib.publisher.PublishableContent

Model mixin to add to models that are potentially publishable.

Inherits from Publishable.

language

The language of this content.

publishing_state

Default value is ‘draft’

Pointer to PublishingStates

filler

Pointer to PageFillers

class lino.modlib.publisher.PublishingStates

A choicelist with the possible states of a publisher page.

>>> rt.show(publisher.PublishingStates, language="en")
======= =========== ========= ============= ========
 value   name        text      Button text   public
------- ----------- --------- ------------- --------
 10      draft       Draft                   No
 20      ready       Ready                   No
 30      published   Public                  Yes
 40      removed     Removed                 No
======= =========== ========= ============= ========
class lino.modlib.publisher.SpecialPages

A choicelist with the special pages available on this site.

>>> rt.show(publisher.SpecialPages, language="en")
=========== ====================== ======================================
 name        text                   Pages
----------- ---------------------- --------------------------------------
 home        Home                   `en <…>`__ | `bn <…>`__ | `de <…>`__
 terms       Terms and conditions   `en <…>`__ | `bn <…>`__ | `de <…>`__
 privacy     Privacy policy         `en <…>`__ | `bn <…>`__ | `de <…>`__
 cookies     Cookie settings        `en <…>`__ | `bn <…>`__ | `de <…>`__
 copyright   Copyright              `en <…>`__ | `bn <…>`__ | `de <…>`__
 about       About us               `en <…>`__ | `bn <…>`__ | `de <…>`__
 pages       pages                  `en <…>`__ | `bn <…>`__ | `de <…>`__
 blog        blog                   `en <…>`__ | `bn <…>`__ | `de <…>`__
 events      events                 `en <…>`__ | `bn <…>`__ | `de <…>`__
=========== ====================== ======================================

Configuration

publisher.locations

A tuple of 2-tuples (loc, cls) where loc is a location string and cls a data table.

>>> pprint(dd.plugins.publisher.locations)
(('b', lino_xl.lib.blogs.models.LatestEntries),
 ('p', lino.modlib.publisher.ui.Pages),
 ('f', lino.modlib.uploads.ui.Uploads),
 ('s', lino_xl.lib.sources.models.Sources),
 ('t', lino_xl.lib.topics.models.Topics))

When setting this setting (usually in a get_plugin_configs() method), the application developer should specify the data tables using their names. The above locations have been set in lino_cms.lib.cms.settings as follows:

yield ('publisher', 'locations', (
    ('b', 'blogs.LatestEntries'),
    ('p', 'publisher.Pages'),
    ('t', 'topics.Topics'),
    ('u', 'users.Users')))