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

system : Site-wide system settings

The lino.modlib.system plugin defines some system features that are automatically installed with every Lino application.

It especially provides the SiteConfig model.

Side note: Code snippets (lines starting with >>>) in this document get tested as part of our development workflow. The following initialization snippet tells you which demo project is being used in this document.

>>> import lino
>>> lino.startup('lino_book.projects.min9.settings')
>>> from lino.api.doctest import *

Editable site parameters

Lino provides a standard method for defining persistent site parameters that are editable by end users (at least for those who have access permission).

class lino.modlib.system.Dashboard

This is your main page.

class lino.modlib.system.SiteConfig

A singleton database object used to store persistent site parameters.

This model has exactly one instance, which is accessible as the settings.SITE.site_config property.

default_build_method

The default build method to use when rendering printable documents.

If this field is empty, Lino uses the value found in lino.core.site.Site.default_build_method.

simulate_today

A constant user-defined date to be substituted as current system date.

This should be empty except in situations such as a posteriori data entry in a prototype.

site_company

The site operator, i.e. the legal person that operates this Lino site.

See How to specify the site operator.

If no plugin named ‘contacts’ is installed, then this is a dummy field and always contains None.

hide_events_before

If this is not empty, any calendar events before that date are being hidden in certain places.

For example OverdueEvents, EntriesByController, …

Injected by lino_xl.lib.cal.

class lino.modlib.system.SiteConfigManager

Always return the cached instance which holds the one and only database instance.

This is to avoid the following situation:

  • User 1 opens the Configure ‣ System‣ System Parameters dialog

  • User 2 creates a new Person (which increases next_partner_id)

  • User 1 clicks on Save.

next_partner_id may not get overwritten by its old value when User 1 clicks “Save”.

class lino.modlib.system.Lockable

Mixin to add row-level edit locking to any model.

Models with row-level edit locking are not editable in detail view by default. All form fields are disabled. The user must click Edit in order to request an edit lock for that row. This will enable all fields (except those which are disabled for some other reason).

Caveats: locking a row and then navigating away without changing anything will leave the row locked.

class lino.modlib.system.BuildSiteCache

Rebuild the site cache. This action is available on About.

class lino.modlib.system.SiteConfigs

The table used to present the SiteConfig row in a Detail form.

See also lino.core.site.Site.get_site_config().

Recurrences in the system

class lino.modlib.system.RecurrenceSet

Mixin for database models that express a set of repeating (“recurrent”) events. Example usage can be found in Event generators.

start_date

The start date of the first meeting to be generated.

end_date

The end date of the first meeting to be generated. Leave this field empty if the meetings last less than one day.

start_time
end_time
every

The frequency of periodic iteration: daily, weekly, monthly or yearly.

every_unit

The interval between each periodic iteration.

For example, when every is yearly, an every_unit of 2 means once every two years. The default value is 1.

positions

Space-separated list of one or several positions within the recurrency cycle.

Each position is a positive or negative integer expressing which occurrence is to be taken from the recurrency period. For example if positions is -1 and every_unit is monthly, we get the last day of every month.

Inspired by dateutil.rrule.

max_events

Maximum number of calendar entries to generate.

monday
tuesday
wednesday
thursday
friday
saturday
sunday
weekdays_text

A virtual field returning the textual formulation of the weekdays where the recurrence occurs.

Usage examples see cal : Calendar functionality.

class lino.modlib.system.Recurrences

List of possible choices for a ‘recurrency’ field.

A recurrency (an item of this choicelist) is also a DurationUnit.

easter

Repeat events yearly, moving them together with the Easter data of that year.

Lino computes the offset (number of days) between this rule’s start_date and the Easter date of that year, and generates subsequent events so that this offset remains the same.

The days of the week

class lino.modlib.system.Weekdays

A choicelist with the seven days of a week.

The available values in the system are.

>>> rt.show(system.Weekdays)
======= =========== ===========
 value   name        text
------- ----------- -----------
 1       monday      Monday
 2       tuesday     Tuesday
 3       wednesday   Wednesday
 4       thursday    Thursday
 5       friday      Friday
 6       saturday    Saturday
 7       sunday      Sunday
