Coverage for lino/modlib/system/choicelists.py : 64%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: UTF-8 -*- # Copyright 2011-2015 Luc Saffre # License: BSD (see file COPYING for details)
Miscellaneous mixins for `lino.modlib.system`.
"""
""" A choicelist with two values "Yes" and "No".
.. django2rst::
from lino.modlib.system.choicelists import YesNo rt.show(YesNo)
Used e.g. to define parameter panel fields for BooleanFields::
foo = dd.YesNo.field(_("Foo"), blank=True)
"""
""" Defines the two possible choices "male" and "female" for the gender of a person.
.. django2rst::
from lino.modlib.system.choicelists import Genders rt.show(Genders)
See :ref:`lino.tutorial.human` for examples. See :doc:`/dev/choicelists`. """
if isinstance(obj, datetime.date): obj = AttrDict(start_date=obj, end_date=obj)
if obj.start_date is None or obj.end_date is None: return qs
if self.name == 'started': qs = qs.filter(start_date__gte=obj.start_date) qs = qs.filter(start_date__lte=obj.end_date) elif self.name == 'ended': qs = qs.filter(end_date__isnull=False) qs = qs.filter(end_date__gte=obj.start_date) qs = qs.filter(end_date__lte=obj.end_date) elif self.name == 'active': qs = qs.filter(Q(start_date__isnull=True) | Q(start_date__lte=obj.end_date)) qs = qs.filter(Q(end_date__isnull=True) | Q(end_date__gte=obj.start_date)) return qs
"""The list of things you can observe on a :class:`DatePeriod`. The default list has the following choices:
.. django2rst::
from lino.modlib.system.choicelists import PeriodEvents rt.show(PeriodEvents)
"""
|