<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from builtins import str <EOL> from builtins import object <EOL> import logging <EOL> logger = logging . getLogger ( __name__ ) <EOL> from django . db import models <EOL> from django . conf import settings <EOL> from lino . api import dd , _ <EOL> from lino import mixins <EOL> from lino . modlib . cal . choicelists import Recurrencies <EOL> from lino . modlib . cal . mixins import Reservation <EOL> from lino . modlib . contacts . mixins import ContactRelated <EOL> class BookingStates ( dd . Workflow ) : <EOL> required_roles = dd . required ( dd . SiteStaff ) <EOL> add = BookingStates . add_item <EOL> add ( '<STR_LIT>' , _ ( "<STR_LIT>" ) , '<STR_LIT>' , editable = True ) <EOL> add ( '<STR_LIT>' , _ ( "<STR_LIT>" ) , '<STR_LIT>' , editable = False ) <EOL> add ( '<STR_LIT>' , _ ( "<STR_LIT>" ) , '<STR_LIT>' , editable = False ) <EOL> add ( '<STR_LIT>' , _ ( "<STR_LIT>" ) , '<STR_LIT>' , editable = False ) <EOL> @ dd . receiver ( dd . pre_analyze ) <EOL> def setup_rooms_workflow ( sender = None , ** kw ) : <EOL> BookingStates . draft . add_transition ( <EOL> required_states = '<STR_LIT>' , <EOL> icon_name = "<STR_LIT>" ) <EOL> BookingStates . option . add_transition ( <EOL> required_states = '<STR_LIT>' , <EOL> icon_name = "<STR_LIT>" , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> BookingStates . registered . add_transition ( <EOL> required_states = '<STR_LIT>' , <EOL> icon_name = "<STR_LIT>" ) <EOL> BookingStates . cancelled . add_transition ( <EOL> required_states = '<STR_LIT>' , <EOL> icon_name = '<STR_LIT>' ) <EOL> @ dd . python_2_unicode_compatible <EOL> class Booking ( ContactRelated , Reservation ) : <EOL> class Meta ( object ) : <EOL> abstract = dd . is_abstract_model ( __name__ , '<STR_LIT>' ) <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> state = BookingStates . field ( default = BookingStates . draft . as_callable ) <EOL> event_type = dd . ForeignKey ( '<STR_LIT>' , null = True , blank = True , <EOL> help_text = _ ( """<STR_LIT>""" ) ) <EOL> def __str__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . _meta . verbose_name , self . pk , self . room ) <EOL> def update_cal_from ( self , ar ) : <EOL> return self . start_date <EOL> def update_cal_until ( self ) : <EOL> return self . end_date <EOL> def update_cal_calendar ( self ) : <EOL> return self . event_type <EOL> def update_cal_summary ( self , i ) : <EOL> if self . every_unit == Recurrencies . once : <EOL> return dd . babelattr ( self . event_type , '<STR_LIT>' ) <EOL> return "<STR_LIT>" % ( dd . babelattr ( self . event_type , '<STR_LIT>' ) , i ) <EOL> def before_auto_event_save ( self , event ) : <EOL> """<STR_LIT>""" <EOL> assert not settings . SITE . loading_from_dump <EOL> assert event . owner == self <EOL> if event . is_user_modified ( ) : <EOL> return <EOL> event . room = self . room <EOL> event . start_time = self . start_time <EOL> event . end_time = self . end_time <EOL> @ classmethod <EOL> def get_registrable_fields ( cls , site ) : <EOL> for f in super ( Booking , cls ) . get_registrable_fields ( site ) : <EOL> yield f <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> def before_state_change ( self , ar , old , new ) : <EOL> if new . name == '<STR_LIT>' : <EOL> if self . get_existing_auto_events ( ) . count ( ) == <NUM_LIT:0> : <EOL> raise Warning ( "<STR_LIT>" ) <EOL> def after_ui_save ( self , ar , cw ) : <EOL> super ( Booking , self ) . after_ui_save ( ar , cw ) <EOL> if self . state . editable : <EOL> self . update_reminders ( ar ) <EOL> dd . update_field ( Booking , '<STR_LIT>' , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> dd . update_field ( Booking , '<STR_LIT>' , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> dd . update_field ( Booking , '<STR_LIT>' , <EOL> default = Recurrencies . once . as_callable ) <EOL> dd . update_field ( Booking , '<STR_LIT>' , default = <NUM_LIT:1> ) <EOL> class BookingDetail ( dd . FormLayout ) : <EOL> main = "<STR_LIT>" <EOL> general = dd . Panel ( """<STR_LIT>""" , label = _ ( "<STR_LIT>" ) ) <EOL> class Bookings ( dd . Table ) : <EOL> model = '<STR_LIT>' <EOL> detail_layout = BookingDetail ( ) <EOL> insert_layout = """<STR_LIT>""" <EOL> column_names = "<STR_LIT>" <EOL> order_by = [ '<STR_LIT>' ] <EOL> parameters = mixins . ObservedPeriod ( <EOL> company = models . ForeignKey ( '<STR_LIT>' , blank = True , null = True ) , <EOL> state = BookingStates . field ( blank = True ) , <EOL> ) <EOL> params_layout = """<STR_LIT>""" <EOL> simple_param_fields = '<STR_LIT>' . split ( ) <EOL> @ classmethod <EOL> def get_request_queryset ( self , ar ) : <EOL> qs = super ( Bookings , self ) . get_request_queryset ( ar ) <EOL> if isinstance ( qs , list ) : <EOL> return qs <EOL> for n in self . simple_param_fields : <EOL> v = ar . param_values . get ( n ) <EOL> if v : <EOL> qs = qs . filter ( ** { n : v } ) <EOL> return qs <EOL> @ classmethod <EOL> def get_title_tags ( self , ar ) : <EOL> for t in super ( Bookings , self ) . get_title_tags ( ar ) : <EOL> yield t <EOL> for n in self . simple_param_fields : <EOL> v = ar . param_values . get ( n ) <EOL> if v : <EOL> yield str ( v ) <EOL> class BookingsByCompany ( Bookings ) : <EOL> master_key = "<STR_LIT>" </s>
