<s> """<STR_LIT>""" <EOL> __all__ = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> from gluon import * <EOL> from gluon . storage import Storage <EOL> from . . s3 import * <EOL> SEPARATORS = ( "<STR_LIT:U+002C>" , "<STR_LIT::>" ) <EOL> class S3ChannelModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> db = current . db <EOL> define_table = self . define_table <EOL> channel_types = Storage ( msg_email_channel = T ( "<STR_LIT>" ) , <EOL> msg_facebook_channel = T ( "<STR_LIT>" ) , <EOL> msg_mcommons_channel = T ( "<STR_LIT>" ) , <EOL> msg_rss_channel = T ( "<STR_LIT>" ) , <EOL> msg_sms_modem_channel = T ( "<STR_LIT>" ) , <EOL> msg_sms_webapi_channel = T ( "<STR_LIT>" ) , <EOL> msg_sms_smtp_channel = T ( "<STR_LIT>" ) , <EOL> msg_tropo_channel = T ( "<STR_LIT>" ) , <EOL> msg_twilio_channel = T ( "<STR_LIT>" ) , <EOL> msg_twitter_channel = T ( "<STR_LIT>" ) , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> self . super_entity ( tablename , "<STR_LIT>" , <EOL> channel_types , <EOL> Field ( "<STR_LIT:name>" , <EOL> ) , <EOL> Field ( "<STR_LIT:description>" , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> ) , <EOL> ) <EOL> table = db [ tablename ] <EOL> table . instance_type . readable = True <EOL> channel_id = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" % tablename , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ondelete = "<STR_LIT>" , <EOL> represent = S3Represent ( lookup = tablename ) , <EOL> requires = IS_EMPTY_OR ( <EOL> IS_ONE_OF_EMPTY ( db , "<STR_LIT>" ) ) , <EOL> ) <EOL> self . add_components ( tablename , <EOL> msg_channel_status = "<STR_LIT>" , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> * s3_timestamp ( ) ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> channel_id ( ) , <EOL> Field ( "<STR_LIT:status>" , <EOL> represent = lambda v : v or current . messages [ "<STR_LIT>" ] , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> return dict ( msg_channel_id = channel_id , <EOL> msg_channel_enable = self . channel_enable , <EOL> msg_channel_disable = self . channel_disable , <EOL> msg_channel_enable_interactive = self . channel_enable_interactive , <EOL> msg_channel_disable_interactive = self . channel_disable_interactive , <EOL> msg_channel_onaccept = self . channel_onaccept , <EOL> msg_channel_poll = self . channel_poll , <EOL> ) <EOL> @ staticmethod <EOL> def channel_enable ( tablename , channel_id ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> s3db = current . s3db <EOL> table = s3db . table ( tablename ) <EOL> record = db ( table . channel_id == channel_id ) . select ( table . id , <EOL> table . enabled , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> ) . first ( ) <EOL> if not record . enabled : <EOL> record . update_record ( enabled = True ) <EOL> s3db . update_super ( table , record ) <EOL> ptable = s3db . msg_parser <EOL> query = ( ptable . channel_id == channel_id ) & ( ptable . deleted == False ) <EOL> parsers = db ( query ) . select ( ptable . id ) <EOL> for parser in parsers : <EOL> s3db . msg_parser_enable ( parser . id ) <EOL> ttable = db . scheduler_task <EOL> args = '<STR_LIT>' % ( tablename , channel_id ) <EOL> query = ( ( ttable . function_name == "<STR_LIT>" ) & ( ttable . args == args ) & ( ttable . status . belongs ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) ) ) <EOL> exists = db ( query ) . select ( ttable . id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if exists : <EOL> return "<STR_LIT>" <EOL> else : <EOL> current . s3task . schedule_task ( "<STR_LIT>" , <EOL> args = [ tablename , channel_id ] , <EOL> period = <NUM_LIT> , <EOL> timeout = <NUM_LIT> , <EOL> repeats = <NUM_LIT:0> <EOL> ) <EOL> return "<STR_LIT>" <EOL> @ staticmethod <EOL> def channel_enable_interactive ( r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> tablename = r . tablename <EOL> result = current . s3db . msg_channel_enable ( tablename , r . record . channel_id ) <EOL> current . session . confirmation = result <EOL> fn = tablename . split ( "<STR_LIT:_>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> redirect ( URL ( f = fn ) ) <EOL> @ staticmethod <EOL> def channel_disable ( tablename , channel_id ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> s3db = current . s3db <EOL> table = s3db . table ( tablename ) <EOL> record = db ( table . channel_id == channel_id ) . select ( table . id , <EOL> table . enabled , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> ) . first ( ) <EOL> if record . enabled : <EOL> record . update_record ( enabled = False ) <EOL> s3db . update_super ( table , record ) <EOL> ptable = s3db . msg_parser <EOL> parsers = db ( ptable . channel_id == channel_id ) . select ( ptable . id ) <EOL> for parser in parsers : <EOL> s3db . msg_parser_disable ( parser . id ) <EOL> ttable = db . scheduler_task <EOL> args = '<STR_LIT>' % ( tablename , channel_id ) <EOL> query = ( ( ttable . function_name == "<STR_LIT>" ) & ( ttable . args == args ) & ( ttable . status . belongs ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) ) ) <EOL> exists = db ( query ) . select ( ttable . id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if exists : <EOL> db ( query ) . update ( status = "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> @ staticmethod <EOL> def channel_disable_interactive ( r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> tablename = r . tablename <EOL> result = current . s3db . msg_channel_disable ( tablename , r . record . channel_id ) <EOL> current . session . confirmation = result <EOL> fn = tablename . split ( "<STR_LIT:_>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> redirect ( URL ( f = fn ) ) <EOL> @ staticmethod <EOL> def channel_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> if form . record : <EOL> if form . record . enabled and not form . vars . enabled : <EOL> current . s3db . msg_channel_disable ( form . table . _tablename , <EOL> form . vars . channel_id ) <EOL> elif form . vars . enabled and not form . record . enabled : <EOL> current . s3db . msg_channel_enable ( form . table . _tablename , <EOL> form . vars . channel_id ) <EOL> else : <EOL> if form . vars . enabled : <EOL> current . s3db . msg_channel_enable ( form . table . _tablename , <EOL> form . vars . channel_id ) <EOL> @ staticmethod <EOL> def channel_poll ( r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> tablename = r . tablename <EOL> current . s3task . async ( "<STR_LIT>" , args = [ tablename , r . record . channel_id ] ) <EOL> current . session . confirmation = current . T ( "<STR_LIT>" ) <EOL> if tablename == "<STR_LIT>" : <EOL> fn = "<STR_LIT>" <EOL> elif tablename == "<STR_LIT>" : <EOL> fn = "<STR_LIT>" <EOL> elif tablename == "<STR_LIT>" : <EOL> fn = "<STR_LIT>" <EOL> elif tablename == "<STR_LIT>" : <EOL> fn = "<STR_LIT>" <EOL> elif tablename == "<STR_LIT>" : <EOL> fn = "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" % tablename <EOL> redirect ( URL ( f = fn ) ) <EOL> class S3MessageModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> db = current . db <EOL> UNKNOWN_OPT = current . messages . UNKNOWN_OPT <EOL> configure = self . configure <EOL> define_table = self . define_table <EOL> msg_priority_opts = { <NUM_LIT:3> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:2> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:1> : T ( "<STR_LIT>" ) , <EOL> } <EOL> message_types = Storage ( msg_email = T ( "<STR_LIT>" ) , <EOL> msg_facebook = T ( "<STR_LIT>" ) , <EOL> msg_rss = T ( "<STR_LIT>" ) , <EOL> msg_sms = T ( "<STR_LIT>" ) , <EOL> msg_twitter = T ( "<STR_LIT>" ) , <EOL> msg_twitter_result = T ( "<STR_LIT>" ) , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> self . super_entity ( tablename , "<STR_LIT>" , <EOL> message_types , <EOL> self . msg_channel_id ( ) , <EOL> s3_datetime ( default = "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:body>" , "<STR_LIT:text>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda direction : ( direction and [ T ( "<STR_LIT>" ) ] or [ T ( "<STR_LIT>" ) ] ) [ <NUM_LIT:0> ] , <EOL> ) , <EOL> ) <EOL> table = db [ tablename ] <EOL> table . instance_type . readable = True <EOL> table . instance_type . writable = True <EOL> configure ( tablename , <EOL> list_fields = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:body>" , <EOL> "<STR_LIT>" , <EOL> ] , <EOL> ) <EOL> message_represent = S3Represent ( lookup = tablename , fields = [ "<STR_LIT:body>" ] ) <EOL> message_id = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" % tablename , <EOL> ondelete = "<STR_LIT>" , <EOL> represent = message_represent , <EOL> requires = IS_EMPTY_OR ( <EOL> IS_ONE_OF_EMPTY ( db , "<STR_LIT>" ) ) , <EOL> ) <EOL> self . add_components ( tablename , <EOL> msg_attachment = "<STR_LIT>" , <EOL> deploy_response = "<STR_LIT>" , <EOL> ) <EOL> MSG_CONTACT_OPTS = current . msg . MSG_CONTACT_OPTS <EOL> MAX_SEND_RETRIES = current . deployment_settings . get_msg_max_send_retries ( ) <EOL> MSG_STATUS_OPTS = { <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> <NUM_LIT:5> : T ( "<STR_LIT>" ) , <EOL> } <EOL> opt_msg_status = S3ReusableField ( "<STR_LIT:status>" , "<STR_LIT>" , <EOL> notnull = True , <EOL> requires = IS_IN_SET ( MSG_STATUS_OPTS , <EOL> zero = None ) , <EOL> default = <NUM_LIT:1> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda opt : MSG_STATUS_OPTS . get ( opt , <EOL> UNKNOWN_OPT ) ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> message_id ( ) , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:address>" ) , <EOL> Field ( "<STR_LIT>" , length = <NUM_LIT:32> , <EOL> default = "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda opt : MSG_CONTACT_OPTS . get ( opt , UNKNOWN_OPT ) , <EOL> requires = IS_IN_SET ( MSG_CONTACT_OPTS , <EOL> zero = None ) , <EOL> ) , <EOL> opt_msg_status ( ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = MAX_SEND_RETRIES , <EOL> readable = False , <EOL> writable = False , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> list_fields = [ "<STR_LIT:id>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:status>" , <EOL> ] , <EOL> orderby = "<STR_LIT>" , <EOL> ) <EOL> return dict ( msg_message_id = message_id , <EOL> msg_message_represent = message_represent , <EOL> ) <EOL> @ staticmethod <EOL> def defaults ( ) : <EOL> """<STR_LIT>""" <EOL> dummy = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" , <EOL> readable = False , <EOL> writable = False ) <EOL> return dict ( msg_message_id = lambda ** attr : dummy ( "<STR_LIT>" ) , <EOL> ) <EOL> class S3MessageAttachmentModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , ) <EOL> def model ( self ) : <EOL> tablename = "<STR_LIT>" <EOL> self . define_table ( tablename , <EOL> self . msg_message_id ( ondelete = "<STR_LIT>" ) , <EOL> self . doc_document_id ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> return { } <EOL> class S3EmailModel ( S3ChannelModel ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> configure = self . configure <EOL> define_table = self . define_table <EOL> set_method = self . set_method <EOL> super_link = self . super_link <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" ) , <EOL> Field ( "<STR_LIT:description>" ) , <EOL> self . org_organisation_id ( ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , <EOL> requires = IS_IN_SET ( [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> zero = None ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:port>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:username>" ) , <EOL> Field ( "<STR_LIT:password>" , "<STR_LIT:password>" , length = <NUM_LIT:64> , <EOL> readable = False , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> onaccept = self . msg_channel_onaccept , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_enable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_disable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_poll ) <EOL> sender = current . deployment_settings . get_mail_sender ( ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> self . msg_channel_id ( ) , <EOL> s3_datetime ( default = "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , length = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_EMPTY_OR ( IS_LENGTH ( <NUM_LIT> ) ) , <EOL> ) , <EOL> Field ( "<STR_LIT:body>" , "<STR_LIT:text>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> default = sender , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_EMAIL ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_EMAIL ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:text>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> readable = False , <EOL> writable = False , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda direction : ( direction and [ T ( "<STR_LIT>" ) ] or [ T ( "<STR_LIT>" ) ] ) [ <NUM_LIT:0> ] , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> orderby = "<STR_LIT>" , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> self . add_components ( tablename , <EOL> deploy_mission = { "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:key>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> } , <EOL> ) <EOL> return { } <EOL> class S3FacebookModel ( S3ChannelModel ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> configure = self . configure <EOL> define_table = self . define_table <EOL> set_method = self . set_method <EOL> super_link = self . super_link <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" ) , <EOL> Field ( "<STR_LIT:description>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> requires = IS_INT_IN_RANGE ( <NUM_LIT:0> , + <NUM_LIT> ) <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:password>" , length = <NUM_LIT:64> , <EOL> readable = False , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> requires = IS_INT_IN_RANGE ( <NUM_LIT:0> , + <NUM_LIT> ) <EOL> ) , <EOL> Field ( "<STR_LIT>" ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> onaccept = self . msg_facebook_channel_onaccept , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_enable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_disable_interactive ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> self . msg_channel_id ( ) , <EOL> s3_datetime ( default = "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:body>" , "<STR_LIT:text>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda direction : ( direction and [ T ( "<STR_LIT>" ) ] or [ T ( "<STR_LIT>" ) ] ) [ <NUM_LIT:0> ] , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> orderby = "<STR_LIT>" , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> return dict ( msg_facebook_login = self . msg_facebook_login , <EOL> ) <EOL> @ staticmethod <EOL> def defaults ( ) : <EOL> """<STR_LIT>""" <EOL> return dict ( msg_facebook_login = lambda : False , <EOL> ) <EOL> @ staticmethod <EOL> def msg_facebook_channel_onaccept ( form ) : <EOL> if form . vars . login : <EOL> current . db ( current . s3db . msg_facebook_channel . id != form . vars . id ) . update ( login = False ) <EOL> S3ChannelModel . channel_onaccept ( form ) <EOL> @ staticmethod <EOL> def msg_facebook_login ( ) : <EOL> table = current . s3db . msg_facebook_channel <EOL> query = ( table . login == True ) & ( table . deleted == False ) <EOL> c = current . db ( query ) . select ( table . app_id , <EOL> table . app_secret , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ) . first ( ) <EOL> return c <EOL> class S3MCommonsModel ( S3ChannelModel ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , ) <EOL> def model ( self ) : <EOL> define_table = self . define_table <EOL> set_method = self . set_method <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" ) , <EOL> Field ( "<STR_LIT:description>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" , length = <NUM_LIT> , unique = True , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT:url>" , <EOL> default = "<STR_LIT>" , <EOL> requires = IS_URL ( ) <EOL> ) , <EOL> Field ( "<STR_LIT:username>" , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT:password>" , "<STR_LIT:password>" , <EOL> readable = False , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> writable = False , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> self . configure ( tablename , <EOL> onaccept = self . msg_channel_onaccept , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_enable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_disable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_poll ) <EOL> return { } <EOL> class S3ParsingModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> define_table = self . define_table <EOL> set_method = self . set_method <EOL> channel_id = self . msg_channel_id <EOL> message_id = self . msg_message_id <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> channel_id ( ondelete = "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> self . configure ( tablename , <EOL> onaccept = self . msg_parser_onaccept , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . parser_enable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . parser_disable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . parser_parse ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> message_id ( ondelete = "<STR_LIT>" ) , <EOL> channel_id ( ondelete = "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda parsed : ( parsed and [ T ( "<STR_LIT>" ) ] or [ T ( "<STR_LIT>" ) ] ) [ <NUM_LIT:0> ] , <EOL> ) , <EOL> message_id ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ondelete = "<STR_LIT>" , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:email>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = current . request . utcnow , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> self . event_incident_type_id ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> return dict ( msg_parser_enabled = self . parser_enabled , <EOL> msg_parser_enable = self . parser_enable , <EOL> msg_parser_disable = self . parser_disable , <EOL> ) <EOL> @ staticmethod <EOL> def parser_parse ( r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> record = r . record <EOL> current . s3task . async ( "<STR_LIT>" , args = [ record . channel_id , record . function_name ] ) <EOL> current . session . confirmation = current . T ( "<STR_LIT>" ) <EOL> redirect ( URL ( f = "<STR_LIT>" ) ) <EOL> @ staticmethod <EOL> def parser_enabled ( channel_id ) : <EOL> """<STR_LIT>""" <EOL> table = current . s3db . msg_parser <EOL> record = current . db ( table . channel_id == channel_id ) . select ( table . enabled , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> ) . first ( ) <EOL> if record and record . enabled : <EOL> return True <EOL> else : <EOL> return False <EOL> @ staticmethod <EOL> def parser_enable ( id ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> s3db = current . s3db <EOL> table = s3db . msg_parser <EOL> record = db ( table . id == id ) . select ( table . id , <EOL> table . enabled , <EOL> table . channel_id , <EOL> table . function_name , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> ) . first ( ) <EOL> if not record . enabled : <EOL> record . update_record ( enabled = True ) <EOL> channel_id = record . channel_id <EOL> function_name = record . function_name <EOL> ttable = db . scheduler_task <EOL> args = '<STR_LIT>' % ( channel_id , function_name ) <EOL> query = ( ( ttable . function_name == "<STR_LIT>" ) & ( ttable . args == args ) & ( ttable . status . belongs ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) ) ) <EOL> exists = db ( query ) . select ( ttable . id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if exists : <EOL> return "<STR_LIT>" <EOL> else : <EOL> current . s3task . schedule_task ( "<STR_LIT>" , <EOL> args = [ channel_id , function_name ] , <EOL> period = <NUM_LIT> , <EOL> timeout = <NUM_LIT> , <EOL> repeats = <NUM_LIT:0> <EOL> ) <EOL> return "<STR_LIT>" <EOL> @ staticmethod <EOL> def parser_enable_interactive ( r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> result = current . s3db . msg_parser_enable ( r . id ) <EOL> current . session . confirmation = result <EOL> redirect ( URL ( f = "<STR_LIT>" ) ) <EOL> @ staticmethod <EOL> def parser_disable ( id ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> s3db = current . s3db <EOL> table = s3db . msg_parser <EOL> record = db ( table . id == id ) . select ( table . id , <EOL> table . enabled , <EOL> table . channel_id , <EOL> table . function_name , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> ) . first ( ) <EOL> if record . enabled : <EOL> record . update_record ( enabled = False ) <EOL> ttable = db . scheduler_task <EOL> args = '<STR_LIT>' % ( record . channel_id , record . function_name ) <EOL> query = ( ( ttable . function_name == "<STR_LIT>" ) & ( ttable . args == args ) & ( ttable . status . belongs ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) ) ) <EOL> exists = db ( query ) . select ( ttable . id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if exists : <EOL> db ( query ) . update ( status = "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> @ staticmethod <EOL> def parser_disable_interactive ( r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> result = current . s3db . msg_parser_disable ( r . id ) <EOL> current . session . confirmation = result <EOL> redirect ( URL ( f = "<STR_LIT>" ) ) <EOL> @ staticmethod <EOL> def msg_parser_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> if form . record : <EOL> if form . record . enabled and not form . vars . enabled : <EOL> current . s3db . msg_parser_disable ( form . vars . id ) <EOL> elif form . vars . enabled and not form . record . enabled : <EOL> current . s3db . msg_parser_enable ( form . vars . id ) <EOL> else : <EOL> if form . vars . enabled : <EOL> current . s3db . msg_parser_enable ( form . vars . id ) <EOL> class S3RSSModel ( S3ChannelModel ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> define_table = self . define_table <EOL> set_method = self . set_method <EOL> super_link = self . super_link <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" , length = <NUM_LIT:255> , unique = True , <EOL> label = T ( "<STR_LIT:Name>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:description>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> Field ( "<STR_LIT:url>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_URL ( ) , <EOL> ) , <EOL> s3_datetime ( label = T ( "<STR_LIT>" ) , <EOL> writable = False , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> writable = False <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> self . configure ( tablename , <EOL> list_fields = [ "<STR_LIT:name>" , <EOL> "<STR_LIT:description>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:url>" , <EOL> "<STR_LIT:date>" , <EOL> "<STR_LIT>" , <EOL> ] , <EOL> onaccept = self . msg_channel_onaccept , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_enable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_disable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_poll ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> self . msg_channel_id ( ) , <EOL> s3_datetime ( default = "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:title>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:body>" , "<STR_LIT:text>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> self . gis_location_id ( ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> readable = False , <EOL> writable = False , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> self . configure ( tablename , <EOL> deduplicate = S3Duplicate ( primary = ( "<STR_LIT>" , ) , <EOL> ignore_case = False , <EOL> ) , <EOL> list_fields = [ "<STR_LIT>" , <EOL> "<STR_LIT:title>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:date>" , <EOL> "<STR_LIT:body>" <EOL> ] , <EOL> super_entity = current . s3db . msg_message , <EOL> ) <EOL> return { } <EOL> class S3SMSModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , ) <EOL> def model ( self ) : <EOL> user = current . auth . user <EOL> if user and user . organisation_id : <EOL> default = user . organisation_id <EOL> else : <EOL> default = None <EOL> tablename = "<STR_LIT>" <EOL> self . define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> self . msg_channel_id ( ) , <EOL> self . org_organisation_id ( default = default ) , <EOL> s3_datetime ( default = "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:body>" , "<STR_LIT:text>" , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> self . configure ( tablename , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> return { } <EOL> class S3SMSOutboundModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> configure = self . configure <EOL> define_table = self . define_table <EOL> settings = current . deployment_settings <EOL> country_code = settings . get_L10n_default_country_code ( ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . msg_channel_id ( <EOL> requires = IS_ONE_OF ( current . db , "<STR_LIT>" , <EOL> S3Represent ( lookup = "<STR_LIT>" ) , <EOL> instance_types = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) , <EOL> sort = True , <EOL> ) , <EOL> ) , <EOL> self . org_organisation_id ( ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = country_code , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" ) , <EOL> Field ( "<STR_LIT:description>" ) , <EOL> Field ( "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> ) , <EOL> Field ( "<STR_LIT:max_length>" , "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" ) , <EOL> Field ( "<STR_LIT:description>" ) , <EOL> Field ( "<STR_LIT:address>" , length = <NUM_LIT:64> , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , length = <NUM_LIT:64> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> ) , <EOL> Field ( "<STR_LIT:max_length>" , "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" ) , <EOL> Field ( "<STR_LIT:description>" ) , <EOL> Field ( "<STR_LIT:url>" , <EOL> default = "<STR_LIT>" , <EOL> requires = IS_URL ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> default = "<STR_LIT>" , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:string>" , <EOL> default = "<STR_LIT:text>" , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:string>" , <EOL> default = "<STR_LIT:to>" , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT:max_length>" , "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> ) , <EOL> Field ( "<STR_LIT:username>" ) , <EOL> Field ( "<STR_LIT:password>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> return { } <EOL> class S3TropoModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> define_table = self . define_table <EOL> set_method = self . set_method <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" ) , <EOL> Field ( "<STR_LIT:description>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" ) , <EOL> * s3_meta_fields ( ) ) <EOL> self . configure ( tablename , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_enable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_disable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_poll ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:message>" ) , <EOL> Field ( "<STR_LIT>" ) , <EOL> ) <EOL> return { } <EOL> class S3TwilioModel ( S3ChannelModel ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> define_table = self . define_table <EOL> set_method = self . set_method <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" ) , <EOL> Field ( "<STR_LIT:description>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" , length = <NUM_LIT:255> , unique = True ) , <EOL> Field ( "<STR_LIT:url>" , <EOL> default = "<STR_LIT>" <EOL> ) , <EOL> Field ( "<STR_LIT>" , length = <NUM_LIT:64> , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:password>" , length = <NUM_LIT:64> , <EOL> readable = False , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> self . configure ( tablename , <EOL> onaccept = self . msg_channel_onaccept , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_enable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_disable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_poll ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . msg_message_id ( ondelete = "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" ) , <EOL> * s3_meta_fields ( ) ) <EOL> return { } <EOL> class S3TwitterModel ( S3Model ) : <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> db = current . db <EOL> configure = self . configure <EOL> define_table = self . define_table <EOL> set_method = self . set_method <EOL> password_widget = S3PasswordWidget ( ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" , <EOL> label = T ( "<STR_LIT:Name>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:description>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:password>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> widget = password_widget , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:password>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> widget = password_widget , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:password>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> widget = password_widget , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:password>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> widget = password_widget , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> onaccept = self . twitter_channel_onaccept , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_enable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_disable_interactive ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . msg_channel_poll ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> self . msg_channel_id ( ) , <EOL> s3_datetime ( default = "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:body>" , length = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = self . twitter_represent , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = self . twitter_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda direction : ( direction and [ T ( "<STR_LIT>" ) ] or [ T ( "<STR_LIT>" ) ] ) [ <NUM_LIT:0> ] , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> readable = False , <EOL> writable = False , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> list_fields = [ "<STR_LIT:id>" , <EOL> "<STR_LIT:body>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:date>" , <EOL> ] , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> return { } <EOL> @ staticmethod <EOL> def twitter_represent ( nickname , show_link = True ) : <EOL> """<STR_LIT>""" <EOL> if not nickname : <EOL> return current . messages [ "<STR_LIT>" ] <EOL> db = current . db <EOL> s3db = current . s3db <EOL> table = s3db . pr_contact <EOL> query = ( table . contact_method == "<STR_LIT>" ) & ( table . value == nickname ) <EOL> row = db ( query ) . select ( table . pe_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if row : <EOL> repr = s3db . pr_pentity_represent ( row . pe_id ) <EOL> if show_link : <EOL> ptable = s3db . pr_person <EOL> row = db ( ptable . pe_id == row . pe_id ) . select ( ptable . id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if row : <EOL> link = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , args = [ row . id ] ) <EOL> return A ( repr , _href = link ) <EOL> return repr <EOL> else : <EOL> return nickname <EOL> @ staticmethod <EOL> def twitter_channel_onaccept ( form ) : <EOL> if form . vars . login : <EOL> current . db ( current . s3db . msg_twitter_channel . id != form . vars . id ) . update ( login = False ) <EOL> S3ChannelModel . channel_onaccept ( form ) <EOL> @ staticmethod <EOL> def twitter_channel_onvalidation ( form ) : <EOL> """<STR_LIT>""" <EOL> T = current . T <EOL> session = current . session <EOL> settings = current . deployment_settings . msg <EOL> s3 = session . s3 <EOL> form_vars = form . vars <EOL> if form_vars . pin and s3 . twitter_request_key and s3 . twitter_request_secret : <EOL> try : <EOL> import tweepy <EOL> except : <EOL> raise HTTP ( <NUM_LIT> , body = T ( "<STR_LIT>" ) ) <EOL> oauth = tweepy . OAuthHandler ( settings . twitter_oauth_consumer_key , <EOL> settings . twitter_oauth_consumer_secret ) <EOL> oauth . set_request_token ( s3 . twitter_request_key , <EOL> s3 . twitter_request_secret ) <EOL> try : <EOL> oauth . get_access_token ( form_vars . pin ) <EOL> form_vars . oauth_key = oauth . access_token . key <EOL> form_vars . oauth_secret = oauth . access_token . secret <EOL> twitter = tweepy . API ( oauth ) <EOL> form_vars . twitter_account = twitter . me ( ) . screen_name <EOL> form_vars . pin = "<STR_LIT>" <EOL> return <EOL> except tweepy . TweepError : <EOL> session . error = T ( "<STR_LIT>" ) <EOL> for k in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> form_vars [ k ] = None <EOL> for k in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> s3 [ k ] = "<STR_LIT>" <EOL> class S3TwitterSearchModel ( S3ChannelModel ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> db = current . db <EOL> configure = self . configure <EOL> define_table = self . define_table <EOL> set_method = self . set_method <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT>" , "<STR_LIT:text>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:count>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:100> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_yes_no_represent , <EOL> comment = DIV ( _class = "<STR_LIT>" , <EOL> _title = "<STR_LIT>" % ( T ( "<STR_LIT>" ) , <EOL> T ( "<STR_LIT>" ) ) ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = s3_yes_no_represent , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> list_fields = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:count>" , <EOL> ] , <EOL> ) <EOL> represent = S3Represent ( lookup = tablename , fields = [ "<STR_LIT>" ] ) <EOL> search_id = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" % tablename , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ondelete = "<STR_LIT>" , <EOL> represent = represent , <EOL> requires = IS_EMPTY_OR ( <EOL> IS_ONE_OF_EMPTY ( db , "<STR_LIT>" ) <EOL> ) , <EOL> ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . twitter_search_poll ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . twitter_keygraph ) <EOL> set_method ( "<STR_LIT>" , "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> action = self . twitter_timeline ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> search_id ( ) , <EOL> s3_datetime ( default = "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) ) , <EOL> Field ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) ) , <EOL> Field ( "<STR_LIT:body>" , <EOL> label = T ( "<STR_LIT>" ) ) , <EOL> self . gis_location_id ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> list_fields = [ <EOL> "<STR_LIT:body>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:date>" , <EOL> "<STR_LIT>" , <EOL> ] , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> return { } <EOL> @ staticmethod <EOL> def twitter_search_poll ( r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> id = r . id <EOL> tablename = r . tablename <EOL> current . s3task . async ( "<STR_LIT>" , args = [ id ] ) <EOL> current . session . confirmation = current . T ( "<STR_LIT>" ) <EOL> redirect ( URL ( f = "<STR_LIT>" , <EOL> vars = { "<STR_LIT>" : id } ) ) <EOL> @ staticmethod <EOL> def twitter_keygraph ( r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> tablename = r . tablename <EOL> current . s3task . async ( "<STR_LIT>" , args = [ r . id ] ) <EOL> current . session . confirmation = current . T ( "<STR_LIT>" ) <EOL> redirect ( URL ( f = "<STR_LIT>" ) ) <EOL> @ staticmethod <EOL> def twitter_timeline ( r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> if r . representation == "<STR_LIT:html>" and r . name == "<STR_LIT>" : <EOL> response = current . response <EOL> s3 = response . s3 <EOL> appname = r . application <EOL> s3 . scripts . append ( "<STR_LIT>" % appname ) <EOL> if s3 . debug : <EOL> s3 . scripts . append ( "<STR_LIT>" % appname ) <EOL> else : <EOL> s3 . scripts . append ( "<STR_LIT>" % appname ) <EOL> if r . record : <EOL> rows = [ r . record ] <EOL> else : <EOL> rows = r . resource . select ( [ "<STR_LIT:date>" , "<STR_LIT:body>" ] , limit = <NUM_LIT> , as_rows = True ) <EOL> data = { "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> now = r . utcnow <EOL> tl_start = tl_end = now <EOL> events = [ ] <EOL> import re <EOL> for row in rows : <EOL> start = row . date or "<STR_LIT>" <EOL> if start : <EOL> if start < tl_start : <EOL> tl_start = start <EOL> if start > tl_end : <EOL> tl_end = start <EOL> start = start . isoformat ( ) <EOL> title = ( re . sub ( r"<STR_LIT>" , "<STR_LIT>" , row . body ) ) <EOL> if len ( title ) > <NUM_LIT:30> : <EOL> title = title [ : <NUM_LIT:30> ] <EOL> events . append ( { "<STR_LIT:start>" : start , <EOL> "<STR_LIT:title>" : title , <EOL> "<STR_LIT:description>" : row . body , <EOL> } ) <EOL> data [ "<STR_LIT>" ] = events <EOL> data = json . dumps ( data , separators = SEPARATORS ) <EOL> code = "<STR_LIT>" . join ( ( <EOL> '''<STR_LIT>''' , data , '''<STR_LIT>''' , tl_start . isoformat ( ) , '''<STR_LIT>''' , tl_end . isoformat ( ) , '''<STR_LIT>''' , now . isoformat ( ) , '''<STR_LIT>''' ) ) <EOL> s3 . js_global . append ( code ) <EOL> item = DIV ( _id = "<STR_LIT>" , _class = "<STR_LIT>" ) <EOL> output = dict ( item = item ) <EOL> if attr . get ( "<STR_LIT>" ) : <EOL> rheader = attr [ "<STR_LIT>" ] ( r ) <EOL> if rheader : <EOL> output [ "<STR_LIT>" ] = rheader <EOL> output [ "<STR_LIT:title>" ] = current . T ( "<STR_LIT>" ) <EOL> response . view = "<STR_LIT>" <EOL> return output <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_METHOD ) <EOL> class S3XFormsModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , ) <EOL> def model ( self ) : <EOL> tablename = "<STR_LIT>" <EOL> self . define_table ( tablename , <EOL> Field ( "<STR_LIT>" , length = <NUM_LIT:20> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:message>" , length = <NUM_LIT> ) <EOL> ) <EOL> return { } <EOL> class S3BaseStationModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> if current . deployment_settings . get_msg_basestation_code_unique ( ) : <EOL> db = current . db <EOL> code_unique = IS_EMPTY_OR ( IS_NOT_IN_DB ( db , "<STR_LIT>" ) ) <EOL> else : <EOL> code_unique = None <EOL> tablename = "<STR_LIT>" <EOL> self . define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" , notnull = True , <EOL> length = <NUM_LIT:64> , <EOL> label = T ( "<STR_LIT:Name>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT:code>" , length = <NUM_LIT:10> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = code_unique , <EOL> ) , <EOL> self . org_organisation_id ( <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = self . org_organisation_requires ( required = True , <EOL> updateable = True ) , <EOL> ) , <EOL> self . gis_location_id ( ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> current . response . s3 . 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> title_upload = T ( "<STR_LIT>" ) , <EOL> title_map = T ( "<STR_LIT>" ) , <EOL> label_list_button = T ( "<STR_LIT>" ) , <EOL> label_delete_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> self . configure ( tablename , <EOL> deduplicate = S3Duplicate ( ) , <EOL> super_entity = "<STR_LIT>" , <EOL> ) <EOL> return { } </s>