======= =========== ===========
lino.modlib.system.WORKDAYS

The five workdays of the week (Monday to Friday).

Duration units

The system plugin defines DurationUnits choicelist, a site-wide list of duration units.

class lino.modlib.system.DurationUnits

The list of possible duration units defined by this application.

This is used as the selection list for the duration_unit field of a calendar entry.

Every item is an instance of DurationUnit.

class lino.modlib.system.DurationUnit

Base class for the choices in the DurationUnits choicelist.

add_duration(unit, orig, value)

Return a date or datetime obtained by adding value times this unit to the specified value orig. Returns None is orig is empty.

This is intended for use as a curried magic method of a specified list item:

The available values in the system are:

>>> rt.show(system.DurationUnits)
======= ========= =========
 value   name      text
------- --------- ---------
 s       seconds   seconds
 m       minutes   minutes
 h       hours     hours
 D       days      days
 W       weeks     weeks
 M       months    months
 Y       years     years
======= ========= =========

Duration units can be used for arithmetic operation on durations. For example:

>>> from lino.modlib.system.choicelists import DurationUnits
>>> start_date = i2d(20111026)
>>> DurationUnits.months.add_duration(start_date, 2)
datetime.date(2011, 12, 26)
>>> from lino.utils import i2d
>>> start_date = i2d(20111026)
>>> DurationUnits.months.add_duration(start_date, 2)
datetime.date(2011, 12, 26)
>>> DurationUnits.months.add_duration(start_date, -2)
datetime.date(2011, 8, 26)
>>> start_date = i2d(20110131)
>>> DurationUnits.months.add_duration(start_date, 1)
datetime.date(2011, 2, 28)
>>> DurationUnits.months.add_duration(start_date, -1)
datetime.date(2010, 12, 31)
>>> DurationUnits.months.add_duration(start_date, -2)
datetime.date(2010, 11, 30)
>>> start_date = i2d(20140401)
>>> DurationUnits.months.add_duration(start_date, 3)
datetime.date(2014, 7, 1)
>>> DurationUnits.years.add_duration(start_date, 1)
datetime.date(2015, 4, 1)

Display colors

class lino.modlib.system.DisplayColors

A list of colors to be specified for displaying.

>>> rt.show(system.DisplayColors)
======= ========= =========
 value   name      text
------- --------- ---------
 100     white     White
 110     gray      Gray
 120     black     Black
 210     red       Red
 220     orange    Orange
 230     yellow    Yellow
 240     green     Green
 250     blue      Blue
 260     magenta   Magenta
 270     violet    Violet
 300     silver    Silver
 310     maroon    Maroon
 311     peru      Peru
 320     olive     Olive
 330     aqua      Aqua
 340     navy      Navy
 350     fuchsia   Fuchsia
 351     purple    Purple
======= ========= =========

Miscellaneous

class lino.modlib.system.BleachChecker

A data checker used to find unbleached html content.

class lino.modlib.system.Genders

Defines the possible choices for the gender of a person (“male”, “female” and “nonbinary”).

>>> rt.show('system.Genders')
======= =========== ===========
 value   name        text
------- ----------- -----------
 M       male        Male
 F       female      Female
 N       nonbinary   Nonbinary
======= =========== ===========

This choicelist is used for deciding the salutation (Mr/Mrs) and for its mf() method. See The Human mixin.

class lino.modlib.system.YesNo

A choicelist with two values “Yes” and “No”.

Used e.g. to define parameter panel fields for BooleanFields:

foo = dd.YesNo.field(_("Foo"), blank=True)
class lino.modlib.system.ObservedEvent

Base class for choices of “observed event”-style choicelists.

add_filter(self, qs, pv)

Add a filter to the given Django queryset. The given obj must be either a datetime.date object or must have two attributes start_date and end_date. The easiest way is to have it an instance of DateRange or DateRangeValue.

class lino.modlib.system.PeriodEvents

The list of things you can observe on a lino.mixins.periods.DateRange.

class lino.modlib.system.TimeZones

Used by lino.modlib.users.User.time_zone and lino_xl.lib.working.Session.time_zone.

See also USE_TZ.

class lino.modlib.system.DateFormats

Used by lino.modlib.users.User.date_format.