<s> """<STR_LIT>""" <EOL> from gluon import current <EOL> from gluon . html import * <EOL> from gluon . http import redirect <EOL> from gluon . storage import Storage <EOL> from s3crud import S3CRUD <EOL> from s3report import S3Report <EOL> from s3query import FS <EOL> from s3widgets import ICON <EOL> class S3Profile ( S3CRUD ) : <EOL> """<STR_LIT>""" <EOL> def apply_method ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> if r . http in ( "<STR_LIT:GET>" , "<STR_LIT:POST>" , "<STR_LIT>" ) : <EOL> if r . record : <EOL> self . settings = current . response . s3 . crud <EOL> self . sqlform = sqlform = self . _config ( "<STR_LIT>" ) <EOL> if not sqlform : <EOL> from s3forms import S3SQLDefaultForm <EOL> self . sqlform = S3SQLDefaultForm ( ) <EOL> output = self . profile ( r , ** attr ) <EOL> elif r . representation not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> redirect ( r . url ( method = "<STR_LIT>" ) ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_RECORD ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_METHOD ) <EOL> return output <EOL> def profile ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> tablename = self . tablename <EOL> get_config = current . s3db . get_config <EOL> widgets = get_config ( tablename , "<STR_LIT>" ) <EOL> if not widgets : <EOL> if r . representation not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> redirect ( r . url ( method = "<STR_LIT>" ) ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_METHOD ) <EOL> for index , widget in enumerate ( widgets ) : <EOL> widget [ "<STR_LIT:index>" ] = index <EOL> if r . representation == "<STR_LIT>" : <EOL> index = r . get_vars . get ( "<STR_LIT>" , None ) <EOL> if index : <EOL> try : <EOL> index = int ( index ) <EOL> except ValueError : <EOL> datalist = "<STR_LIT>" <EOL> else : <EOL> datalist = self . _datalist ( r , widgets [ index ] , ** attr ) <EOL> output = { "<STR_LIT>" : datalist } <EOL> elif r . representation == "<STR_LIT>" : <EOL> index = r . get_vars . get ( "<STR_LIT>" , None ) <EOL> if index : <EOL> try : <EOL> index = int ( index ) <EOL> except ValueError : <EOL> datalist = "<STR_LIT>" <EOL> else : <EOL> datatable = self . _datatable ( r , widgets [ index ] , ** attr ) <EOL> return datatable <EOL> else : <EOL> title = get_config ( tablename , "<STR_LIT>" ) <EOL> if not title : <EOL> try : <EOL> title = r . record . name <EOL> except : <EOL> title = current . T ( "<STR_LIT>" ) <EOL> elif callable ( title ) : <EOL> title = title ( r ) <EOL> header = get_config ( tablename , "<STR_LIT>" ) <EOL> if not header : <EOL> header = H2 ( title , _class = "<STR_LIT>" ) <EOL> elif callable ( header ) : <EOL> header = header ( r ) <EOL> output = dict ( title = title , header = header ) <EOL> update = get_config ( tablename , "<STR_LIT>" ) <EOL> if update : <EOL> editable = get_config ( tablename , "<STR_LIT>" , True ) <EOL> authorised = self . _permitted ( method = "<STR_LIT>" ) <EOL> if authorised and editable : <EOL> show = self . crud_string ( tablename , "<STR_LIT>" ) <EOL> hide = current . T ( "<STR_LIT>" ) <EOL> form = self . update ( r , ** attr ) [ "<STR_LIT>" ] <EOL> else : <EOL> show = self . crud_string ( tablename , "<STR_LIT>" ) <EOL> hide = current . T ( "<STR_LIT>" ) <EOL> form = self . read ( r , ** attr ) [ "<STR_LIT>" ] <EOL> if update == "<STR_LIT>" : <EOL> hidden = False <EOL> label = hide <EOL> style_hide , style_show = None , "<STR_LIT>" <EOL> else : <EOL> hidden = True <EOL> label = show <EOL> style_hide , style_show = "<STR_LIT>" , None <EOL> toggle = A ( SPAN ( label , <EOL> data = { "<STR_LIT>" : show , <EOL> "<STR_LIT>" : hide , <EOL> } , <EOL> ) , <EOL> ICON ( "<STR_LIT>" , _style = style_show ) , <EOL> ICON ( "<STR_LIT>" , _style = style_hide ) , <EOL> data = { "<STR_LIT>" : hidden } , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> form . update ( _style = style_hide ) <EOL> output [ "<STR_LIT>" ] = DIV ( toggle , <EOL> form , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> else : <EOL> output [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> response = current . response <EOL> rows = [ ] <EOL> append = rows . append <EOL> row = None <EOL> cols = get_config ( tablename , "<STR_LIT>" ) <EOL> if not cols : <EOL> cols = <NUM_LIT:2> <EOL> row_cols = <NUM_LIT:0> <EOL> for widget in widgets : <EOL> w_type = widget [ "<STR_LIT:type>" ] <EOL> if w_type == "<STR_LIT>" : <EOL> w = self . _comments ( r , widget , ** attr ) <EOL> elif w_type == "<STR_LIT>" : <EOL> w = self . _datalist ( r , widget , ** attr ) <EOL> elif w_type == "<STR_LIT>" : <EOL> w = self . _datatable ( r , widget , ** attr ) <EOL> elif w_type == "<STR_LIT>" : <EOL> w = self . _form ( r , widget , ** attr ) <EOL> elif w_type == "<STR_LIT>" : <EOL> w = self . _map ( r , widget , widgets , ** attr ) <EOL> elif w_type == "<STR_LIT>" : <EOL> w = self . _report ( r , widget , ** attr ) <EOL> elif w_type == "<STR_LIT>" : <EOL> w = self . _custom ( r , widget , ** attr ) <EOL> else : <EOL> if response . s3 . debug : <EOL> raise SyntaxError ( "<STR_LIT>" % <EOL> w_type ) <EOL> else : <EOL> continue <EOL> if row is None : <EOL> row = DIV ( _class = "<STR_LIT>" ) <EOL> row_cols = <NUM_LIT:0> <EOL> row . append ( w ) <EOL> colspan = widget . get ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> row_cols += colspan <EOL> if row_cols == cols : <EOL> append ( row ) <EOL> row = None <EOL> if row : <EOL> append ( row ) <EOL> output [ "<STR_LIT>" ] = rows <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> return output <EOL> @ staticmethod <EOL> def _resolve_context ( r , tablename , context ) : <EOL> """<STR_LIT>""" <EOL> record_id = r . id <EOL> if not record_id : <EOL> return None <EOL> if not context : <EOL> query = None <EOL> elif type ( context ) is tuple : <EOL> context , field = context <EOL> query = ( FS ( context ) == r . record [ field ] ) <EOL> elif context == "<STR_LIT:location>" : <EOL> s = "<STR_LIT>" <EOL> m = ( "<STR_LIT>" % dict ( id = record_id ) ) . split ( "<STR_LIT:U+002C>" ) <EOL> m = [ f . replace ( "<STR_LIT:*>" , "<STR_LIT:%>" ) for f in m ] <EOL> query = ( FS ( s ) . like ( m ) ) <EOL> else : <EOL> s = "<STR_LIT>" % context <EOL> query = ( FS ( s ) == record_id ) <EOL> resource = current . s3db . resource ( tablename , filter = query ) <EOL> r . customise_resource ( tablename ) <EOL> return resource , query <EOL> def _comments ( self , r , widget , ** attr ) : <EOL> """<STR_LIT>""" <EOL> label = widget . get ( "<STR_LIT:label>" , "<STR_LIT>" ) <EOL> if label : <EOL> label = current . T ( label ) <EOL> icon = widget . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if icon : <EOL> icon = ICON ( icon ) <EOL> _class = self . _lookup_class ( r , widget ) <EOL> comments = "<STR_LIT>" <EOL> output = DIV ( H4 ( icon , <EOL> label , <EOL> _class = "<STR_LIT>" ) , <EOL> DIV ( comments , <EOL> _class = "<STR_LIT>" ) , <EOL> _class = _class ) <EOL> return output <EOL> def _custom ( self , r , widget , ** attr ) : <EOL> """<STR_LIT>""" <EOL> label = widget . get ( "<STR_LIT:label>" , "<STR_LIT>" ) <EOL> if label : <EOL> label = current . T ( label ) <EOL> icon = widget . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if icon : <EOL> icon = ICON ( icon ) <EOL> _class = self . _lookup_class ( r , widget ) <EOL> contents = widget [ "<STR_LIT>" ] ( r , ** attr ) <EOL> output = DIV ( H4 ( icon , <EOL> label , <EOL> _class = "<STR_LIT>" ) , <EOL> DIV ( contents , <EOL> _class = "<STR_LIT>" ) , <EOL> _class = _class ) <EOL> return output <EOL> def _datalist ( self , r , widget , ** attr ) : <EOL> """<STR_LIT>""" <EOL> T = current . T <EOL> context = widget . get ( "<STR_LIT>" ) <EOL> tablename = widget . get ( "<STR_LIT>" ) <EOL> resource , context = self . _resolve_context ( r , tablename , context ) <EOL> config = resource . get_config <EOL> list_fields = widget . get ( "<STR_LIT>" , <EOL> config ( "<STR_LIT>" , None ) ) <EOL> list_layout = widget . get ( "<STR_LIT>" , <EOL> config ( "<STR_LIT>" , None ) ) <EOL> orderby = widget . get ( "<STR_LIT>" , <EOL> config ( "<STR_LIT>" , <EOL> config ( "<STR_LIT>" , <EOL> ~ resource . table . created_on ) ) ) <EOL> widget_filter = widget . get ( "<STR_LIT>" ) <EOL> if widget_filter : <EOL> resource . add_filter ( widget_filter ) <EOL> list_id = "<STR_LIT>" % ( tablename , widget [ "<STR_LIT:index>" ] ) <EOL> pagesize = widget . get ( "<STR_LIT>" , <NUM_LIT:4> ) <EOL> representation = r . representation <EOL> if representation == "<STR_LIT>" : <EOL> get_vars = r . get_vars <EOL> record_id = get_vars . get ( "<STR_LIT>" , None ) <EOL> if record_id is not None : <EOL> resource . add_filter ( FS ( "<STR_LIT:id>" ) == record_id ) <EOL> start , limit = <NUM_LIT:0> , <NUM_LIT:1> <EOL> else : <EOL> start = get_vars . get ( "<STR_LIT:start>" , None ) <EOL> limit = get_vars . get ( "<STR_LIT>" , None ) <EOL> if limit is not None : <EOL> try : <EOL> start = int ( start ) <EOL> limit = int ( limit ) <EOL> except ValueError : <EOL> start , limit = <NUM_LIT:0> , pagesize <EOL> else : <EOL> start = None <EOL> else : <EOL> start , limit = <NUM_LIT:0> , pagesize <EOL> if representation == "<STR_LIT>" and r . http in ( "<STR_LIT>" , "<STR_LIT:POST>" ) : <EOL> if "<STR_LIT>" in r . get_vars : <EOL> return self . _dl_ajax_delete ( r , resource ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_METHOD ) <EOL> datalist , numrows , ids = resource . datalist ( fields = list_fields , <EOL> start = start , <EOL> limit = limit , <EOL> list_id = list_id , <EOL> orderby = orderby , <EOL> layout = list_layout ) <EOL> ajaxurl = r . url ( vars = { "<STR_LIT>" : widget [ "<STR_LIT:index>" ] } , <EOL> representation = "<STR_LIT>" ) <EOL> data = datalist . html ( ajaxurl = ajaxurl , <EOL> pagesize = pagesize , <EOL> empty = P ( ICON ( "<STR_LIT>" ) , <EOL> BR ( ) , <EOL> S3CRUD . crud_string ( tablename , <EOL> "<STR_LIT>" ) , <EOL> _class = "<STR_LIT>" <EOL> ) , <EOL> ) <EOL> if representation == "<STR_LIT>" : <EOL> current . response . view = "<STR_LIT>" <EOL> return data <EOL> label = widget . get ( "<STR_LIT:label>" , "<STR_LIT>" ) <EOL> if label : <EOL> label = T ( label ) <EOL> icon = widget . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if icon : <EOL> icon = ICON ( icon ) <EOL> if pagesize and numrows > pagesize : <EOL> more = numrows - pagesize <EOL> get_vars_new = { } <EOL> if context : <EOL> filters = context . serialize_url ( resource ) <EOL> for f in filters : <EOL> get_vars_new [ f ] = filters [ f ] <EOL> if widget_filter : <EOL> filters = widget_filter . serialize_url ( resource ) <EOL> for f in filters : <EOL> get_vars_new [ f ] = filters [ f ] <EOL> c , f = tablename . split ( "<STR_LIT:_>" , <NUM_LIT:1> ) <EOL> f = widget . get ( "<STR_LIT>" , f ) <EOL> url = URL ( c = c , f = f , args = [ "<STR_LIT>" ] , <EOL> vars = get_vars_new ) <EOL> more = DIV ( A ( BUTTON ( "<STR_LIT>" % ( T ( "<STR_LIT>" ) , more ) , <EOL> _class = "<STR_LIT>" , <EOL> _type = "<STR_LIT>" , <EOL> ) , <EOL> _class = "<STR_LIT>" , <EOL> _href = url , <EOL> _title = label , <EOL> ) , <EOL> _class = "<STR_LIT>" ) <EOL> else : <EOL> more = "<STR_LIT>" <EOL> create_popup = self . _create_popup ( r , <EOL> widget , <EOL> list_id , <EOL> resource , <EOL> context , <EOL> numrows ) <EOL> _class = self . _lookup_class ( r , widget ) <EOL> output = DIV ( create_popup , <EOL> H4 ( icon , <EOL> label , <EOL> _class = "<STR_LIT>" ) , <EOL> DIV ( data , <EOL> more , <EOL> _class = "<STR_LIT>" ) , <EOL> _class = _class ) <EOL> return output <EOL> def _datatable ( self , r , widget , ** attr ) : <EOL> """<STR_LIT>""" <EOL> context = widget . get ( "<STR_LIT>" ) <EOL> tablename = widget . get ( "<STR_LIT>" ) <EOL> resource , context = self . _resolve_context ( r , tablename , context ) <EOL> list_fields = widget . get ( "<STR_LIT>" ) <EOL> if not list_fields : <EOL> list_fields = resource . list_fields ( ) <EOL> widget_filter = widget . get ( "<STR_LIT>" ) <EOL> if widget_filter : <EOL> resource . add_filter ( widget_filter ) <EOL> list_id = "<STR_LIT>" % ( tablename , widget [ "<STR_LIT:index>" ] ) <EOL> def default_orderby ( ) : <EOL> for f in list_fields : <EOL> selector = f [ <NUM_LIT:1> ] if isinstance ( f , tuple ) else f <EOL> if selector == "<STR_LIT:id>" : <EOL> continue <EOL> rfield = resource . resolve_selector ( selector ) <EOL> if rfield . field : <EOL> return rfield . field <EOL> return None <EOL> representation = r . representation <EOL> get_vars = self . request . get_vars <EOL> if representation == "<STR_LIT>" : <EOL> start = get_vars . get ( "<STR_LIT>" , None ) <EOL> limit = get_vars . get ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> else : <EOL> start = get_vars . get ( "<STR_LIT:start>" , None ) <EOL> limit = get_vars . get ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> if limit : <EOL> if limit . lower ( ) == "<STR_LIT:none>" : <EOL> limit = None <EOL> else : <EOL> try : <EOL> start = int ( start ) <EOL> limit = int ( limit ) <EOL> except ( ValueError , TypeError ) : <EOL> start = None <EOL> limit = <NUM_LIT:0> <EOL> else : <EOL> start = None <EOL> dtargs = attr . get ( "<STR_LIT>" , { } ) <EOL> if r . interactive : <EOL> s3 = current . response . s3 <EOL> if s3 . dataTable_pageLength : <EOL> display_length = s3 . dataTable_pageLength <EOL> else : <EOL> display_length = widget . get ( "<STR_LIT>" , <NUM_LIT:10> ) <EOL> dtargs [ "<STR_LIT>" ] = [ [ <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:50> , - <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:50> , str ( current . T ( "<STR_LIT>" ) ) ] <EOL> ] <EOL> orderby = widget . get ( "<STR_LIT>" ) <EOL> if not orderby : <EOL> orderby = resource . get_config ( "<STR_LIT>" ) <EOL> if not orderby : <EOL> orderby = default_orderby ( ) <EOL> if not s3 . no_sspag : <EOL> dt_pagination = "<STR_LIT:true>" <EOL> if not limit and display_length is not None : <EOL> limit = <NUM_LIT:2> * display_length <EOL> else : <EOL> limit = None <EOL> else : <EOL> dt_pagination = "<STR_LIT:false>" <EOL> dt , totalrows , ids = resource . datatable ( fields = list_fields , <EOL> start = start , <EOL> limit = limit , <EOL> orderby = orderby ) <EOL> displayrows = totalrows <EOL> if dt . empty : <EOL> empty_str = self . crud_string ( tablename , <EOL> "<STR_LIT>" ) <EOL> else : <EOL> empty_str = self . crud_string ( tablename , <EOL> "<STR_LIT>" ) <EOL> empty = DIV ( empty_str , _class = "<STR_LIT>" ) <EOL> dtargs [ "<STR_LIT>" ] = dt_pagination <EOL> dtargs [ "<STR_LIT>" ] = display_length <EOL> s3 . no_formats = True <EOL> dtargs [ "<STR_LIT>" ] = r . url ( method = "<STR_LIT>" , vars = { } ) <EOL> dtargs [ "<STR_LIT>" ] = r . url ( vars = { "<STR_LIT>" : widget [ "<STR_LIT:index>" ] } , <EOL> representation = "<STR_LIT>" ) <EOL> actions = widget . get ( "<STR_LIT>" ) <EOL> if callable ( actions ) : <EOL> actions = actions ( r , list_id ) <EOL> if actions : <EOL> dtargs [ "<STR_LIT>" ] = actions <EOL> datatable = dt . html ( totalrows , <EOL> displayrows , <EOL> id = list_id , <EOL> ** dtargs ) <EOL> if dt . data : <EOL> empty . update ( _style = "<STR_LIT>" ) <EOL> else : <EOL> datatable . update ( _style = "<STR_LIT>" ) <EOL> contents = DIV ( datatable , empty , _class = "<STR_LIT>" ) <EOL> create_popup = self . _create_popup ( r , <EOL> widget , <EOL> list_id , <EOL> resource , <EOL> context , <EOL> totalrows ) <EOL> label = widget . get ( "<STR_LIT:label>" , "<STR_LIT>" ) <EOL> if label : <EOL> label = current . T ( label ) <EOL> else : <EOL> label = S3CRUD . crud_string ( tablename , "<STR_LIT>" ) <EOL> icon = widget . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if icon : <EOL> icon = ICON ( icon ) <EOL> _class = self . _lookup_class ( r , widget ) <EOL> output = DIV ( create_popup , <EOL> H4 ( icon , label , <EOL> _class = "<STR_LIT>" ) , <EOL> DIV ( contents , <EOL> _class = "<STR_LIT>" ) , <EOL> _class = _class ) <EOL> return output <EOL> elif representation == "<STR_LIT>" : <EOL> searchq , orderby , left = resource . datatable_filter ( list_fields , <EOL> get_vars ) <EOL> if not orderby : <EOL> orderby = widget . get ( "<STR_LIT>" ) <EOL> if not orderby : <EOL> orderby = resource . get_config ( "<STR_LIT>" ) <EOL> if not orderby : <EOL> orderby = default_orderby ( ) <EOL> if searchq is not None : <EOL> totalrows = resource . count ( ) <EOL> resource . add_filter ( searchq ) <EOL> else : <EOL> totalrows = None <EOL> if totalrows != <NUM_LIT:0> : <EOL> dt , displayrows , ids = resource . datatable ( fields = list_fields , <EOL> start = start , <EOL> limit = limit , <EOL> left = left , <EOL> orderby = orderby , <EOL> getids = False ) <EOL> else : <EOL> dt , displayrows = None , <NUM_LIT:0> <EOL> if totalrows is None : <EOL> totalrows = displayrows <EOL> draw = int ( get_vars . get ( "<STR_LIT>" ) or <NUM_LIT:0> ) <EOL> if dt is not None : <EOL> data = dt . json ( totalrows , <EOL> displayrows , <EOL> list_id , <EOL> draw , <EOL> ** dtargs ) <EOL> else : <EOL> data = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' % ( totalrows , list_id , draw ) <EOL> return data <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> def _form ( self , r , widget , ** attr ) : <EOL> """<STR_LIT>""" <EOL> label = widget . get ( "<STR_LIT:label>" , "<STR_LIT>" ) <EOL> if label : <EOL> label = current . T ( label ) <EOL> icon = widget . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if icon : <EOL> icon = ICON ( icon ) <EOL> context = widget . get ( "<STR_LIT>" ) <EOL> tablename = widget . get ( "<STR_LIT>" ) <EOL> resource , context = self . _resolve_context ( r , tablename , context ) <EOL> widget_filter = widget . get ( "<STR_LIT>" ) <EOL> if widget_filter : <EOL> resource . add_filter ( widget_filter ) <EOL> record = resource . select ( [ "<STR_LIT:id>" ] , limit = <NUM_LIT:1> , as_rows = True ) . first ( ) <EOL> if record : <EOL> record_id = record . id <EOL> else : <EOL> record_id = None <EOL> if record_id : <EOL> readonly = not current . auth . s3_has_permission ( "<STR_LIT>" , tablename , record_id ) <EOL> else : <EOL> readonly = not current . auth . s3_has_permission ( "<STR_LIT>" , tablename ) <EOL> sqlform = widget . get ( "<STR_LIT>" ) <EOL> if not sqlform : <EOL> sqlform = resource . get_config ( "<STR_LIT>" ) <EOL> if not sqlform : <EOL> from s3forms import S3SQLDefaultForm <EOL> sqlform = S3SQLDefaultForm ( ) <EOL> get_config = current . s3db . get_config <EOL> if record_id : <EOL> onvalidation = get_config ( tablename , "<STR_LIT>" ) or get_config ( tablename , "<STR_LIT>" ) <EOL> onaccept = get_config ( tablename , "<STR_LIT>" ) or get_config ( tablename , "<STR_LIT>" ) <EOL> else : <EOL> onvalidation = get_config ( tablename , "<STR_LIT>" ) or get_config ( tablename , "<STR_LIT>" ) <EOL> onaccept = get_config ( tablename , "<STR_LIT>" ) or get_config ( tablename , "<STR_LIT>" ) <EOL> form = sqlform ( request = r , <EOL> resource = resource , <EOL> record_id = record_id , <EOL> readonly = readonly , <EOL> format = "<STR_LIT:html>" , <EOL> onvalidation = onvalidation , <EOL> onaccept = onaccept , <EOL> ) <EOL> _class = self . _lookup_class ( r , widget ) <EOL> output = DIV ( H4 ( icon , <EOL> label , <EOL> _class = "<STR_LIT>" ) , <EOL> DIV ( form , <EOL> _class = "<STR_LIT>" ) , <EOL> _class = _class ) <EOL> return output <EOL> def _map ( self , r , widget , widgets , ** attr ) : <EOL> """<STR_LIT>""" <EOL> T = current . T <EOL> db = current . db <EOL> s3db = current . s3db <EOL> label = widget . get ( "<STR_LIT:label>" , "<STR_LIT>" ) <EOL> if label and isinstance ( label , basestring ) : <EOL> label = T ( label ) <EOL> icon = widget . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if icon : <EOL> icon = ICON ( icon ) <EOL> _class = self . _lookup_class ( r , widget ) <EOL> context = widget . get ( "<STR_LIT>" , None ) <EOL> tablename = r . tablename <EOL> resource , context = self . _resolve_context ( r , tablename , context ) <EOL> if context : <EOL> cserialize_url = context . serialize_url <EOL> else : <EOL> cserialize_url = lambda res : { } <EOL> height = widget . get ( "<STR_LIT>" , <NUM_LIT> ) <EOL> width = widget . get ( "<STR_LIT:width>" , <NUM_LIT> ) <EOL> bbox = widget . get ( "<STR_LIT>" , { } ) <EOL> ftable = s3db . gis_layer_feature <EOL> mtable = s3db . gis_marker <EOL> feature_resources = [ ] <EOL> fappend = feature_resources . append <EOL> s3dbresource = s3db . resource <EOL> for widget in widgets : <EOL> if widget [ "<STR_LIT:type>" ] not in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> continue <EOL> show_on_map = widget . get ( "<STR_LIT>" , True ) <EOL> if not show_on_map : <EOL> continue <EOL> tablename = widget [ "<STR_LIT>" ] <EOL> list_id = "<STR_LIT>" % ( tablename , widget [ "<STR_LIT:index>" ] ) <EOL> layer = dict ( name = T ( widget [ "<STR_LIT:label>" ] ) , <EOL> id = list_id , <EOL> active = True , <EOL> ) <EOL> filter = widget . get ( "<STR_LIT>" , None ) <EOL> marker = widget . get ( "<STR_LIT>" , None ) <EOL> if marker : <EOL> marker = db ( mtable . name == marker ) . select ( mtable . image , <EOL> mtable . height , <EOL> mtable . width , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> layer_id = None <EOL> layer_name = widget . get ( "<STR_LIT>" , None ) <EOL> if layer_name : <EOL> row = db ( ftable . name == layer_name ) . select ( ftable . layer_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if row : <EOL> layer_id = row . layer_id <EOL> if layer_id : <EOL> layer [ "<STR_LIT>" ] = layer_id <EOL> resource = s3dbresource ( tablename ) <EOL> filter_url = "<STR_LIT>" <EOL> first = True <EOL> if context : <EOL> filters = cserialize_url ( resource ) <EOL> for f in filters : <EOL> sep = "<STR_LIT>" if first else "<STR_LIT:&>" <EOL> filter_url = "<STR_LIT>" % ( filter_url , sep , f , filters [ f ] ) <EOL> first = False <EOL> if filter : <EOL> filters = filter . serialize_url ( resource ) <EOL> for f in filters : <EOL> sep = "<STR_LIT>" if first else "<STR_LIT:&>" <EOL> filter_url = "<STR_LIT>" % ( filter_url , sep , f , filters [ f ] ) <EOL> first = False <EOL> if filter_url : <EOL> layer [ "<STR_LIT>" ] = filter_url <EOL> else : <EOL> layer [ "<STR_LIT>" ] = tablename <EOL> map_url = widget . get ( "<STR_LIT>" , None ) <EOL> if not map_url : <EOL> c , f = tablename . split ( "<STR_LIT:_>" , <NUM_LIT:1> ) <EOL> map_url = URL ( c = c , f = f , extension = "<STR_LIT>" ) <EOL> resource = s3dbresource ( tablename ) <EOL> first = True <EOL> if context : <EOL> filters = cserialize_url ( resource ) <EOL> for f in filters : <EOL> sep = "<STR_LIT:?>" if first else "<STR_LIT:&>" <EOL> map_url = "<STR_LIT>" % ( map_url , sep , f , filters [ f ] ) <EOL> first = False <EOL> if filter : <EOL> filters = filter . serialize_url ( resource ) <EOL> for f in filters : <EOL> sep = "<STR_LIT:?>" if first else "<STR_LIT:&>" <EOL> map_url = "<STR_LIT>" % ( map_url , sep , f , filters [ f ] ) <EOL> first = False <EOL> layer [ "<STR_LIT:url>" ] = map_url <EOL> if marker : <EOL> layer [ "<STR_LIT>" ] = marker <EOL> fappend ( layer ) <EOL> profile_layers = s3db . get_config ( r . tablename , "<STR_LIT>" ) <EOL> if profile_layers : <EOL> for layer in profile_layers : <EOL> fappend ( layer ) <EOL> lat = widget . get ( "<STR_LIT>" , None ) <EOL> lon = widget . get ( "<STR_LIT>" , None ) <EOL> map = current . gis . show_map ( height = height , <EOL> lat = lat , <EOL> lon = lon , <EOL> width = width , <EOL> bbox = bbox , <EOL> collapsed = True , <EOL> feature_resources = feature_resources , <EOL> ) <EOL> fullscreen = A ( ICON ( "<STR_LIT>" ) , <EOL> _href = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" ) , <EOL> _class = "<STR_LIT>" , <EOL> _title = T ( "<STR_LIT>" ) , <EOL> ) <EOL> s3 = current . response . s3 <EOL> if s3 . debug : <EOL> script = "<STR_LIT>" % current . request . application <EOL> else : <EOL> script = "<STR_LIT>" % current . request . application <EOL> s3 . scripts . append ( script ) <EOL> output = DIV ( fullscreen , <EOL> H4 ( icon , <EOL> label , <EOL> _class = "<STR_LIT>" ) , <EOL> DIV ( map , <EOL> _class = "<STR_LIT>" ) , <EOL> _class = _class ) <EOL> return output <EOL> def _report ( self , r , widget , ** attr ) : <EOL> """<STR_LIT>""" <EOL> context = widget . get ( "<STR_LIT>" , None ) <EOL> tablename = widget . get ( "<STR_LIT>" , None ) <EOL> resource , context = self . _resolve_context ( r , tablename , context ) <EOL> widget_filter = widget . get ( "<STR_LIT>" , None ) <EOL> if widget_filter : <EOL> resource . add_filter ( widget_filter ) <EOL> widget_id = "<STR_LIT>" % ( tablename , widget [ "<STR_LIT:index>" ] ) <EOL> report = S3Report ( ) <EOL> report . resource = resource <EOL> ajaxurl = widget . get ( "<STR_LIT>" , None ) <EOL> contents = report . widget ( r , <EOL> widget_id = widget_id , <EOL> ajaxurl = ajaxurl , <EOL> ** attr ) <EOL> label = widget . get ( "<STR_LIT:label>" , "<STR_LIT>" ) <EOL> if label and isinstance ( label , basestring ) : <EOL> label = current . T ( label ) <EOL> icon = widget . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if icon : <EOL> icon = ICON ( icon ) <EOL> _class = self . _lookup_class ( r , widget ) <EOL> output = DIV ( H4 ( icon , label , <EOL> _class = "<STR_LIT>" ) , <EOL> DIV ( contents , <EOL> _class = "<STR_LIT>" ) , <EOL> _class = _class ) <EOL> return output <EOL> @ staticmethod <EOL> def _lookup_class ( r , widget ) : <EOL> """<STR_LIT>""" <EOL> page_cols = current . s3db . get_config ( r . tablename , "<STR_LIT>" ) <EOL> if not page_cols : <EOL> page_cols = <NUM_LIT:2> <EOL> widget_cols = widget . get ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> span = int ( <NUM_LIT:12> / page_cols ) * widget_cols <EOL> formstyle = current . deployment_settings . ui . get ( "<STR_LIT>" , "<STR_LIT:default>" ) <EOL> if current . deployment_settings . ui . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> return "<STR_LIT>" % span <EOL> return "<STR_LIT>" % span <EOL> @ staticmethod <EOL> def _create_popup ( r , widget , list_id , resource , context , numrows ) : <EOL> """<STR_LIT>""" <EOL> create = "<STR_LIT>" <EOL> insert = widget . get ( "<STR_LIT>" , True ) <EOL> if not insert : <EOL> return create <EOL> table = resource . table <EOL> tablename = resource . tablename <EOL> c , f = tablename . split ( "<STR_LIT:_>" , <NUM_LIT:1> ) <EOL> create_controller = widget . get ( "<STR_LIT>" ) <EOL> if create_controller : <EOL> c = create_controller <EOL> create_function = widget . get ( "<STR_LIT>" ) <EOL> if create_function : <EOL> f = create_function <EOL> permit = current . auth . s3_has_permission <EOL> create_ok = permit ( "<STR_LIT>" , table , c = c , f = f ) <EOL> if create_ok : <EOL> if not create_controller or not create_function : <EOL> create_ok = permit ( "<STR_LIT>" , r . table , record_id = r . id , c = c , f = f ) <EOL> if create_ok : <EOL> widget_filter = widget . get ( "<STR_LIT>" ) <EOL> if widget_filter : <EOL> url_vars = widget_filter . serialize_url ( resource ) <EOL> else : <EOL> url_vars = Storage ( ) <EOL> if context : <EOL> filters = context . serialize_url ( resource ) <EOL> for selector in filters : <EOL> url_vars [ selector ] = filters [ selector ] <EOL> default = widget . get ( "<STR_LIT:default>" ) <EOL> if default : <EOL> k , v = default . split ( "<STR_LIT:=>" , <NUM_LIT:1> ) <EOL> url_vars [ k ] = v <EOL> url_vars . refresh = list_id <EOL> url_vars . profile = r . tablename <EOL> label_create = widget . get ( "<STR_LIT>" , None ) <EOL> if label_create : <EOL> label_create = current . T ( label_create ) <EOL> else : <EOL> label_create = S3CRUD . crud_string ( tablename , "<STR_LIT>" ) <EOL> component = widget . get ( "<STR_LIT>" , None ) <EOL> if component : <EOL> args = [ r . id , component , "<STR_LIT>" ] <EOL> else : <EOL> args = [ "<STR_LIT>" ] <EOL> add_url = URL ( c = c , f = f , args = args , vars = url_vars ) <EOL> if callable ( insert ) : <EOL> create = insert ( r , list_id , label_create , add_url ) <EOL> elif current . deployment_settings . ui . formstyle == "<STR_LIT>" : <EOL> create = A ( ICON ( "<STR_LIT>" , _class = "<STR_LIT>" ) , <EOL> _href = add_url , <EOL> _class = "<STR_LIT>" , <EOL> _title = label_create , <EOL> ) <EOL> else : <EOL> create = A ( label_create , <EOL> _href = add_url , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> if widget . get ( "<STR_LIT:type>" ) == "<STR_LIT>" : <EOL> multiple = widget . get ( "<STR_LIT>" , True ) <EOL> if not multiple and hasattr ( create , "<STR_LIT>" ) : <EOL> if numrows : <EOL> create . update ( _style = "<STR_LIT>" ) <EOL> else : <EOL> create . update ( _style = "<STR_LIT>" ) <EOL> createid = create [ "<STR_LIT>" ] <EOL> if not createid : <EOL> createid = "<STR_LIT>" % list_id <EOL> create . update ( _id = createid ) <EOL> script = '''<STR_LIT>''' % dict ( list_id = list_id , createid = createid ) <EOL> current . response . s3 . jquery_ready . append ( script ) <EOL> return create </s>
