Welcome | Get started | Dive into Lino | Contribute | Topics | Reference | More

lino.mixins.periods

Defines classes related to date ranges.

Functions

is_future(self)

rangefmt(r)

rangetext(self[, fmt, empty_text])

Return a textual representation of the given date range.

Classes

CombinedDateTime(*args, **kwargs)

Mixin for models which have at least one couple of date and time fields which form a kind of editable timestamp field.

DateRange(*args, **kwargs)

Mixin for models that represent a period defined by a start date and an end date.

DateRangeObservable(*args, **kwargs)

Ended(*args, **kwargs)

Mixin for models with two fields end_date and end_time.

Monthly([verbose_name_start, verbose_name_end])

An ObservedDateRange which defaults to the current month.

ObservedDateRange([verbose_name_start, ...])

lino.core.param_panel.ParameterPanel with two fields start_date and end_date which default to empty.

Started(*args, **kwargs)

Adds two fields start_date and start_time.

Today([verbose_name])

A ParameterPanel with a field today that defaults to today.

Weekly([verbose_name_start, verbose_name_end])

An ObservedDateRange which defaults to the current week.

Yearly([verbose_name_start, verbose_name_end])

An ObservedDateRange for which start_date defaults to Jan 1st and end_date to Dec 31 of the current year.

lino.mixins.periods.rangetext(self, fmt=<function fdl>, empty_text='')

Return a textual representation of the given date range.

The date range is to be specified as an object that has two attributes start_date and end_date.

See tested examples in aids : Aid grantings. Also used by lino_xl.lib.vat.

class lino.mixins.periods.CombinedDateTime(*args, **kwargs)

Bases: Model

Mixin for models which have at least one couple of date and time fields which form a kind of editable timestamp field.

get_time_zone()

The time zone for the date and time fields in this model.

Expected to always return an instance of lino.modlib.about.choicelists.TimeZone.

May get overridden to return the author's timezone.

set_datetime(name, value)

Given a datetime value, update the two corresponding fields FOO_date and FOO_time (where FOO is specified in name which must be either "start" or "end").

get_datetime(name, altname=None)

Return a datetime value from the two corresponding date and time fields.

name can be 'start' or 'end'.

The optional altname can be used e.g. in a single-day calendar event to support having end_date empty, meaning "same as start_date". In that case you should ask get_datetime("end", "start").

class lino.mixins.periods.Started(*args, **kwargs)

Bases: CombinedDateTime

Adds two fields start_date and start_time.

start_date
start_time
save(*args, **kw)

Fills default value "today" to start_date

class lino.mixins.periods.Ended(*args, **kwargs)

Bases: CombinedDateTime

Mixin for models with two fields end_date and end_time.

end_date
end_time
get_duration()

Return the duration in hours.

class lino.mixins.periods.DateRange(*args, **kwargs)

Bases: DateRangeObservable

Mixin for models that represent a period defined by a start date and an end date.

Designed for usage with lino.modlib.system.PeriodEvents.

class lino.mixins.periods.ObservedDateRange(verbose_name_start='Date from', verbose_name_end='until', **kwargs)

Bases: ParameterPanel

lino.core.param_panel.ParameterPanel with two fields start_date and end_date which default to empty.

Note that you must define yourself a get_request_queryset method in order to actually use these two parameter fields.

class lino.mixins.periods.Yearly(verbose_name_start='Date from', verbose_name_end='until', **kwargs)

Bases: ObservedDateRange

An ObservedDateRange for which start_date defaults to Jan 1st and end_date to Dec 31 of the current year.

class lino.mixins.periods.Monthly(verbose_name_start='Date from', verbose_name_end='until', **kwargs)

Bases: ObservedDateRange

An ObservedDateRange which defaults to the current month.

class lino.mixins.periods.Weekly(verbose_name_start='Date from', verbose_name_end='until', **kwargs)

Bases: ObservedDateRange

An ObservedDateRange which defaults to the current week.

class lino.mixins.periods.Today(verbose_name='Situation on', **kw)

Bases: ParameterPanel

A ParameterPanel with a field today that defaults to today.