<s> """<STR_LIT>""" <EOL> __all__ = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> from gluon import * <EOL> from . . s3 import * <EOL> from s3layouts import S3PopupLink <EOL> class WorkContextModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> db = current . db <EOL> T = current . T <EOL> settings = current . deployment_settings <EOL> tablename = "<STR_LIT>" <EOL> self . define_table ( tablename , <EOL> Field ( "<STR_LIT:name>" ) , <EOL> * s3_meta_fields ( ) ) <EOL> return { } <EOL> @ staticmethod <EOL> def defaults ( ) : <EOL> return { } <EOL> class WorkJobModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> db = current . db <EOL> T = current . T <EOL> s3 = current . response . s3 <EOL> settings = current . deployment_settings <EOL> crud_strings = s3 . crud_strings <EOL> define_table = self . define_table <EOL> configure = self . configure <EOL> add_components = self . add_components <EOL> set_method = self . set_method <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT:name>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> crud_strings [ tablename ] = Storage ( <EOL> label_create = T ( "<STR_LIT>" ) , <EOL> title_display = T ( "<STR_LIT>" ) , <EOL> title_list = T ( "<STR_LIT>" ) , <EOL> title_update = T ( "<STR_LIT>" ) , <EOL> label_list_button = T ( "<STR_LIT>" ) , <EOL> msg_record_created = T ( "<STR_LIT>" ) , <EOL> msg_record_modified = T ( "<STR_LIT>" ) , <EOL> msg_record_deleted = T ( "<STR_LIT>" ) , <EOL> msg_list_empty = T ( "<STR_LIT>" ) <EOL> ) <EOL> represent = S3Represent ( lookup = tablename ) <EOL> job_type_id = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" % tablename , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = represent , <EOL> requires = IS_EMPTY_OR ( IS_ONE_OF ( <EOL> db , "<STR_LIT>" , <EOL> represent , <EOL> ) ) , <EOL> sortby = "<STR_LIT:name>" , <EOL> comment = S3PopupLink ( c = "<STR_LIT>" , <EOL> f = "<STR_LIT>" , <EOL> tooltip = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> ) <EOL> job_priority = { <NUM_LIT:1> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:2> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:3> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:4> : T ( "<STR_LIT>" ) , <EOL> } <EOL> job_status = ( ( "<STR_LIT>" , T ( "<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , T ( "<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , T ( "<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , T ( "<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , T ( "<STR_LIT>" ) ) , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> job_type_id ( ) , <EOL> Field ( "<STR_LIT:name>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:text>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_text_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:3> , <EOL> requires = IS_IN_SET ( job_priority , zero = None ) , <EOL> represent = S3Represent ( options = job_priority ) , <EOL> ) , <EOL> Field ( "<STR_LIT:status>" , <EOL> default = "<STR_LIT>" , <EOL> requires = IS_IN_SET ( job_status , zero = None , sort = False ) , <EOL> represent = S3Represent ( options = dict ( job_status ) ) , <EOL> ) , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> orderby = "<STR_LIT>" , <EOL> readable = True , <EOL> writable = True , <EOL> represent = self . org_site_represent , <EOL> ) , <EOL> s3_datetime ( "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_EMPTY_OR ( IS_FLOAT_IN_RANGE ( <NUM_LIT:0> , None ) ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:1> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_INT_IN_RANGE ( <NUM_LIT:1> , None ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_EMPTY_OR ( IS_INT_IN_RANGE ( <NUM_LIT:1> , None ) ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_INT_IN_RANGE ( <NUM_LIT:0> , None ) , <EOL> writable = False , <EOL> ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> crud_strings [ tablename ] = Storage ( <EOL> label_create = T ( "<STR_LIT>" ) , <EOL> title_display = T ( "<STR_LIT>" ) , <EOL> title_list = T ( "<STR_LIT>" ) , <EOL> title_update = T ( "<STR_LIT>" ) , <EOL> label_list_button = T ( "<STR_LIT>" ) , <EOL> msg_record_created = T ( "<STR_LIT>" ) , <EOL> msg_record_modified = T ( "<STR_LIT>" ) , <EOL> msg_record_deleted = T ( "<STR_LIT>" ) , <EOL> msg_list_empty = T ( "<STR_LIT>" ) <EOL> ) <EOL> filter_widgets = [ S3TextFilter ( [ "<STR_LIT:name>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> S3OptionsFilter ( "<STR_LIT>" ) , <EOL> S3OptionsFilter ( "<STR_LIT:status>" ) , <EOL> S3OptionsFilter ( "<STR_LIT>" , <EOL> hidden = True , <EOL> ) , <EOL> S3DateFilter ( "<STR_LIT>" , <EOL> hidden = True , <EOL> ) , <EOL> ] <EOL> list_fields = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:name>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:status>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> configure ( tablename , <EOL> filter_widgets = filter_widgets , <EOL> list_fields = list_fields , <EOL> list_layout = work_JobListLayout ( ) , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = work_SignUp , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = work_SignUp , <EOL> ) <EOL> add_components ( tablename , <EOL> work_assignment = "<STR_LIT>" , <EOL> ) <EOL> represent = S3Represent ( lookup = tablename , show_link = True ) <EOL> job_id = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" % tablename , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = represent , <EOL> requires = IS_ONE_OF ( db , "<STR_LIT>" , <EOL> represent , <EOL> ) , <EOL> sortby = "<STR_LIT:name>" , <EOL> comment = S3PopupLink ( c = "<STR_LIT>" , <EOL> f = "<STR_LIT>" , <EOL> tooltip = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> ) <EOL> auth = current . auth <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> job_id ( ) , <EOL> self . pr_person_id ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> crud_strings [ tablename ] = Storage ( <EOL> label_create = T ( "<STR_LIT>" ) , <EOL> title_display = T ( "<STR_LIT>" ) , <EOL> title_list = T ( "<STR_LIT>" ) , <EOL> title_update = T ( "<STR_LIT>" ) , <EOL> label_list_button = T ( "<STR_LIT>" ) , <EOL> msg_record_created = T ( "<STR_LIT>" ) , <EOL> msg_record_modified = T ( "<STR_LIT>" ) , <EOL> msg_record_deleted = T ( "<STR_LIT>" ) , <EOL> msg_list_empty = T ( "<STR_LIT>" ) <EOL> ) <EOL> configure ( tablename , <EOL> onaccept = self . assignment_onaccept , <EOL> ondelete = self . assignment_ondelete , <EOL> onvalidation = self . assignment_onvalidation , <EOL> ) <EOL> return { "<STR_LIT>" : job_id , <EOL> } <EOL> @ staticmethod <EOL> def defaults ( ) : <EOL> """<STR_LIT>""" <EOL> dummy = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" , <EOL> readable = False , <EOL> writable = False , <EOL> ) <EOL> return { "<STR_LIT>" : lambda ** attr : dummy ( "<STR_LIT>" ) , <EOL> } <EOL> @ staticmethod <EOL> def assignment_onvalidation ( form ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> s3db = current . s3db <EOL> table = s3db . work_assignment <EOL> form_vars = form . vars <EOL> if "<STR_LIT:id>" in form_vars : <EOL> record_id = form_vars . id <EOL> elif hasattr ( form , "<STR_LIT>" ) : <EOL> record_id = form . record_id <EOL> else : <EOL> record_id = None <EOL> try : <EOL> job_id = form_vars . job_id <EOL> except AttributeError : <EOL> job_id = None <EOL> try : <EOL> person_id = form_vars . person_id <EOL> except AttributeError : <EOL> person_id = None <EOL> if ( job_id is None or person_id is None ) : <EOL> if record_id : <EOL> query = ( table . id == record_id ) & ( table . deleted != True ) <EOL> record = db ( query ) . select ( table . job_id , <EOL> table . person_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if record : <EOL> job_id = record . job_id <EOL> person_id = record . person_id <EOL> else : <EOL> if job_id is None : <EOL> job_id = table . job_id . default <EOL> if person_id is None : <EOL> person_id = table . person_id . default <EOL> if job_id and person_id : <EOL> query = ( table . job_id == job_id ) & ( table . person_id == person_id ) & ( table . deleted != True ) <EOL> if record_id : <EOL> query = ( table . id != record_id ) & query <EOL> duplicate = db ( query ) . select ( table . id , limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if duplicate : <EOL> msg = current . T ( "<STR_LIT>" ) <EOL> form . errors [ "<STR_LIT>" ] = msg <EOL> @ classmethod <EOL> def assignment_onaccept ( cls , form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> formvars = form . vars <EOL> except AttributeError : <EOL> return <EOL> db = current . db <EOL> atable = current . s3db . work_assignment <EOL> if "<STR_LIT>" not in formvars : <EOL> if "<STR_LIT:id>" not in formvars : <EOL> return <EOL> record_id = formvars . id <EOL> row = db ( atable . id == record_id ) . select ( atable . job_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if not row : <EOL> return <EOL> job_id = row . job_id <EOL> else : <EOL> job_id = formvars . job_id <EOL> if job_id : <EOL> cls . update_workers_assigned ( job_id ) <EOL> return <EOL> @ classmethod <EOL> def assignment_ondelete ( cls , row ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> record_id = row . id <EOL> except AttributeError : <EOL> return <EOL> db = current . db <EOL> atable = current . s3db . work_assignment <EOL> row = db ( atable . id == record_id ) . select ( atable . deleted_fk , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if row and row . deleted_fk : <EOL> data = json . loads ( row . deleted_fk ) <EOL> job_id = data . get ( "<STR_LIT>" ) <EOL> if job_id : <EOL> cls . update_workers_assigned ( job_id ) <EOL> return <EOL> @ staticmethod <EOL> def update_workers_assigned ( job_id ) : <EOL> """<STR_LIT>""" <EOL> if not job_id : <EOL> return <EOL> db = current . db <EOL> s3db = current . s3db <EOL> jtable = s3db . work_job <EOL> atable = s3db . work_assignment <EOL> query = ( atable . job_id == job_id ) & ( atable . deleted != True ) <EOL> count = atable . id . count ( ) <EOL> row = db ( query ) . select ( count , limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if not row : <EOL> workers_assigned = <NUM_LIT:0> <EOL> else : <EOL> workers_assigned = row [ count ] <EOL> db ( jtable . id == job_id ) . update ( workers_assigned = workers_assigned , <EOL> modified_by = jtable . modified_by , <EOL> modified_on = jtable . modified_on , <EOL> ) <EOL> return <EOL> def work_rheader ( r , tabs = [ ] ) : <EOL> """<STR_LIT>""" <EOL> if r . representation != "<STR_LIT:html>" : <EOL> return None <EOL> tablename = r . tablename <EOL> record = r . record <EOL> rheader = None <EOL> rheader_fields = [ ] <EOL> if record : <EOL> T = current . T <EOL> if tablename == "<STR_LIT>" : <EOL> if not tabs : <EOL> tabs = [ ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) , <EOL> ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) , <EOL> ] <EOL> rheader_fields = [ [ "<STR_LIT:name>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT:status>" ] , <EOL> ] <EOL> rheader = S3ResourceHeader ( rheader_fields , tabs ) ( r ) <EOL> return rheader <EOL> class work_SignUp ( S3Method ) : <EOL> """<STR_LIT>""" <EOL> def apply_method ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> output = { } <EOL> if r . http == "<STR_LIT:POST>" : <EOL> if r . representation == "<STR_LIT>" : <EOL> method = r . method <EOL> if method == "<STR_LIT>" : <EOL> output = self . signup ( r , ** attr ) <EOL> elif method == "<STR_LIT>" : <EOL> output = self . cancel ( r , ** attr ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_METHOD ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_METHOD ) <EOL> return output <EOL> def signup ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> s3db = current . s3db <EOL> job_id = self . record_id <EOL> if not job_id : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_RECORD ) <EOL> atable = s3db . work_assignment <EOL> auth = current . auth <EOL> person_id = auth . s3_logged_in_person ( ) <EOL> if not person_id or not auth . s3_has_permission ( "<STR_LIT>" , atable ) : <EOL> auth . permission . fail ( ) <EOL> query = ( atable . job_id == job_id ) & ( atable . person_id == person_id ) & ( atable . deleted != True ) <EOL> row = current . db ( query ) . select ( atable . id , limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if not row : <EOL> assignment = { "<STR_LIT>" : job_id , <EOL> "<STR_LIT>" : person_id , <EOL> } <EOL> assignment_id = atable . insert ( ** assignment ) <EOL> if assignment_id : <EOL> current . audit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> record = assignment_id , <EOL> representation = r . representation , <EOL> ) <EOL> assignment [ "<STR_LIT:id>" ] = assignment_id <EOL> s3db . update_super ( atable , assignment ) <EOL> auth . s3_set_record_owner ( atable , assignment_id ) <EOL> auth . s3_make_session_owner ( atable , assignment_id ) <EOL> s3db . onaccept ( atable , assignment ) <EOL> output = current . xml . json_message ( True ) <EOL> return output <EOL> def cancel ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> s3db = current . s3db <EOL> job_id = self . record_id <EOL> if not job_id : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_RECORD ) <EOL> atable = s3db . work_assignment <EOL> auth = current . auth <EOL> person_id = auth . s3_logged_in_person ( ) <EOL> if not person_id or not auth . s3_has_permission ( "<STR_LIT>" , atable ) : <EOL> auth . permission . fail ( ) <EOL> query = ( FS ( "<STR_LIT>" ) == job_id ) & ( FS ( "<STR_LIT>" ) == person_id ) <EOL> assignments = s3db . resource ( "<STR_LIT>" , filter = query ) <EOL> success = assignments . delete ( ) <EOL> if not success : <EOL> error = assignments . error or current . ERROR . NOT_PERMITTED <EOL> r . error ( <NUM_LIT> , error ) <EOL> output = current . xml . json_message ( True ) <EOL> return output <EOL> class work_JobListLayout ( S3DataListLayout ) : <EOL> """<STR_LIT>""" <EOL> list_fields = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:name>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:status>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> def __init__ ( self , profile = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> super ( work_JobListLayout , self ) . __init__ ( profile = profile ) <EOL> self . current_assignments = set ( ) <EOL> def prep ( self , resource , records ) : <EOL> logged_in_person = current . auth . s3_logged_in_person ( ) <EOL> if not logged_in_person : <EOL> self . logged_in = False <EOL> return <EOL> self . logged_in = True <EOL> db = current . db <EOL> atable = current . s3db . work_assignment <EOL> record_ids = [ record [ "<STR_LIT>" ] [ "<STR_LIT>" ] for record in records ] <EOL> query = ( atable . job_id . belongs ( record_ids ) ) & ( atable . person_id == logged_in_person ) & ( atable . deleted != True ) <EOL> rows = db ( query ) . select ( atable . job_id ) <EOL> self . current_assignments = set ( row . job_id for row in rows ) <EOL> def render_header ( self , list_id , item_id , resource , rfields , record ) : <EOL> """<STR_LIT>""" <EOL> T = current . T <EOL> toolbox = self . render_toolbox ( list_id , <EOL> resource , <EOL> record , <EOL> ) <EOL> if not toolbox : <EOL> toolbox = "<STR_LIT>" <EOL> place = record [ "<STR_LIT>" ] <EOL> date = record [ "<STR_LIT>" ] <EOL> hours_planned = record [ "<STR_LIT>" ] <EOL> job_type = record [ "<STR_LIT>" ] <EOL> header = DIV ( SPAN ( place , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> SPAN ( date , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> SPAN ( "<STR_LIT>" % ( hours_planned , T ( "<STR_LIT>" ) ) , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> SPAN ( job_type , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> toolbox , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> return header <EOL> def render_body ( self , list_id , item_id , resource , rfields , record ) : <EOL> """<STR_LIT>""" <EOL> T = current . T <EOL> title = record [ "<STR_LIT>" ] <EOL> details = record [ "<STR_LIT>" ] <EOL> status = record [ "<STR_LIT>" ] <EOL> priority = record [ "<STR_LIT>" ] <EOL> last_modified = record [ "<STR_LIT>" ] <EOL> date_line = DIV ( LABEL ( T ( "<STR_LIT>" ) , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> SPAN ( status , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> LABEL ( T ( "<STR_LIT>" ) , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> SPAN ( priority , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> LABEL ( T ( "<STR_LIT>" ) , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> SPAN ( last_modified , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> footer = self . render_footer ( list_id , <EOL> item_id , <EOL> resource , <EOL> rfields , <EOL> record , <EOL> ) <EOL> body = DIV ( DIV ( title , <EOL> _class = "<STR_LIT>" <EOL> ) , <EOL> details , <EOL> date_line , <EOL> footer , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> return DIV ( body , _class = "<STR_LIT>" ) <EOL> def render_footer ( self , list_id , item_id , resource , rfields , record ) : <EOL> """<STR_LIT>""" <EOL> T = current . T <EOL> raw = record [ "<STR_LIT>" ] <EOL> button = "<STR_LIT>" <EOL> actionable = False <EOL> status = raw [ "<STR_LIT>" ] <EOL> if status == "<STR_LIT>" : <EOL> button_text = T ( "<STR_LIT>" ) <EOL> elif status == "<STR_LIT>" : <EOL> button_text = T ( "<STR_LIT>" ) <EOL> elif status == "<STR_LIT>" : <EOL> button_text = T ( "<STR_LIT>" ) <EOL> else : <EOL> button_text = "<STR_LIT>" <EOL> actionable = True <EOL> if actionable : <EOL> if not self . logged_in : <EOL> button = A ( T ( "<STR_LIT>" ) , <EOL> _href = URL ( c = "<STR_LIT:default>" , f = "<STR_LIT:user>" , <EOL> args = [ "<STR_LIT>" ] , <EOL> vars = { "<STR_LIT>" : URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" ] , <EOL> ) , <EOL> } , <EOL> ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> else : <EOL> record_id = raw [ "<STR_LIT>" ] <EOL> if record_id in self . current_assignments : <EOL> button = A ( "<STR_LIT>" , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> elif status != "<STR_LIT>" : <EOL> start_date = raw [ "<STR_LIT>" ] <EOL> duration = raw [ "<STR_LIT>" ] <EOL> if start_date : <EOL> delta = ( start_date - current . request . utcnow ) <EOL> hours = ( delta . days * <NUM_LIT> + delta . seconds ) / <NUM_LIT> <EOL> hours += duration if duration else <NUM_LIT:1> <EOL> if hours < <NUM_LIT:0> : <EOL> actionable = False <EOL> button_text = T ( "<STR_LIT>" ) <EOL> if actionable : <EOL> workers_needed = raw [ "<STR_LIT>" ] <EOL> if not workers_needed : <EOL> workers_needed = raw [ "<STR_LIT>" ] <EOL> workers_assigned = raw [ "<STR_LIT>" ] <EOL> if workers_assigned < workers_needed : <EOL> button = A ( T ( "<STR_LIT>" ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> else : <EOL> actionable = False <EOL> button_text = T ( "<STR_LIT>" ) <EOL> else : <EOL> actionable = False <EOL> button_text = T ( "<STR_LIT>" ) <EOL> if not actionable : <EOL> button = A ( button_text , <EOL> _class = "<STR_LIT>" , <EOL> _disabled = "<STR_LIT>" , <EOL> ) <EOL> return DIV ( button , _class = "<STR_LIT>" ) <EOL> def render_toolbox ( self , list_id , resource , record ) : <EOL> """<STR_LIT>""" <EOL> T = current . T <EOL> record_id = record [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> has_permission = current . auth . s3_has_permission <EOL> table = current . db . work_job <EOL> if has_permission ( "<STR_LIT>" , table , record_id = record_id ) : <EOL> edit_btn = A ( ICON ( "<STR_LIT>" ) , <EOL> _href = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ record_id , "<STR_LIT>" ] , <EOL> vars = { "<STR_LIT>" : list_id , <EOL> "<STR_LIT>" : record_id , <EOL> } <EOL> ) , <EOL> _class = "<STR_LIT>" , <EOL> _title = T ( "<STR_LIT>" ) , <EOL> ) <EOL> else : <EOL> edit_btn = "<STR_LIT>" <EOL> if has_permission ( "<STR_LIT>" , table , record_id = record_id ) : <EOL> delete_btn = A ( ICON ( "<STR_LIT>" ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> else : <EOL> delete_btn = "<STR_LIT>" <EOL> return DIV ( edit_btn , <EOL> delete_btn , <EOL> _class = "<STR_LIT>" , <EOL> ) </s>
