<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import datetime <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . db . models import Q <EOL> from lino . core . choicelists import ChoiceList , Choice <EOL> from lino . utils import AttrDict <EOL> class YesNo ( ChoiceList ) : <EOL> """<STR_LIT>""" <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> add = YesNo . add_item <EOL> add ( '<STR_LIT:y>' , _ ( "<STR_LIT>" ) , '<STR_LIT:yes>' ) <EOL> add ( '<STR_LIT:n>' , _ ( "<STR_LIT>" ) , '<STR_LIT>' ) <EOL> class Genders ( ChoiceList ) : <EOL> """<STR_LIT>""" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> add = Genders . add_item <EOL> add ( '<STR_LIT:M>' , _ ( "<STR_LIT>" ) , '<STR_LIT>' ) <EOL> add ( '<STR_LIT:F>' , _ ( "<STR_LIT>" ) , '<STR_LIT>' ) <EOL> class PeriodEvent ( Choice ) : <EOL> def add_filter ( self , qs , obj ) : <EOL> if isinstance ( obj , datetime . date ) : <EOL> obj = AttrDict ( start_date = obj , end_date = obj ) <EOL> if obj . start_date is None or obj . end_date is None : <EOL> return qs <EOL> if self . name == '<STR_LIT>' : <EOL> qs = qs . filter ( start_date__gte = obj . start_date ) <EOL> qs = qs . filter ( start_date__lte = obj . end_date ) <EOL> elif self . name == '<STR_LIT>' : <EOL> qs = qs . filter ( end_date__isnull = False ) <EOL> qs = qs . filter ( end_date__gte = obj . start_date ) <EOL> qs = qs . filter ( end_date__lte = obj . end_date ) <EOL> elif self . name == '<STR_LIT>' : <EOL> qs = qs . filter ( Q ( start_date__isnull = True ) | <EOL> Q ( start_date__lte = obj . end_date ) ) <EOL> qs = qs . filter ( Q ( end_date__isnull = True ) | <EOL> Q ( end_date__gte = obj . start_date ) ) <EOL> return qs <EOL> class PeriodEvents ( ChoiceList ) : <EOL> """<STR_LIT>""" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> item_class = PeriodEvent <EOL> add = PeriodEvents . add_item <EOL> add ( '<STR_LIT>' , _ ( "<STR_LIT>" ) , '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , _ ( "<STR_LIT>" ) , '<STR_LIT>' ) <EOL> add ( '<STR_LIT>' , _ ( "<STR_LIT>" ) , '<STR_LIT>' ) </s>
