<s> """<STR_LIT>""" <EOL> __all__ = ( "<STR_LIT>" , ) <EOL> try : <EOL> import json <EOL> except ImportError : <EOL> try : <EOL> import simplejson as json <EOL> except : <EOL> import gluon . contrib . simplejson as json <EOL> try : <EOL> from lxml import etree <EOL> except ImportError : <EOL> import sys <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> raise <EOL> from gluon import * <EOL> from gluon . languages import lazyT <EOL> from gluon . storage import Storage <EOL> from gluon . tools import callback <EOL> from s3datetime import S3DateTime <EOL> from s3export import S3Exporter <EOL> from s3forms import S3SQLDefaultForm <EOL> from s3rest import S3Method <EOL> from s3utils import s3_unicode , s3_validate , s3_represent_value , s3_set_extension <EOL> from s3widgets import S3EmbeddedComponentWidget , S3Selector , ICON <EOL> SEPARATORS = ( "<STR_LIT:U+002C>" , "<STR_LIT::>" ) <EOL> class S3CRUD ( S3Method ) : <EOL> """<STR_LIT>""" <EOL> def apply_method ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> self . settings = current . response . s3 . crud <EOL> sqlform = self . _config ( "<STR_LIT>" ) <EOL> self . sqlform = sqlform if sqlform else S3SQLDefaultForm ( ) <EOL> self . data = None <EOL> if r . http == "<STR_LIT:GET>" and not self . record_id : <EOL> populate = attr . pop ( "<STR_LIT>" , None ) <EOL> if callable ( populate ) : <EOL> try : <EOL> self . data = populate ( r , ** attr ) <EOL> except TypeError : <EOL> self . data = None <EOL> except : <EOL> raise <EOL> elif isinstance ( populate , dict ) : <EOL> self . data = populate <EOL> method = self . method <EOL> if r . http == "<STR_LIT>" or self . method == "<STR_LIT>" : <EOL> output = self . delete ( r , ** attr ) <EOL> elif method == "<STR_LIT>" : <EOL> output = self . create ( r , ** attr ) <EOL> elif method == "<STR_LIT>" : <EOL> output = self . read ( r , ** attr ) <EOL> elif method == "<STR_LIT>" : <EOL> output = self . update ( r , ** attr ) <EOL> elif method == "<STR_LIT:list>" : <EOL> output = self . select ( r , ** attr ) <EOL> elif method in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> _attr = Storage ( attr ) <EOL> _attr [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> if method == "<STR_LIT>" : <EOL> self . hide_filter = False <EOL> output = self . select ( r , ** _attr ) <EOL> elif method in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> _attr = Storage ( attr ) <EOL> _attr [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> if method == "<STR_LIT>" : <EOL> self . hide_filter = False <EOL> output = self . select ( r , ** _attr ) <EOL> elif method == "<STR_LIT>" : <EOL> output = self . validate ( r , ** attr ) <EOL> elif method == "<STR_LIT>" : <EOL> if r . record : <EOL> output = self . review ( r , ** attr ) <EOL> else : <EOL> output = self . unapproved ( r , ** attr ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_METHOD ) <EOL> return output <EOL> def widget ( self , r , method = None , widget_id = None , visible = True , ** attr ) : <EOL> """<STR_LIT>""" <EOL> self . settings = current . response . s3 . crud <EOL> sqlform = self . _config ( "<STR_LIT>" ) <EOL> self . sqlform = sqlform if sqlform else S3SQLDefaultForm ( ) <EOL> _attr = Storage ( attr ) <EOL> _attr [ "<STR_LIT>" ] = widget_id <EOL> if method == "<STR_LIT>" : <EOL> output = self . _datatable ( r , ** _attr ) <EOL> if isinstance ( output , dict ) : <EOL> output = DIV ( output [ "<STR_LIT>" ] , _id = "<STR_LIT>" ) <EOL> return output <EOL> elif method == "<STR_LIT>" : <EOL> output = self . _datalist ( r , ** _attr ) <EOL> if isinstance ( output , dict ) and "<STR_LIT>" in output : <EOL> output = DIV ( output [ "<STR_LIT>" ] , _id = "<STR_LIT>" ) <EOL> return output <EOL> elif method == "<STR_LIT>" : <EOL> return self . _widget_create ( r , ** _attr ) <EOL> else : <EOL> return None <EOL> def create ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> session = current . session <EOL> request = self . request <EOL> response = current . response <EOL> resource = self . resource <EOL> table = resource . table <EOL> tablename = resource . tablename <EOL> representation = r . representation <EOL> output = dict ( ) <EOL> native = r . method == "<STR_LIT>" <EOL> _config = self . _config <EOL> insertable = _config ( "<STR_LIT>" , True ) <EOL> if not insertable : <EOL> if native : <EOL> r . error ( <NUM_LIT> , current . ERROR . METHOD_DISABLED ) <EOL> else : <EOL> return dict ( form = None ) <EOL> authorised = self . _permitted ( method = "<STR_LIT>" ) <EOL> if not authorised : <EOL> if native : <EOL> r . unauthorised ( ) <EOL> else : <EOL> return dict ( form = None ) <EOL> onvalidation = _config ( "<STR_LIT>" ) or _config ( "<STR_LIT>" ) <EOL> onaccept = _config ( "<STR_LIT>" ) or _config ( "<STR_LIT>" ) <EOL> if r . interactive : <EOL> crud_string = self . crud_string <EOL> if native : <EOL> if representation in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = request . vars . caller <EOL> else : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> if r . component : <EOL> title = crud_string ( r . tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT:title>" ] = title <EOL> else : <EOL> title = crud_string ( tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT:title>" ] = title <EOL> output [ "<STR_LIT>" ] = crud_string ( tablename , "<STR_LIT>" ) <EOL> buttons = self . render_buttons ( r , [ "<STR_LIT:list>" ] , ** attr ) <EOL> if buttons : <EOL> output [ "<STR_LIT>" ] = buttons <EOL> link = None <EOL> if r . component : <EOL> if resource . link is None : <EOL> link = self . _embed_component ( resource , record = r . id ) <EOL> pkey = resource . pkey <EOL> fkey = resource . fkey <EOL> field = table [ fkey ] <EOL> value = r . record [ pkey ] <EOL> field . comment = None <EOL> field . default = value <EOL> field . update = value <EOL> if r . http == "<STR_LIT:POST>" : <EOL> r . post_vars . update ( { fkey : value } ) <EOL> field . readable = False <EOL> field . writable = False <EOL> else : <EOL> link = Storage ( resource = resource . link , master = r . record ) <EOL> get_vars = r . get_vars <EOL> hierarchy = None <EOL> link_to_parent = get_vars . get ( "<STR_LIT>" ) <EOL> if link_to_parent : <EOL> try : <EOL> parent = long ( link_to_parent ) <EOL> except ValueError : <EOL> r . error ( <NUM_LIT> , "<STR_LIT>" % link_to_parent ) <EOL> else : <EOL> from s3hierarchy import S3Hierarchy <EOL> h = S3Hierarchy ( tablename ) <EOL> if h . config : <EOL> try : <EOL> hierarchy = h . preprocess_create_node ( r , parent ) <EOL> except KeyError : <EOL> import sys <EOL> r . error ( <NUM_LIT> , sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> from_table = None <EOL> from_record = get_vars . get ( "<STR_LIT>" ) <EOL> map_fields = get_vars . get ( "<STR_LIT>" ) <EOL> if from_record : <EOL> del get_vars [ "<STR_LIT>" ] <EOL> if from_record . find ( "<STR_LIT:.>" ) != - <NUM_LIT:1> : <EOL> from_table , from_record = from_record . split ( "<STR_LIT:.>" , <NUM_LIT:1> ) <EOL> from_table = current . db . get ( from_table , None ) <EOL> if not from_table : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_RESOURCE ) <EOL> else : <EOL> from_table = table <EOL> try : <EOL> from_record = long ( from_record ) <EOL> except : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_RECORD ) <EOL> authorised = current . auth . s3_has_permission ( "<STR_LIT>" , <EOL> from_table . _tablename , <EOL> from_record ) <EOL> if not authorised : <EOL> r . unauthorised ( ) <EOL> if map_fields : <EOL> del r . get_vars [ "<STR_LIT>" ] <EOL> if map_fields . find ( "<STR_LIT:$>" ) != - <NUM_LIT:1> : <EOL> mf = map_fields . split ( "<STR_LIT:U+002C>" ) <EOL> mf = [ f . find ( "<STR_LIT:$>" ) != - <NUM_LIT:1> and f . split ( "<STR_LIT:$>" ) or [ f , f ] for f in mf ] <EOL> map_fields = Storage ( mf ) <EOL> else : <EOL> map_fields = map_fields . split ( "<STR_LIT:U+002C>" ) <EOL> message = crud_string ( self . tablename , "<STR_LIT>" ) <EOL> if "<STR_LIT:id>" in request . post_vars : <EOL> post_vars = request . post_vars <EOL> original = str ( post_vars . id ) <EOL> formkey = session . get ( "<STR_LIT>" % tablename ) <EOL> formname = "<STR_LIT>" % ( tablename , original ) <EOL> session [ "<STR_LIT>" % formname ] = formkey <EOL> if "<STR_LIT>" in table : <EOL> table . deleted . writable = True <EOL> post_vars [ "<STR_LIT>" ] = False <EOL> if "<STR_LIT>" in table : <EOL> table . created_on . writable = True <EOL> post_vars [ "<STR_LIT>" ] = request . utcnow <EOL> if "<STR_LIT>" in table : <EOL> table . created_by . writable = True <EOL> if current . auth . user : <EOL> post_vars [ "<STR_LIT>" ] = current . auth . user . id <EOL> else : <EOL> post_vars [ "<STR_LIT>" ] = None <EOL> post_vars [ "<STR_LIT>" ] = True <EOL> post_vars [ "<STR_LIT>" ] = formname <EOL> post_vars [ "<STR_LIT:id>" ] = original <EOL> request . vars . update ( ** post_vars ) <EOL> else : <EOL> original = None <EOL> subheadings = _config ( "<STR_LIT>" ) <EOL> self . _interim_save_button ( ) <EOL> if r . representation == "<STR_LIT:html>" and r . method == "<STR_LIT>" : <EOL> self . _default_cancel_button ( r ) <EOL> output [ "<STR_LIT>" ] = self . sqlform ( request = request , <EOL> resource = resource , <EOL> data = self . data , <EOL> record_id = original , <EOL> from_table = from_table , <EOL> from_record = from_record , <EOL> map_fields = map_fields , <EOL> onvalidation = onvalidation , <EOL> onaccept = onaccept , <EOL> link = link , <EOL> hierarchy = hierarchy , <EOL> message = message , <EOL> subheadings = subheadings , <EOL> format = representation , <EOL> ) <EOL> if self . settings . navigate_away_confirm : <EOL> response . s3 . jquery_ready . append ( "<STR_LIT>" ) <EOL> if representation in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . next = None <EOL> else : <EOL> if r . http == "<STR_LIT:POST>" and "<STR_LIT>" in r . post_vars : <EOL> next_vars = self . _remove_filters ( r . get_vars ) <EOL> create_next = r . url ( target = "<STR_LIT>" , method = "<STR_LIT>" , <EOL> vars = next_vars ) <EOL> elif r . http == "<STR_LIT:POST>" and "<STR_LIT>" in r . post_vars : <EOL> create_next = _config ( "<STR_LIT>" ) <EOL> elif session . s3 . rapid_data_entry and not r . component : <EOL> create_next = r . url ( ) <EOL> else : <EOL> create_next = _config ( "<STR_LIT>" ) <EOL> if not create_next : <EOL> next_vars = self . _remove_filters ( r . get_vars ) <EOL> if r . component : <EOL> self . next = r . url ( method = "<STR_LIT>" , <EOL> vars = next_vars ) <EOL> else : <EOL> self . next = r . url ( id = "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> vars = next_vars ) <EOL> elif callable ( create_next ) : <EOL> self . next = create_next ( r ) <EOL> else : <EOL> self . next = create_next <EOL> elif representation == "<STR_LIT>" : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> crud_string = self . crud_string <EOL> message = crud_string ( tablename , "<STR_LIT>" ) <EOL> subheadings = _config ( "<STR_LIT>" ) <EOL> output [ "<STR_LIT:title>" ] = crud_string ( tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> output [ "<STR_LIT>" ] = self . sqlform ( request = request , <EOL> resource = resource , <EOL> data = self . data , <EOL> onvalidation = onvalidation , <EOL> onaccept = onaccept , <EOL> message = message , <EOL> subheadings = subheadings , <EOL> format = representation ) <EOL> elif representation == "<STR_LIT>" : <EOL> import cgi <EOL> import csv <EOL> csv . field_size_limit ( <NUM_LIT> ) <EOL> infile = request . vars . filename <EOL> if isinstance ( infile , cgi . FieldStorage ) and infile . filename : <EOL> infile = infile . file <EOL> else : <EOL> try : <EOL> infile = open ( infile , "<STR_LIT:rb>" ) <EOL> except : <EOL> session . error = current . T ( "<STR_LIT>" ) % dict ( filename = infile ) <EOL> redirect ( r . url ( method = "<STR_LIT>" , representation = "<STR_LIT:html>" ) ) <EOL> try : <EOL> self . import_csv ( infile , table = table ) <EOL> except : <EOL> session . error = current . T ( "<STR_LIT>" ) <EOL> else : <EOL> session . confirmation = current . T ( "<STR_LIT>" ) <EOL> elif representation == "<STR_LIT>" : <EOL> from s3pdf import S3PDF <EOL> exporter = S3PDF ( ) <EOL> return exporter ( r , ** attr ) <EOL> elif representation == "<STR_LIT:url>" : <EOL> results = self . import_url ( r ) <EOL> return results <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> return output <EOL> def _widget_create ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> response = current . response <EOL> resource = self . resource <EOL> get_config = resource . get_config <EOL> tablename = resource . tablename <EOL> output = { } <EOL> insertable = get_config ( "<STR_LIT>" , True ) <EOL> if insertable : <EOL> listadd = get_config ( "<STR_LIT>" , True ) <EOL> addbtn = get_config ( "<STR_LIT>" , False ) <EOL> if listadd : <EOL> self . data = None <EOL> if r . http == "<STR_LIT:GET>" and not self . record_id : <EOL> populate = attr . pop ( "<STR_LIT>" , None ) <EOL> if callable ( populate ) : <EOL> try : <EOL> self . data = populate ( r , ** attr ) <EOL> except TypeError : <EOL> self . data = None <EOL> except : <EOL> raise <EOL> elif isinstance ( populate , dict ) : <EOL> self . data = populate <EOL> view = response . view <EOL> s3 = response . s3 <EOL> cancel = s3 . cancel <EOL> s3 . cancel = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> form = self . create ( r , ** attr ) . get ( "<STR_LIT>" , None ) <EOL> if form and form . accepted and self . next : <EOL> return { "<STR_LIT:success>" : True , "<STR_LIT>" : self . next } <EOL> response . view = view <EOL> s3 . cancel = cancel <EOL> if form is not None : <EOL> output [ "<STR_LIT>" ] = form <EOL> output [ "<STR_LIT>" ] = self . crud_button ( tablename = tablename , <EOL> name = "<STR_LIT>" , <EOL> icon = "<STR_LIT>" , <EOL> _id = "<STR_LIT>" ) <EOL> addtitle = self . crud_string ( tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = addtitle <EOL> if r . http == "<STR_LIT:POST>" : <EOL> script = '''<STR_LIT>''' <EOL> s3 . jquery_ready . append ( script ) <EOL> elif addbtn : <EOL> add_btn = self . crud_button ( <EOL> tablename = tablename , <EOL> name = "<STR_LIT>" , <EOL> icon = "<STR_LIT>" , <EOL> _id = "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = { "<STR_LIT>" : add_btn } <EOL> view = self . _view ( r , "<STR_LIT>" ) <EOL> output = XML ( response . render ( view , output ) ) <EOL> return output <EOL> def read ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> authorised = self . _permitted ( ) <EOL> if not authorised : <EOL> r . unauthorised ( ) <EOL> request = self . request <EOL> response = current . response <EOL> resource = self . resource <EOL> table = resource . table <EOL> tablename = resource . tablename <EOL> representation = r . representation <EOL> output = dict ( ) <EOL> _config = self . _config <EOL> editable = _config ( "<STR_LIT>" , True ) <EOL> record_id = self . record_id <EOL> if r . interactive : <EOL> if not record_id and r . component and not r . component . multiple : <EOL> authorised = self . _permitted ( method = "<STR_LIT>" ) <EOL> if authorised : <EOL> r . method = "<STR_LIT>" <EOL> return self . create ( r , ** attr ) <EOL> else : <EOL> return self . select ( r , ** attr ) <EOL> if not r . method : <EOL> authorised = self . _permitted ( "<STR_LIT>" ) <EOL> if authorised and representation == "<STR_LIT:html>" and editable : <EOL> return self . update ( r , ** attr ) <EOL> subheadings = _config ( "<STR_LIT>" ) <EOL> crud_string = self . crud_string <EOL> title = crud_string ( r . tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT:title>" ] = title <EOL> if r . component : <EOL> subtitle = crud_string ( tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = subtitle <EOL> output [ "<STR_LIT>" ] = crud_string ( tablename , "<STR_LIT>" ) <EOL> if record_id : <EOL> try : <EOL> item = self . sqlform ( request = request , <EOL> resource = resource , <EOL> record_id = record_id , <EOL> readonly = True , <EOL> subheadings = subheadings , <EOL> format = representation ) <EOL> except HTTP , e : <EOL> message = current . ERROR . BAD_RECORD if e . status == <NUM_LIT> else e . message <EOL> r . error ( e . status , message ) <EOL> else : <EOL> item = DIV ( crud_string ( tablename , "<STR_LIT>" ) , <EOL> _class = "<STR_LIT>" ) <EOL> if representation == "<STR_LIT:html>" : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = item <EOL> elif representation == "<STR_LIT>" : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = item <EOL> caller = attr . get ( "<STR_LIT>" , None ) <EOL> output [ "<STR_LIT>" ] = caller <EOL> elif representation == "<STR_LIT>" : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = item <EOL> buttons = self . render_buttons ( r , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:list>" , "<STR_LIT>" ] , <EOL> record_id = record_id , <EOL> ** attr ) <EOL> if buttons : <EOL> output [ "<STR_LIT>" ] = buttons <EOL> last_update = self . last_update ( ) <EOL> if last_update : <EOL> try : <EOL> output [ "<STR_LIT>" ] = last_update [ "<STR_LIT>" ] <EOL> except : <EOL> pass <EOL> try : <EOL> output [ "<STR_LIT>" ] = last_update [ "<STR_LIT>" ] <EOL> except : <EOL> pass <EOL> from s3merge import S3Merge <EOL> output [ "<STR_LIT>" ] = S3Merge . bookmark ( r , tablename , record_id ) <EOL> elif representation == "<STR_LIT>" : <EOL> T = current . T <EOL> fields = [ f for f in table if f . readable ] <EOL> if r . component : <EOL> if record_id : <EOL> record = current . db ( table . _id == record_id ) . select ( limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> * fields <EOL> ) . first ( ) <EOL> else : <EOL> record = None <EOL> else : <EOL> record = r . record <EOL> if record : <EOL> for field in fields : <EOL> try : <EOL> value = record [ field ] <EOL> except : <EOL> value = None <EOL> if value is None or value == "<STR_LIT>" or value == [ ] : <EOL> field . readable = False <EOL> item = self . sqlform ( request = request , <EOL> resource = resource , <EOL> record_id = record_id , <EOL> readonly = True , <EOL> format = representation ) <EOL> popup_edit_url = _config ( "<STR_LIT>" , None ) <EOL> if popup_edit_url and current . auth . s3_has_permission ( "<STR_LIT>" , table , record_id ) : <EOL> details_btn = A ( T ( "<STR_LIT>" ) , <EOL> _href = popup_edit_url , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> output [ "<STR_LIT>" ] = details_btn <EOL> else : <EOL> popup_url = _config ( "<STR_LIT>" , None ) <EOL> if popup_url is None : <EOL> popup_url = r . url ( method = "<STR_LIT>" , representation = "<STR_LIT:html>" ) <EOL> if popup_url : <EOL> details_btn = A ( T ( "<STR_LIT>" ) , <EOL> _href = popup_url , <EOL> _class = "<STR_LIT>" , <EOL> _target = "<STR_LIT>" , <EOL> ) <EOL> output [ "<STR_LIT>" ] = details_btn <EOL> title = self . crud_string ( r . tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT:title>" ] = title <EOL> else : <EOL> item = T ( "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = item <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> elif representation == "<STR_LIT>" : <EOL> exporter = S3Exporter ( ) . csv <EOL> output = exporter ( resource ) <EOL> elif representation == "<STR_LIT>" : <EOL> exporter = S3Exporter ( ) . pdf <EOL> output = exporter ( resource , request = r , ** attr ) <EOL> elif representation == "<STR_LIT>" : <EOL> list_fields = resource . list_fields ( ) <EOL> exporter = S3Exporter ( ) . shp <EOL> output = exporter ( resource , list_fields = list_fields , ** attr ) <EOL> elif representation == "<STR_LIT>" : <EOL> list_fields = resource . list_fields ( ) <EOL> exporter = S3Exporter ( ) . svg <EOL> output = exporter ( resource , list_fields = list_fields , ** attr ) <EOL> elif representation == "<STR_LIT>" : <EOL> list_fields = resource . list_fields ( ) <EOL> exporter = S3Exporter ( ) . xls <EOL> output = exporter ( resource , list_fields = list_fields ) <EOL> elif representation == "<STR_LIT>" : <EOL> exporter = S3Exporter ( ) . json <EOL> get_vars = request . get_vars <EOL> if "<STR_LIT>" in get_vars : <EOL> tooltip = get_vars [ "<STR_LIT>" ] <EOL> else : <EOL> tooltip = None <EOL> output = exporter ( resource , tooltip = tooltip ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> return output <EOL> def update ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> resource = self . resource <EOL> table = resource . table <EOL> tablename = resource . tablename <EOL> representation = r . representation <EOL> output = dict ( ) <EOL> _config = self . _config <EOL> editable = _config ( "<STR_LIT>" , True ) <EOL> onvalidation = _config ( "<STR_LIT>" ) or _config ( "<STR_LIT>" ) <EOL> onaccept = _config ( "<STR_LIT>" ) or _config ( "<STR_LIT>" ) <EOL> record_id = self . record_id <EOL> if r . interactive and not record_id : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_RECORD ) <EOL> if not editable : <EOL> if r . interactive : <EOL> return self . read ( r , ** attr ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . METHOD_DISABLED ) <EOL> authorised = self . _permitted ( method = "<STR_LIT>" ) <EOL> if not authorised : <EOL> r . unauthorised ( ) <EOL> if r . interactive or representation == "<STR_LIT>" : <EOL> response = current . response <EOL> s3 = response . s3 <EOL> subheadings = _config ( "<STR_LIT>" ) <EOL> if representation == "<STR_LIT:html>" : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> elif representation in "<STR_LIT>" : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> elif representation == "<STR_LIT>" : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> elif representation == "<STR_LIT>" : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> crud_string = self . crud_string <EOL> if r . component : <EOL> title = crud_string ( r . tablename , "<STR_LIT>" ) <EOL> subtitle = crud_string ( self . tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT:title>" ] = title <EOL> output [ "<STR_LIT>" ] = subtitle <EOL> else : <EOL> title = crud_string ( self . tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT:title>" ] = title <EOL> output [ "<STR_LIT>" ] = crud_string ( tablename , "<STR_LIT>" ) <EOL> link = None <EOL> if r . component : <EOL> if resource . link is None : <EOL> link = self . _embed_component ( resource , record = r . id ) <EOL> pkey = resource . pkey <EOL> fkey = resource . fkey <EOL> field = table [ fkey ] <EOL> value = r . record [ pkey ] <EOL> field . comment = None <EOL> field . default = value <EOL> field . update = value <EOL> if r . http == "<STR_LIT:POST>" : <EOL> r . post_vars . update ( { fkey : value } ) <EOL> field . readable = False <EOL> field . writable = False <EOL> else : <EOL> link = Storage ( resource = resource . link , master = r . record ) <EOL> message = crud_string ( self . tablename , "<STR_LIT>" ) <EOL> self . _interim_save_button ( ) <EOL> if r . representation == "<STR_LIT:html>" and ( r . method == "<STR_LIT>" or not r . method ) : <EOL> self . _default_cancel_button ( r ) <EOL> try : <EOL> form = self . sqlform ( request = self . request , <EOL> resource = resource , <EOL> record_id = record_id , <EOL> onvalidation = onvalidation , <EOL> onaccept = onaccept , <EOL> message = message , <EOL> link = link , <EOL> subheadings = subheadings , <EOL> format = representation ) <EOL> except HTTP , e : <EOL> message = current . ERROR . BAD_RECORD if e . status == <NUM_LIT> else e . message <EOL> r . error ( e . status , message ) <EOL> if self . settings . navigate_away_confirm : <EOL> s3 . jquery_ready . append ( "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = form <EOL> if representation == "<STR_LIT>" : <EOL> output [ "<STR_LIT>" ] = form <EOL> output [ "<STR_LIT:title>" ] = "<STR_LIT>" <EOL> buttons = self . render_buttons ( r , <EOL> [ "<STR_LIT>" ] , <EOL> record_id = record_id , <EOL> ** attr ) <EOL> if buttons : <EOL> output [ "<STR_LIT>" ] = buttons <EOL> last_update = self . last_update ( ) <EOL> if last_update : <EOL> try : <EOL> output [ "<STR_LIT>" ] = last_update [ "<STR_LIT>" ] <EOL> except : <EOL> pass <EOL> try : <EOL> output [ "<STR_LIT>" ] = last_update [ "<STR_LIT>" ] <EOL> except : <EOL> pass <EOL> from s3merge import S3Merge <EOL> output [ "<STR_LIT>" ] = S3Merge . bookmark ( r , tablename , record_id ) <EOL> if r . http == "<STR_LIT:POST>" and "<STR_LIT>" in r . post_vars : <EOL> next_vars = self . _remove_filters ( r . get_vars ) <EOL> self . next = r . url ( target = "<STR_LIT>" , method = "<STR_LIT>" , <EOL> vars = next_vars ) <EOL> else : <EOL> update_next = _config ( "<STR_LIT>" ) <EOL> if representation in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . next = None <EOL> elif not update_next : <EOL> next_vars = self . _remove_filters ( r . get_vars ) <EOL> if r . component : <EOL> self . next = r . url ( method = "<STR_LIT>" , vars = next_vars ) <EOL> else : <EOL> self . next = r . url ( id = "<STR_LIT>" , <EOL> method = "<STR_LIT>" , <EOL> vars = next_vars ) <EOL> else : <EOL> try : <EOL> self . next = update_next ( self ) <EOL> except TypeError : <EOL> self . next = update_next <EOL> elif representation == "<STR_LIT:url>" : <EOL> return self . import_url ( r ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> return output <EOL> def delete ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> output = dict ( ) <EOL> config = self . _config <EOL> deletable = config ( "<STR_LIT>" , True ) <EOL> delete_next = config ( "<STR_LIT>" , None ) <EOL> if not deletable : <EOL> r . error ( <NUM_LIT> , current . ERROR . NOT_PERMITTED , <EOL> next = r . url ( method = "<STR_LIT>" ) ) <EOL> record_id = self . record_id <EOL> authorised = self . _permitted ( ) <EOL> if not authorised : <EOL> r . unauthorised ( ) <EOL> elif ( r . interactive or r . representation == "<STR_LIT>" ) and r . http == "<STR_LIT:GET>" and not record_id : <EOL> output = self . _datatable ( r , ** attr ) <EOL> if isinstance ( output , dict ) : <EOL> form = FORM ( TABLE ( TR ( TD ( self . settings . confirm_delete , <EOL> _style = "<STR_LIT>" ) , <EOL> TD ( INPUT ( _type = "<STR_LIT>" , <EOL> _value = current . T ( "<STR_LIT>" ) , <EOL> _style = "<STR_LIT>" ) ) ) ) ) <EOL> output [ "<STR_LIT>" ] = form <EOL> current . response . view = self . _view ( r , "<STR_LIT>" ) <EOL> else : <EOL> return output <EOL> elif r . interactive and ( r . http == "<STR_LIT:POST>" or <EOL> r . http == "<STR_LIT:GET>" and record_id ) : <EOL> numrows = self . resource . delete ( format = r . representation ) <EOL> if numrows > <NUM_LIT:1> : <EOL> message = "<STR_LIT>" % ( numrows , current . T ( "<STR_LIT>" ) ) <EOL> elif numrows == <NUM_LIT:1> : <EOL> message = self . crud_string ( self . tablename , <EOL> "<STR_LIT>" ) <EOL> else : <EOL> r . error ( <NUM_LIT> , self . resource . error , next = r . url ( method = "<STR_LIT>" ) ) <EOL> current . response . confirmation = message <EOL> r . http = "<STR_LIT>" <EOL> self . next = delete_next or r . url ( method = "<STR_LIT>" ) <EOL> elif r . http == "<STR_LIT>" or r . representation == "<STR_LIT>" and r . http == "<STR_LIT:POST>" and record_id : <EOL> numrows = None <EOL> resource = self . resource <EOL> recursive = r . get_vars . get ( "<STR_LIT>" , False ) <EOL> if recursive and recursive . lower ( ) in ( "<STR_LIT:1>" , "<STR_LIT:true>" ) : <EOL> from s3hierarchy import S3Hierarchy <EOL> h = S3Hierarchy ( resource . tablename ) <EOL> if h . config : <EOL> node_ids = None <EOL> pkey = h . pkey <EOL> if str ( pkey ) == str ( resource . _id ) : <EOL> node_ids = [ record_id ] <EOL> else : <EOL> query = ( resource . _id == record_id ) <EOL> row = current . db ( query ) . select ( pkey , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if row : <EOL> node_ids = [ row [ pkey ] ] <EOL> numrows = h . delete ( node_ids ) if node_ids else <NUM_LIT:0> <EOL> if not numrows : <EOL> resource . error = current . T ( "<STR_LIT>" ) <EOL> numrows = <NUM_LIT:0> <EOL> if numrows is None : <EOL> numrows = self . resource . delete ( format = r . representation ) <EOL> if numrows > <NUM_LIT:1> : <EOL> message = "<STR_LIT>" % ( numrows , current . T ( "<STR_LIT>" ) ) <EOL> elif numrows == <NUM_LIT:1> : <EOL> message = self . crud_string ( self . tablename , <EOL> "<STR_LIT>" ) <EOL> else : <EOL> r . error ( <NUM_LIT> , resource . error , next = r . url ( method = "<STR_LIT>" ) ) <EOL> item = current . xml . json_message ( message = message ) <EOL> current . response . view = "<STR_LIT>" <EOL> output . update ( item = item ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_METHOD ) <EOL> return output <EOL> def select ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> resource = self . resource <EOL> tablename = resource . tablename <EOL> get_config = resource . get_config <EOL> list_fields = get_config ( "<STR_LIT>" , None ) <EOL> representation = r . representation <EOL> if representation in ( "<STR_LIT:html>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> hide_filter = self . hide_filter <EOL> filter_widgets = get_config ( "<STR_LIT>" , None ) <EOL> show_filter_form = False <EOL> if filter_widgets and not hide_filter and representation not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> show_filter_form = True <EOL> from s3filter import S3FilterForm <EOL> S3FilterForm . apply_filter_defaults ( r , resource ) <EOL> list_type = attr . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if list_type == "<STR_LIT>" : <EOL> filter_ajax = True <EOL> target = "<STR_LIT>" <EOL> output = self . _datalist ( r , ** attr ) <EOL> else : <EOL> if filter_widgets and not hide_filter : <EOL> dtargs = attr . get ( "<STR_LIT>" , { } ) <EOL> if "<STR_LIT>" not in dtargs : <EOL> dtargs [ "<STR_LIT>" ] = False <EOL> _attr = dict ( attr ) <EOL> _attr [ "<STR_LIT>" ] = dtargs <EOL> else : <EOL> _attr = attr <EOL> filter_ajax = True <EOL> target = "<STR_LIT>" <EOL> output = self . _datatable ( r , ** _attr ) <EOL> if representation in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> return output <EOL> output [ "<STR_LIT>" ] = list_type <EOL> crud_string = self . crud_string <EOL> if representation != "<STR_LIT>" : <EOL> if r . component : <EOL> title = crud_string ( r . tablename , "<STR_LIT>" ) <EOL> else : <EOL> title = crud_string ( self . tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT:title>" ] = title <EOL> if show_filter_form : <EOL> filter_submit_url = attr . get ( "<STR_LIT>" ) <EOL> if not filter_submit_url : <EOL> _vars = self . _remove_filters ( r . get_vars ) <EOL> filter_submit_url = r . url ( vars = _vars ) <EOL> filter_ajax_url = attr . get ( "<STR_LIT>" , <EOL> r . url ( method = "<STR_LIT>" , <EOL> vars = { } , <EOL> representation = "<STR_LIT>" ) ) <EOL> filter_clear = get_config ( "<STR_LIT>" , <EOL> current . deployment_settings . get_ui_filter_clear ( ) ) <EOL> filter_formstyle = get_config ( "<STR_LIT>" , None ) <EOL> filter_submit = get_config ( "<STR_LIT>" , True ) <EOL> filter_form = S3FilterForm ( filter_widgets , <EOL> clear = filter_clear , <EOL> formstyle = filter_formstyle , <EOL> submit = filter_submit , <EOL> ajax = filter_ajax , <EOL> url = filter_submit_url , <EOL> ajaxurl = filter_ajax_url , <EOL> _class = "<STR_LIT>" , <EOL> _id = "<STR_LIT>" % target <EOL> ) <EOL> fresource = current . s3db . resource ( resource . tablename ) <EOL> alias = resource . alias if r . component else None <EOL> output [ "<STR_LIT>" ] = filter_form . html ( fresource , <EOL> r . get_vars , <EOL> target = target , <EOL> alias = alias <EOL> ) <EOL> else : <EOL> output [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> insertable = get_config ( "<STR_LIT>" , True ) <EOL> if insertable : <EOL> addbtn = get_config ( "<STR_LIT>" , False ) <EOL> listadd = get_config ( "<STR_LIT>" , True ) <EOL> if listadd : <EOL> response = current . response <EOL> view = response . view <EOL> s3 = response . s3 <EOL> cancel = s3 . cancel <EOL> s3 . cancel = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> form = self . create ( r , ** attr ) . get ( "<STR_LIT>" , None ) <EOL> if form is not None : <EOL> output [ "<STR_LIT>" ] = form <EOL> addtitle = self . crud_string ( tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = addtitle <EOL> showadd_btn = self . crud_button ( None , <EOL> tablename = tablename , <EOL> name = "<STR_LIT>" , <EOL> icon = "<STR_LIT>" , <EOL> _id = "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = showadd_btn <EOL> response . view = view <EOL> s3 . cancel = cancel <EOL> elif addbtn : <EOL> buttons = self . render_buttons ( r , [ "<STR_LIT>" ] , ** attr ) <EOL> if buttons : <EOL> output [ "<STR_LIT>" ] = buttons <EOL> return output <EOL> elif representation == "<STR_LIT>" : <EOL> if resource . count ( ) == <NUM_LIT:1> : <EOL> resource . load ( ) <EOL> r . record = resource . records ( ) . first ( ) <EOL> if r . record : <EOL> r . id = r . record . id <EOL> self . record_id = self . _record_id ( r ) <EOL> if "<STR_LIT>" in r . get_vars and self . _permitted ( method = "<STR_LIT>" ) : <EOL> items = self . update ( r , ** attr ) . get ( "<STR_LIT>" , None ) <EOL> else : <EOL> items = self . sqlform ( request = self . request , <EOL> resource = self . resource , <EOL> record_id = r . id , <EOL> readonly = True , <EOL> format = representation ) <EOL> else : <EOL> raise HTTP ( <NUM_LIT> , body = "<STR_LIT>" ) <EOL> else : <EOL> rows = resource . select ( list_fields , <EOL> limit = None , <EOL> as_rows = True ) <EOL> if rows : <EOL> items = rows . as_list ( ) <EOL> else : <EOL> items = [ ] <EOL> current . response . view = "<STR_LIT>" <EOL> return dict ( item = items ) <EOL> elif representation == "<STR_LIT>" : <EOL> exporter = S3Exporter ( ) . csv <EOL> return exporter ( resource ) <EOL> elif representation == "<STR_LIT>" : <EOL> get_vars = self . request . get_vars <EOL> start , limit = self . _limits ( get_vars ) <EOL> tooltip = get_vars . get ( "<STR_LIT>" , None ) <EOL> represent = get_vars . get ( "<STR_LIT>" , False ) <EOL> if represent and represent != "<STR_LIT:0>" : <EOL> represent = True <EOL> exporter = S3Exporter ( ) . json <EOL> return exporter ( resource , <EOL> start = start , <EOL> limit = limit , <EOL> represent = represent , <EOL> tooltip = tooltip ) <EOL> elif representation == "<STR_LIT>" : <EOL> report_hide_comments = get_config ( "<STR_LIT>" , None ) <EOL> report_filename = get_config ( "<STR_LIT>" , None ) <EOL> report_formname = get_config ( "<STR_LIT>" , None ) <EOL> exporter = S3Exporter ( ) . pdf <EOL> return exporter ( resource , <EOL> request = r , <EOL> list_fields = list_fields , <EOL> report_hide_comments = report_hide_comments , <EOL> report_filename = report_filename , <EOL> report_formname = report_formname , <EOL> ** attr ) <EOL> elif representation == "<STR_LIT>" : <EOL> exporter = S3Exporter ( ) . shp <EOL> return exporter ( resource , <EOL> list_fields = list_fields , <EOL> ** attr ) <EOL> elif representation == "<STR_LIT>" : <EOL> exporter = S3Exporter ( ) . svg <EOL> return exporter ( resource , <EOL> list_fields = list_fields , <EOL> ** attr ) <EOL> elif representation == "<STR_LIT>" : <EOL> report_groupby = get_config ( "<STR_LIT>" , None ) <EOL> exporter = S3Exporter ( ) . xls <EOL> return exporter ( resource , <EOL> list_fields = list_fields , <EOL> report_groupby = report_groupby , <EOL> ** attr ) <EOL> elif representation == "<STR_LIT>" : <EOL> if r . http == "<STR_LIT:POST>" : <EOL> from s3notify import S3Notifications <EOL> return S3Notifications . send ( r , resource ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_METHOD ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> def _datatable ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> authorised = self . _permitted ( ) <EOL> if not authorised : <EOL> r . unauthorised ( ) <EOL> resource = self . resource <EOL> get_config = resource . get_config <EOL> linkto = get_config ( "<STR_LIT>" , None ) <EOL> list_id = attr . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> list_fields = resource . list_fields ( ) <EOL> orderby = get_config ( "<STR_LIT>" , None ) <EOL> response = current . response <EOL> s3 = response . s3 <EOL> representation = r . representation <EOL> get_vars = self . request . get_vars <EOL> if representation == "<STR_LIT>" : <EOL> start , limit = self . _limits ( get_vars ) <EOL> else : <EOL> start = None <EOL> limit = None if s3 . no_sspag else <NUM_LIT:0> <EOL> output = { } <EOL> if not linkto : <EOL> linkto = self . _linkto ( r ) <EOL> left = [ ] <EOL> distinct = False <EOL> dtargs = attr . get ( "<STR_LIT>" , { } ) <EOL> if r . interactive : <EOL> if s3 . dataTable_pageLength : <EOL> display_length = s3 . dataTable_pageLength <EOL> else : <EOL> display_length = <NUM_LIT> <EOL> if not s3 . no_sspag : <EOL> dt_pagination = "<STR_LIT:true>" <EOL> if not limit : <EOL> limit = <NUM_LIT:2> * display_length <EOL> current . session . s3 . filter = get_vars <EOL> if orderby is None : <EOL> dt_sorting = { "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> if len ( list_fields ) > <NUM_LIT:1> : <EOL> dt_sorting [ "<STR_LIT>" ] = "<STR_LIT:false>" <EOL> dt_sorting [ "<STR_LIT>" ] = "<STR_LIT:1>" <EOL> else : <EOL> dt_sorting [ "<STR_LIT>" ] = "<STR_LIT:true>" <EOL> dt_sorting [ "<STR_LIT>" ] = "<STR_LIT:0>" <EOL> q , orderby , left = resource . datatable_filter ( list_fields , <EOL> dt_sorting ) <EOL> else : <EOL> dt_pagination = "<STR_LIT:false>" <EOL> dt , totalrows , ids = resource . datatable ( fields = list_fields , <EOL> start = start , <EOL> limit = limit , <EOL> left = left , <EOL> orderby = orderby , <EOL> distinct = distinct ) <EOL> displayrows = totalrows <EOL> if not dt . data : <EOL> if r . component and "<STR_LIT>" in output : <EOL> del output [ "<STR_LIT>" ] <EOL> datatable = "<STR_LIT>" <EOL> dtargs [ "<STR_LIT>" ] = dt_pagination <EOL> dtargs [ "<STR_LIT>" ] = display_length <EOL> dtargs [ "<STR_LIT>" ] = r . url ( method = "<STR_LIT>" , vars = { } ) <EOL> dtargs [ "<STR_LIT>" ] = r . url ( ) <EOL> datatable = dt . html ( totalrows , <EOL> displayrows , <EOL> id = list_id , <EOL> ** dtargs ) <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = datatable <EOL> elif representation == "<STR_LIT>" : <EOL> searchq , orderby , left = resource . datatable_filter ( list_fields , <EOL> get_vars ) <EOL> if searchq is not None : <EOL> totalrows = resource . count ( ) <EOL> resource . add_filter ( searchq ) <EOL> else : <EOL> totalrows = None <EOL> if orderby is None : <EOL> orderby = get_config ( "<STR_LIT>" , 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> distinct = distinct , <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>" , <NUM_LIT:0> ) ) <EOL> if dt is not None : <EOL> output = dt . json ( totalrows , <EOL> displayrows , <EOL> list_id , <EOL> draw , <EOL> ** dtargs ) <EOL> else : <EOL> output = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' % ( totalrows , list_id , draw ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> return output <EOL> def _datalist ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> authorised = self . _permitted ( ) <EOL> if not authorised : <EOL> r . unauthorised ( ) <EOL> resource = self . resource <EOL> get_config = resource . get_config <EOL> get_vars = self . request . get_vars <EOL> layout = get_config ( "<STR_LIT>" , None ) <EOL> list_id = get_vars . get ( "<STR_LIT>" , <EOL> attr . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> if hasattr ( layout , "<STR_LIT>" ) : <EOL> list_fields = layout . list_fields <EOL> else : <EOL> list_fields = resource . list_fields ( ) <EOL> orderby = get_config ( "<STR_LIT>" , <EOL> get_config ( "<STR_LIT>" , None ) ) <EOL> if orderby is None : <EOL> if "<STR_LIT>" in resource . fields : <EOL> default_orderby = ~ ( resource . table [ "<STR_LIT>" ] ) <EOL> else : <EOL> for f in list_fields : <EOL> rfield = resource . resolve_selector ( f ) <EOL> if rfield . field and rfield . colname != str ( resource . _id ) : <EOL> default_orderby = rfield . field <EOL> break <EOL> else : <EOL> default_orderby = None <EOL> response = current . response <EOL> s3 = response . s3 <EOL> if "<STR_LIT>" in attr : <EOL> pagelength = attr [ "<STR_LIT>" ] <EOL> elif s3 . dl_pagelength : <EOL> pagelength = s3 . dl_pagelength <EOL> else : <EOL> pagelength = <NUM_LIT:10> <EOL> if "<STR_LIT>" in attr : <EOL> rowsize = attr [ "<STR_LIT>" ] <EOL> elif s3 . dl_rowsize : <EOL> rowsize = s3 . dl_rowsize <EOL> else : <EOL> rowsize = <NUM_LIT:1> <EOL> if pagelength % rowsize : <EOL> pagelength = ( int ( pagelength / rowsize ) + <NUM_LIT:1> ) * rowsize <EOL> record_id = get_vars . get ( "<STR_LIT>" , None ) <EOL> if record_id is not None : <EOL> from s3query import FS <EOL> resource . add_filter ( FS ( "<STR_LIT:id>" ) == record_id ) <EOL> start = <NUM_LIT:0> <EOL> limit = <NUM_LIT:1> <EOL> else : <EOL> start , limit = self . _limits ( get_vars ) <EOL> output = { } <EOL> representation = r . representation <EOL> if representation == "<STR_LIT>" and r . http in ( "<STR_LIT>" , "<STR_LIT:POST>" ) : <EOL> if "<STR_LIT>" in get_vars : <EOL> return { "<STR_LIT>" : self . _dl_ajax_delete ( r , resource ) } <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_METHOD ) <EOL> if representation in ( "<STR_LIT:html>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if limit : <EOL> initial_limit = min ( limit , pagelength ) <EOL> else : <EOL> initial_limit = pagelength <EOL> if not orderby : <EOL> orderby = default_orderby <EOL> datalist , numrows , ids = resource . datalist ( fields = list_fields , <EOL> start = start , <EOL> limit = initial_limit , <EOL> orderby = orderby , <EOL> list_id = list_id , <EOL> layout = layout ) <EOL> if numrows == <NUM_LIT:0> : <EOL> s3 . no_formats = True <EOL> if r . component and "<STR_LIT>" in output : <EOL> del output [ "<STR_LIT>" ] <EOL> ajax_url = attr . get ( "<STR_LIT>" , None ) <EOL> if not ajax_url : <EOL> vars = dict ( ( k , v ) for k , v in r . get_vars . iteritems ( ) <EOL> if k not in ( "<STR_LIT:start>" , "<STR_LIT>" ) ) <EOL> ajax_url = r . url ( representation = "<STR_LIT>" , vars = vars ) <EOL> if representation == "<STR_LIT>" or not limit : <EOL> limit = numrows <EOL> dl = datalist . html ( start = start if start else <NUM_LIT:0> , <EOL> limit = limit , <EOL> pagesize = pagelength , <EOL> rowsize = rowsize , <EOL> ajaxurl = ajax_url ) <EOL> data = dl <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> if representation == "<STR_LIT:html>" : <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = data <EOL> elif representation == "<STR_LIT>" : <EOL> response . view = "<STR_LIT>" <EOL> output [ "<STR_LIT>" ] = data <EOL> elif representation == "<STR_LIT>" : <EOL> response . view = "<STR_LIT>" <EOL> output [ "<STR_LIT>" ] = data <EOL> if s3 . debug : <EOL> appname = current . request . application <EOL> sappend = s3 . scripts . append <EOL> sappend ( "<STR_LIT>" % appname ) <EOL> sappend ( "<STR_LIT>" % appname ) <EOL> sappend ( "<STR_LIT>" % appname ) <EOL> else : <EOL> s3 . scripts . append ( "<STR_LIT>" % current . request . application ) <EOL> return output <EOL> def unapproved ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> session = current . session <EOL> response = current . response <EOL> s3 = response . s3 <EOL> resource = self . resource <EOL> table = self . table <EOL> representation = r . representation <EOL> output = dict ( ) <EOL> _config = self . _config <EOL> orderby = _config ( "<STR_LIT>" , None ) <EOL> linkto = _config ( "<STR_LIT>" , None ) <EOL> list_fields = _config ( "<STR_LIT>" ) <EOL> list_id = "<STR_LIT>" <EOL> authorised = self . _permitted ( ) <EOL> if not authorised : <EOL> r . unauthorised ( ) <EOL> get_vars = self . request . get_vars <EOL> if representation == "<STR_LIT>" : <EOL> start , limit = self . _limits ( get_vars ) <EOL> else : <EOL> start = None <EOL> limit = None if s3 . no_sspag else <NUM_LIT:0> <EOL> if not linkto : <EOL> linkto = self . _linkto ( r ) <EOL> if not list_fields : <EOL> fields = resource . readable_fields ( ) <EOL> list_fields = [ f . name for f in fields ] <EOL> else : <EOL> fields = [ table [ f ] for f in list_fields if f in table . fields ] <EOL> if not fields : <EOL> fields = [ ] <EOL> if not fields or fields [ <NUM_LIT:0> ] . name != table . fields [ <NUM_LIT:0> ] : <EOL> fields . insert ( <NUM_LIT:0> , table [ table . fields [ <NUM_LIT:0> ] ] ) <EOL> if list_fields [ <NUM_LIT:0> ] != table . fields [ <NUM_LIT:0> ] : <EOL> list_fields . insert ( <NUM_LIT:0> , table . fields [ <NUM_LIT:0> ] ) <EOL> left = [ ] <EOL> distinct = False <EOL> if r . interactive : <EOL> resource . build_query ( filter = s3 . filter ) <EOL> response . view = self . _view ( r , "<STR_LIT>" ) <EOL> crud_string = self . crud_string <EOL> if r . component : <EOL> title = crud_string ( r . tablename , "<STR_LIT>" ) <EOL> else : <EOL> title = crud_string ( self . tablename , "<STR_LIT>" ) <EOL> output [ "<STR_LIT:title>" ] = title <EOL> if s3 . dataTable_pageLength : <EOL> display_length = s3 . dataTable_pageLength <EOL> else : <EOL> display_length = <NUM_LIT> <EOL> if not s3 . no_sspag : <EOL> dt_pagination = "<STR_LIT:true>" <EOL> if not limit : <EOL> limit = <NUM_LIT:2> * display_length <EOL> session . s3 . filter = get_vars <EOL> if orderby is None : <EOL> scol = len ( list_fields ) > <NUM_LIT:1> and "<STR_LIT:1>" or "<STR_LIT:0>" <EOL> get_vars . update ( iSortingCols = "<STR_LIT:1>" , <EOL> iSortCol_0 = scol , <EOL> sSortDir_0 = "<STR_LIT>" ) <EOL> q , orderby , left = resource . datatable_filter ( list_fields , <EOL> get_vars ) <EOL> del get_vars [ "<STR_LIT>" ] <EOL> del get_vars [ "<STR_LIT>" ] <EOL> del get_vars [ "<STR_LIT>" ] <EOL> else : <EOL> dt_pagination = "<STR_LIT:false>" <EOL> dt , totalrows , ids = resource . datatable ( fields = list_fields , <EOL> start = start , <EOL> limit = limit , <EOL> left = left , <EOL> orderby = orderby , <EOL> distinct = distinct ) <EOL> displayrows = totalrows <EOL> if dt is None : <EOL> s3 . no_formats = True <EOL> datatable = current . T ( "<STR_LIT>" ) <EOL> else : <EOL> dt_dom = s3 . get ( "<STR_LIT>" , <EOL> current . deployment_settings . get_ui_datatables_dom ( ) ) <EOL> datatable = dt . html ( totalrows , displayrows , list_id , <EOL> dt_pagination = dt_pagination , <EOL> dt_pageLength = display_length , <EOL> dt_dom = dt_dom , <EOL> ) <EOL> s3 . actions = [ { "<STR_LIT:label>" : str ( current . T ( "<STR_LIT>" ) ) , <EOL> "<STR_LIT:url>" : r . url ( id = "<STR_LIT>" , method = "<STR_LIT>" ) , <EOL> "<STR_LIT>" : "<STR_LIT>" } ] <EOL> output [ "<STR_LIT>" ] = datatable <EOL> elif r . representation == "<STR_LIT>" : <EOL> resource . build_query ( filter = s3 . filter , vars = session . s3 . filter ) <EOL> searchq , orderby , left = resource . datatable_filter ( list_fields , get_vars ) <EOL> if searchq is not None : <EOL> totalrows = resource . count ( ) <EOL> resource . add_filter ( searchq ) <EOL> else : <EOL> totalrows = None <EOL> if orderby is None : <EOL> orderby = _config ( "<STR_LIT>" , 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> distinct = distinct ) <EOL> else : <EOL> dt , displayrows = None , <NUM_LIT:0> <EOL> if totalrows is None : <EOL> totalrows = displayrows <EOL> draw = int ( get_vars . draw or <NUM_LIT:0> ) <EOL> if dt is not None : <EOL> output = dt . json ( totalrows , <EOL> displayrows , <EOL> list_id , <EOL> draw ) <EOL> else : <EOL> output = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' % ( totalrows , list_id , draw ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> return output <EOL> def review ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> if not self . _permitted ( "<STR_LIT>" ) : <EOL> r . unauthorized ( ) <EOL> T = current . T <EOL> session = current . session <EOL> response = current . response <EOL> output = Storage ( ) <EOL> if r . interactive : <EOL> _next = r . url ( id = "<STR_LIT>" , method = "<STR_LIT>" ) <EOL> if self . _permitted ( "<STR_LIT>" ) : <EOL> approve = FORM ( INPUT ( _value = T ( "<STR_LIT>" ) , <EOL> _type = "<STR_LIT>" , <EOL> _name = "<STR_LIT>" , <EOL> _id = "<STR_LIT>" , <EOL> _class = "<STR_LIT>" ) ) <EOL> reject = FORM ( INPUT ( _value = T ( "<STR_LIT>" ) , <EOL> _type = "<STR_LIT>" , <EOL> _name = "<STR_LIT>" , <EOL> _id = "<STR_LIT>" , <EOL> _class = "<STR_LIT>" ) ) <EOL> edit = A ( T ( "<STR_LIT>" ) , <EOL> _href = r . url ( id = r . id , method = "<STR_LIT>" , <EOL> vars = { "<STR_LIT>" : r . url ( id = r . id , method = "<STR_LIT>" ) } ) , <EOL> _class = "<STR_LIT>" ) <EOL> cancel = A ( T ( "<STR_LIT>" ) , <EOL> _href = r . url ( id = <NUM_LIT:0> ) , <EOL> _class = "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = DIV ( TABLE ( TR ( approve , reject , edit , cancel ) ) , <EOL> _id = "<STR_LIT>" ) <EOL> reviewing = False <EOL> if approve . accepts ( r . post_vars , session , formname = "<STR_LIT>" ) : <EOL> resource = current . s3db . resource ( r . tablename , r . id , <EOL> approved = False , <EOL> unapproved = True ) <EOL> try : <EOL> success = resource . approve ( ) <EOL> except : <EOL> success = False <EOL> if success : <EOL> response . confirmation = T ( "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> else : <EOL> response . warning = T ( "<STR_LIT>" ) <EOL> r . http = "<STR_LIT:GET>" <EOL> _next = r . url ( id = <NUM_LIT:0> , method = "<STR_LIT>" ) <EOL> elif reject . accepts ( r . post_vars , session , formname = "<STR_LIT>" ) : <EOL> resource = current . s3db . resource ( r . tablename , r . id , <EOL> approved = False , <EOL> unapproved = True ) <EOL> try : <EOL> success = resource . reject ( ) <EOL> except : <EOL> success = False <EOL> if success : <EOL> response . confirmation = T ( "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> else : <EOL> response . warning = T ( "<STR_LIT>" ) <EOL> r . http = "<STR_LIT:GET>" <EOL> _next = r . url ( id = <NUM_LIT:0> , method = "<STR_LIT>" ) <EOL> else : <EOL> reviewing = True <EOL> if reviewing : <EOL> output . update ( self . read ( r , ** attr ) ) <EOL> self . next = _next <EOL> r . http = r . env . request_method <EOL> current . response . view = "<STR_LIT>" <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> return output <EOL> def validate ( self , r , ** attr ) : <EOL> """<STR_LIT>""" <EOL> if r . representation != "<STR_LIT>" : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_FORMAT ) <EOL> resource = self . resource <EOL> get_vars = r . get_vars <EOL> if "<STR_LIT>" in get_vars : <EOL> alias = get_vars [ "<STR_LIT>" ] <EOL> else : <EOL> alias = None <EOL> if "<STR_LIT>" in get_vars : <EOL> tablename = get_vars [ "<STR_LIT>" ] <EOL> customise = current . deployment_settings . customise_resource ( tablename ) <EOL> if customise : <EOL> customise ( r , tablename ) <EOL> components = [ alias ] if alias else None <EOL> try : <EOL> resource = current . s3db . resource ( tablename , <EOL> components = components ) <EOL> except : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_RESOURCE ) <EOL> if alias : <EOL> if alias in resource . components : <EOL> component = resource . components [ alias ] <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_RESOURCE ) <EOL> else : <EOL> component = resource <EOL> source = r . body <EOL> source . seek ( <NUM_LIT:0> ) <EOL> try : <EOL> data = json . load ( source ) <EOL> except ValueError : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_SOURCE ) <EOL> if not isinstance ( data , list ) : <EOL> single = True <EOL> data = [ data ] <EOL> else : <EOL> single = False <EOL> table = component . table <EOL> pkey = table . _id . name <EOL> get_config = current . s3db . get_config <EOL> tablename = component . tablename <EOL> onvalidation = get_config ( tablename , "<STR_LIT>" ) <EOL> update_onvalidation = get_config ( tablename , "<STR_LIT>" , <EOL> onvalidation ) <EOL> create_onvalidation = get_config ( tablename , "<STR_LIT>" , <EOL> onvalidation ) <EOL> output = [ ] <EOL> for record in data : <EOL> has_errors = False <EOL> if pkey in record : <EOL> original = { pkey : record [ pkey ] } <EOL> elif "<STR_LIT>" in record : <EOL> original = { pkey : record [ "<STR_LIT>" ] } <EOL> else : <EOL> original = None <EOL> fields = Storage ( ) <EOL> for fname in record : <EOL> error = None <EOL> validated = fields [ fname ] = Storage ( ) <EOL> if fname in ( pkey , "<STR_LIT>" ) : <EOL> continue <EOL> value = record [ fname ] <EOL> if fname not in table . fields : <EOL> validated [ "<STR_LIT:value>" ] = value <EOL> validated [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> continue <EOL> else : <EOL> field = table [ fname ] <EOL> field = table [ fname ] <EOL> if field . type == "<STR_LIT>" : <EOL> if value not in ( None , "<STR_LIT>" ) : <EOL> try : <EOL> value = int ( value ) <EOL> except ValueError : <EOL> value = <NUM_LIT:0> <EOL> else : <EOL> value = None <EOL> if field . type == "<STR_LIT>" : <EOL> if value not in ( None , "<STR_LIT>" ) : <EOL> try : <EOL> value = float ( value ) <EOL> except ValueError : <EOL> value = <NUM_LIT:0> <EOL> else : <EOL> value = None <EOL> widget = field . widget <EOL> if isinstance ( widget , S3Selector ) : <EOL> value , error = widget . validate ( value , <EOL> requires = field . requires , <EOL> ) <EOL> validated [ "<STR_LIT:value>" ] = widget . serialize ( value ) <EOL> widget_represent = widget . represent <EOL> else : <EOL> try : <EOL> value , error = s3_validate ( table , fname , value , original ) <EOL> except AttributeError : <EOL> error = "<STR_LIT>" <EOL> validated [ "<STR_LIT:value>" ] = field . formatter ( value ) <EOL> widget_represent = None <EOL> if error : <EOL> has_errors = True <EOL> validated [ "<STR_LIT>" ] = s3_unicode ( error ) <EOL> elif widget_represent : <EOL> try : <EOL> text = widget_represent ( value ) <EOL> except : <EOL> text = s3_unicode ( value ) <EOL> validated [ "<STR_LIT:text>" ] = text <EOL> else : <EOL> try : <EOL> text = s3_represent_value ( field , value = value ) <EOL> except : <EOL> text = s3_unicode ( value ) <EOL> validated [ "<STR_LIT:text>" ] = text <EOL> if not has_errors : <EOL> if original is not None : <EOL> onvalidation = update_onvalidation <EOL> else : <EOL> onvalidation = create_onvalidation <EOL> form = Storage ( vars = Storage ( record ) , errors = Storage ( ) ) <EOL> if onvalidation is not None : <EOL> callback ( onvalidation , form , tablename = tablename ) <EOL> for fn in form . errors : <EOL> msg = s3_unicode ( form . errors [ fn ] ) <EOL> if fn in fields : <EOL> validated = fields [ fn ] <EOL> has_errors = True <EOL> validated . _error = msg <EOL> if "<STR_LIT:text>" in validated : <EOL> del validated [ "<STR_LIT:text>" ] <EOL> else : <EOL> msg = "<STR_LIT>" % ( fn , msg ) <EOL> if "<STR_LIT>" in fields : <EOL> fields [ "<STR_LIT>" ] = "<STR_LIT:\n>" . join ( [ msg , <EOL> fields [ "<STR_LIT>" ] ] ) <EOL> else : <EOL> fields [ "<STR_LIT>" ] = msg <EOL> output . append ( fields ) <EOL> if single and len ( output ) == <NUM_LIT:1> : <EOL> output = output [ <NUM_LIT:0> ] <EOL> return json . dumps ( output , separators = SEPARATORS ) <EOL> @ staticmethod <EOL> def crud_button ( label = None , <EOL> tablename = None , <EOL> name = None , <EOL> icon = None , <EOL> _href = None , <EOL> _id = None , <EOL> _class = None , <EOL> _title = None , <EOL> _target = None , <EOL> ** attr ) : <EOL> """<STR_LIT>""" <EOL> settings = current . deployment_settings <EOL> bootstrap = settings . ui . formstyle == "<STR_LIT>" <EOL> if "<STR_LIT>" in attr : <EOL> custom = attr [ "<STR_LIT>" ] <EOL> if custom is None : <EOL> custom = "<STR_LIT>" <EOL> elif bootstrap and hasattr ( custom , "<STR_LIT>" ) : <EOL> custom . add_class ( "<STR_LIT>" ) <EOL> return custom <EOL> if _class is None and not bootstrap : <EOL> _class = "<STR_LIT>" <EOL> if name : <EOL> labelstr = S3CRUD . crud_string ( tablename , name ) <EOL> else : <EOL> labelstr = str ( label ) <EOL> if icon and settings . get_ui_use_button_icons ( ) : <EOL> button = A ( ICON ( icon ) , labelstr , _id = _id , _class = _class ) <EOL> else : <EOL> button = A ( labelstr , _id = _id , _class = _class ) <EOL> if _href : <EOL> button [ "<STR_LIT>" ] = _href <EOL> if _title : <EOL> button [ "<STR_LIT>" ] = _title <EOL> if _target : <EOL> button [ "<STR_LIT>" ] = _target <EOL> if bootstrap : <EOL> button . add_class ( "<STR_LIT>" ) <EOL> return button <EOL> def last_update ( self ) : <EOL> """<STR_LIT>""" <EOL> output = { } <EOL> record_id = self . record_id <EOL> if record_id : <EOL> record = None <EOL> fields = [ ] <EOL> table = self . table <EOL> if "<STR_LIT>" in table . fields : <EOL> fields . append ( table . modified_on ) <EOL> if "<STR_LIT>" in table . fields : <EOL> fields . append ( table . modified_by ) <EOL> if fields : <EOL> query = ( table . _id == record_id ) <EOL> record = current . db ( query ) . select ( limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> * fields ) . first ( ) <EOL> if record : <EOL> T = current . T <EOL> if "<STR_LIT>" in record : <EOL> if not record . modified_by : <EOL> modified_by = T ( "<STR_LIT>" ) <EOL> else : <EOL> modified_by = table . modified_by . represent ( record . modified_by ) <EOL> output [ "<STR_LIT>" ] = T ( "<STR_LIT>" ) % { "<STR_LIT>" : modified_by } <EOL> if "<STR_LIT>" in record : <EOL> modified_on = S3DateTime . datetime_represent ( record . modified_on , <EOL> utc = True , <EOL> ) <EOL> output [ "<STR_LIT>" ] = T ( "<STR_LIT>" ) % { "<STR_LIT:date>" : modified_on } <EOL> return output <EOL> def render_buttons ( self , r , buttons , record_id = None , ** attr ) : <EOL> """<STR_LIT>""" <EOL> output = { } <EOL> custom_crud_buttons = attr . get ( "<STR_LIT>" , { } ) <EOL> tablename = self . tablename <EOL> representation = r . representation <EOL> url = r . url <EOL> remove_filters = self . _remove_filters <EOL> crud_string = self . crud_string <EOL> config = self . _config <EOL> crud_button = self . crud_button <EOL> if "<STR_LIT>" in buttons and config ( "<STR_LIT>" , True ) : <EOL> ADD_BTN = "<STR_LIT>" <EOL> authorised = self . _permitted ( method = "<STR_LIT>" ) <EOL> if authorised : <EOL> if ADD_BTN in custom_crud_buttons : <EOL> btn = crud_button ( custom = custom_crud_buttons [ ADD_BTN ] ) <EOL> else : <EOL> label = crud_string ( tablename , "<STR_LIT>" ) <EOL> _href = url ( method = "<STR_LIT>" , <EOL> representation = representation ) <EOL> btn = crud_button ( label = label , <EOL> icon = "<STR_LIT>" , <EOL> _href = _href , <EOL> _id = "<STR_LIT>" ) <EOL> output [ ADD_BTN ] = btn <EOL> if "<STR_LIT:list>" in buttons : <EOL> LIST_BTN = "<STR_LIT>" <EOL> if not r . component or r . component . multiple : <EOL> if LIST_BTN in custom_crud_buttons : <EOL> btn = crud_button ( custom = custom_crud_buttons [ LIST_BTN ] ) <EOL> else : <EOL> label = crud_string ( tablename , "<STR_LIT>" ) <EOL> _href = url ( method = "<STR_LIT>" , <EOL> id = r . id if r . component else <NUM_LIT:0> , <EOL> vars = remove_filters ( r . get_vars ) , <EOL> representation = representation ) <EOL> btn = crud_button ( label = label , <EOL> icon = "<STR_LIT:list>" , <EOL> _href = _href , <EOL> _id = "<STR_LIT>" ) <EOL> output [ LIST_BTN ] = btn <EOL> if "<STR_LIT>" in buttons : <EOL> SUMMARY_BTN = "<STR_LIT>" <EOL> if not r . component or r . component . multiple : <EOL> if SUMMARY_BTN in custom_crud_buttons : <EOL> btn = crud_button ( custom = custom_crud_buttons [ SUMMARY_BTN ] ) <EOL> else : <EOL> label = crud_string ( tablename , "<STR_LIT>" ) <EOL> _href = url ( method = "<STR_LIT>" , <EOL> id = <NUM_LIT:0> , <EOL> vars = remove_filters ( r . get_vars ) , <EOL> representation = representation ) <EOL> btn = crud_button ( label = label , <EOL> icon = "<STR_LIT:list>" , <EOL> _href = _href , <EOL> _id = "<STR_LIT>" ) <EOL> output [ SUMMARY_BTN ] = btn <EOL> if not record_id : <EOL> return output <EOL> if "<STR_LIT>" in buttons and config ( "<STR_LIT>" , True ) : <EOL> EDIT_BTN = "<STR_LIT>" <EOL> authorised = self . _permitted ( method = "<STR_LIT>" ) <EOL> if authorised : <EOL> if EDIT_BTN in custom_crud_buttons : <EOL> btn = crud_button ( custom = custom_crud_buttons [ EDIT_BTN ] ) <EOL> else : <EOL> label = current . messages . UPDATE <EOL> _href = url ( method = "<STR_LIT>" , <EOL> representation = representation ) <EOL> btn = crud_button ( label = label , <EOL> icon = "<STR_LIT>" , <EOL> _href = _href , <EOL> _id = "<STR_LIT>" ) <EOL> output [ EDIT_BTN ] = btn <EOL> if "<STR_LIT>" in buttons and config ( "<STR_LIT>" , True ) : <EOL> DELETE_BTN = "<STR_LIT>" <EOL> authorised = self . _permitted ( method = "<STR_LIT>" ) <EOL> if authorised : <EOL> if DELETE_BTN in custom_crud_buttons : <EOL> btn = crud_button ( custom = custom_crud_buttons [ DELETE_BTN ] ) <EOL> else : <EOL> label = crud_string ( tablename , "<STR_LIT>" ) <EOL> _href = url ( method = "<STR_LIT>" , <EOL> representation = representation ) <EOL> btn = crud_button ( label = label , <EOL> icon = "<STR_LIT>" , <EOL> _href = _href , <EOL> _id = "<STR_LIT>" , <EOL> _class = "<STR_LIT>" ) <EOL> output [ DELETE_BTN ] = btn <EOL> return output <EOL> @ staticmethod <EOL> def action_button ( label , url , icon = None , ** attr ) : <EOL> """<STR_LIT>""" <EOL> link = dict ( attr ) <EOL> link [ "<STR_LIT:label>" ] = str ( label ) <EOL> link [ "<STR_LIT:url>" ] = url <EOL> if icon and current . deployment_settings . get_ui_use_button_icons ( ) : <EOL> link [ "<STR_LIT>" ] = ICON . css_class ( icon ) <EOL> if "<STR_LIT>" not in link : <EOL> link [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> s3 = current . response . s3 <EOL> if s3 . actions is None : <EOL> s3 . actions = [ link ] <EOL> else : <EOL> s3 . actions . append ( link ) <EOL> @ staticmethod <EOL> def action_buttons ( r , <EOL> deletable = True , <EOL> editable = True , <EOL> copyable = False , <EOL> read_url = None , <EOL> delete_url = None , <EOL> update_url = None , <EOL> copy_url = None ) : <EOL> """<STR_LIT>""" <EOL> s3crud = S3CRUD <EOL> s3 = current . response . s3 <EOL> labels = s3 . crud_labels <EOL> custom_actions = s3 . actions <EOL> s3 . actions = None <EOL> auth = current . auth <EOL> has_permission = auth . s3_has_permission <EOL> ownership_required = auth . permission . ownership_required <EOL> if r . component : <EOL> table = r . component . table <EOL> args = [ r . id , r . component . alias , "<STR_LIT>" ] <EOL> else : <EOL> table = r . table <EOL> args = [ "<STR_LIT>" ] <EOL> get_vars = Storage ( ) <EOL> if "<STR_LIT>" in r . get_vars : <EOL> get_vars [ "<STR_LIT>" ] = r . get_vars [ "<STR_LIT>" ] <EOL> if r . representation == "<STR_LIT>" : <EOL> if current . deployment_settings . get_ui_iframe_opens_full ( ) : <EOL> iframe_safe = lambda url : url <EOL> target = dict ( _target = "<STR_LIT>" ) <EOL> else : <EOL> iframe_safe = lambda url : s3_set_extension ( url , "<STR_LIT>" ) <EOL> target = { } <EOL> else : <EOL> iframe_safe = lambda url : url <EOL> target = { } <EOL> if editable and has_permission ( "<STR_LIT>" , table ) and not ownership_required ( "<STR_LIT>" , table ) : <EOL> if not update_url : <EOL> update_url = iframe_safe ( URL ( args = args + [ "<STR_LIT>" ] , <EOL> vars = get_vars ) ) <EOL> s3crud . action_button ( labels . UPDATE , update_url , <EOL> _class = "<STR_LIT>" , <EOL> icon = "<STR_LIT>" , <EOL> ** target <EOL> ) <EOL> else : <EOL> if not read_url : <EOL> read_url = iframe_safe ( URL ( args = args , <EOL> vars = get_vars ) ) <EOL> s3crud . action_button ( labels . READ , read_url , <EOL> _class = "<STR_LIT>" , <EOL> icon = "<STR_LIT:file>" , <EOL> ** target <EOL> ) <EOL> if deletable and has_permission ( "<STR_LIT>" , table ) : <EOL> icon = "<STR_LIT>" <EOL> if not delete_url : <EOL> delete_url = iframe_safe ( URL ( args = args + [ "<STR_LIT>" ] , <EOL> vars = get_vars ) ) <EOL> if ownership_required ( "<STR_LIT>" , table ) : <EOL> query = auth . s3_accessible_query ( "<STR_LIT>" , table ) <EOL> rows = current . db ( query ) . select ( table . _id ) <EOL> restrict = [ ] <EOL> rappend = restrict . append <EOL> for row in rows : <EOL> row_id = row . get ( "<STR_LIT:id>" , None ) <EOL> if row_id : <EOL> rappend ( str ( row_id ) ) <EOL> s3crud . action_button ( labels . DELETE , delete_url , <EOL> _class = "<STR_LIT>" , <EOL> icon = icon , <EOL> restrict = restrict , <EOL> ** target <EOL> ) <EOL> else : <EOL> s3crud . action_button ( labels . DELETE , delete_url , <EOL> _class = "<STR_LIT>" , <EOL> icon = icon , <EOL> ** target <EOL> ) <EOL> if copyable and has_permission ( "<STR_LIT>" , table ) : <EOL> if not copy_url : <EOL> copy_url = iframe_safe ( URL ( args = args + [ "<STR_LIT>" ] ) ) <EOL> s3crud . action_button ( labels . COPY , <EOL> copy_url , <EOL> icon = "<STR_LIT>" , <EOL> ** target <EOL> ) <EOL> if custom_actions : <EOL> s3 . actions = s3 . actions + custom_actions <EOL> return <EOL> def _default_cancel_button ( self , r ) : <EOL> """<STR_LIT>""" <EOL> if r . representation != "<STR_LIT:html>" : <EOL> return False <EOL> s3 = current . response . s3 <EOL> cancel = s3 . cancel <EOL> if cancel is False or isinstance ( cancel , dict ) : <EOL> success = False <EOL> elif cancel is True or current . deployment_settings . get_ui_default_cancel_button ( ) : <EOL> if isinstance ( cancel , basestring ) : <EOL> default_url = cancel <EOL> else : <EOL> method = r . method <EOL> if method == "<STR_LIT>" : <EOL> if r . component : <EOL> default_url = r . url ( method = "<STR_LIT>" , <EOL> component_id = "<STR_LIT>" , <EOL> vars = { } , <EOL> ) <EOL> else : <EOL> config = self . _config ( "<STR_LIT>" ) <EOL> if config or current . deployment_settings . get_ui_summary ( ) : <EOL> default_url = r . url ( method = "<STR_LIT>" , id = <NUM_LIT:0> ) <EOL> else : <EOL> default_url = r . url ( method = "<STR_LIT>" , id = <NUM_LIT:0> ) <EOL> elif method == "<STR_LIT>" or not method : <EOL> if r . component : <EOL> default_url = r . url ( method = "<STR_LIT>" , <EOL> component_id = "<STR_LIT>" , <EOL> vars = { } , <EOL> ) <EOL> else : <EOL> default_url = r . url ( method = "<STR_LIT>" ) <EOL> if default_url : <EOL> script = '''<STR_LIT>''' % default_url <EOL> else : <EOL> script = '''<STR_LIT>''' <EOL> jquery_ready = current . response . s3 . jquery_ready <EOL> if script not in jquery_ready : <EOL> jquery_ready . append ( script ) <EOL> success = s3 . cancel = True <EOL> else : <EOL> success = False <EOL> return success <EOL> def import_csv ( self , file , table = None ) : <EOL> """<STR_LIT>""" <EOL> if table : <EOL> table . import_from_csv_file ( file ) <EOL> else : <EOL> db = current . db <EOL> db . import_from_csv_file ( file ) <EOL> db . commit ( ) <EOL> @ staticmethod <EOL> def import_url ( r ) : <EOL> """<STR_LIT>""" <EOL> xml = current . xml <EOL> prefix , name , table , tablename = r . target ( ) <EOL> record = r . record <EOL> resource = r . resource <EOL> if record and r . component : <EOL> resource = resource . components [ r . component_name ] <EOL> resource . load ( ) <EOL> if len ( resource ) == <NUM_LIT:1> : <EOL> record = resource . records ( ) [ <NUM_LIT:0> ] <EOL> else : <EOL> record = None <EOL> r . vars . update ( { resource . fkey : r . record [ resource . pkey ] } ) <EOL> elif not record and r . component : <EOL> item = xml . json_message ( False , <NUM_LIT> , "<STR_LIT>" ) <EOL> return dict ( item = item ) <EOL> if record and xml . UID in table . fields : <EOL> r . vars . update ( { xml . UID : xml . export_uid ( record [ xml . UID ] ) } ) <EOL> element = etree . Element ( xml . TAG . resource ) <EOL> element . set ( xml . ATTRIBUTE . name , resource . tablename ) <EOL> for var in r . vars : <EOL> if var . find ( "<STR_LIT:.>" ) != - <NUM_LIT:1> : <EOL> continue <EOL> elif var in table . fields : <EOL> field = table [ var ] <EOL> value = str ( r . vars [ var ] ) . decode ( "<STR_LIT:utf-8>" ) <EOL> if var in xml . FIELDS_TO_ATTRIBUTES : <EOL> element . set ( var , value ) <EOL> else : <EOL> data = etree . Element ( xml . TAG . data ) <EOL> data . set ( xml . ATTRIBUTE . field , var ) <EOL> if field . type == "<STR_LIT>" : <EOL> data . set ( xml . ATTRIBUTE . filename , value ) <EOL> else : <EOL> data . text = value <EOL> element . append ( data ) <EOL> tree = xml . tree ( [ element ] , domain = xml . domain ) <EOL> result = Storage ( committed = False ) <EOL> def log ( item ) : <EOL> result [ "<STR_LIT>" ] = item <EOL> resource . configure ( oncommit_import_item = log ) <EOL> try : <EOL> success = resource . import_xml ( tree ) <EOL> except SyntaxError : <EOL> pass <EOL> if result . item : <EOL> result = result . item <EOL> if success and result . committed : <EOL> r . id = result . id <EOL> method = result . method <EOL> if method == result . METHOD . CREATE : <EOL> item = xml . json_message ( True , <NUM_LIT> , "<STR_LIT>" % <EOL> ( str ( r . url ( method = "<STR_LIT>" , <EOL> representation = "<STR_LIT:html>" , <EOL> vars = dict ( ) , <EOL> ) <EOL> ) , <EOL> r . name , result . id ) <EOL> ) <EOL> else : <EOL> item = xml . json_message ( True , <NUM_LIT:200> , "<STR_LIT>" ) <EOL> else : <EOL> item = xml . json_message ( False , <NUM_LIT> , <EOL> "<STR_LIT>" % <EOL> resource . error or xml . error , <EOL> tree = xml . tree2json ( tree ) ) <EOL> return dict ( item = item ) <EOL> def _embed_component ( self , resource , record = None ) : <EOL> """<STR_LIT>""" <EOL> link = None <EOL> component = resource . linked <EOL> if component is not None and component . actuate == "<STR_LIT>" : <EOL> ctablename = component . tablename <EOL> attr = { "<STR_LIT>" : resource . tablename , <EOL> "<STR_LIT>" : ctablename , <EOL> } <EOL> autocomplete = component . autocomplete <EOL> if autocomplete and autocomplete in component . table : <EOL> attr [ "<STR_LIT>" ] = autocomplete <EOL> if record is not None : <EOL> attr [ "<STR_LIT>" ] = "<STR_LIT>" % ( <EOL> resource . tablename , <EOL> component . lkey , <EOL> record , <EOL> component . rkey , <EOL> component . fkey ) <EOL> rkey = component . rkey <EOL> if rkey in resource . table : <EOL> field = resource . table [ rkey ] <EOL> field . widget = S3EmbeddedComponentWidget ( ** attr ) <EOL> field . comment = None <EOL> callback = self . _postprocess_embedded <EOL> postprocess = lambda form , key = rkey , component = ctablename : callback ( form , key = key , component = component ) <EOL> link = Storage ( postprocess = postprocess ) <EOL> return link <EOL> def _postprocess_embedded ( self , form , <EOL> component = None , <EOL> key = None ) : <EOL> """<STR_LIT>""" <EOL> s3db = current . s3db <EOL> request = current . request <EOL> get_config = lambda key , tablename = component : s3db . get_config ( tablename , key , None ) <EOL> try : <EOL> selected = form . vars [ key ] <EOL> except : <EOL> selected = None <EOL> if request . env . request_method == "<STR_LIT:POST>" : <EOL> db = current . db <EOL> table = db [ component ] <EOL> post_vars = request . post_vars <EOL> form_vars = Storage ( table . _filter_fields ( post_vars ) ) <EOL> for k in form_vars : <EOL> value , error = s3_validate ( table , k , form_vars [ k ] ) <EOL> if not error : <EOL> form_vars [ k ] = value <EOL> _form = Storage ( vars = form_vars , errors = Storage ( ) ) <EOL> if _form . vars : <EOL> if selected : <EOL> form_vars [ table . _id . name ] = selected <EOL> onvalidation = get_config ( "<STR_LIT>" ) or get_config ( "<STR_LIT>" ) <EOL> callback ( onvalidation , _form , tablename = component ) <EOL> if not _form . errors : <EOL> db ( table . _id == selected ) . update ( ** _form . vars ) <EOL> else : <EOL> form . errors . update ( _form . errors ) <EOL> return <EOL> s3db . update_super ( table , dict ( id = selected ) ) <EOL> update_realm = s3db . get_config ( table , "<STR_LIT>" ) <EOL> if update_realm : <EOL> current . auth . set_realm_entity ( table , selected , <EOL> force_update = True ) <EOL> onaccept = get_config ( "<STR_LIT>" ) or get_config ( "<STR_LIT>" ) <EOL> callback ( onaccept , _form , tablename = component ) <EOL> else : <EOL> form_vars . pop ( table . _id . name , None ) <EOL> onvalidation = get_config ( "<STR_LIT>" ) or get_config ( "<STR_LIT>" ) <EOL> callback ( onvalidation , _form , tablename = component ) <EOL> if not _form . errors : <EOL> selected = table . insert ( ** _form . vars ) <EOL> else : <EOL> form . errors . update ( _form . errors ) <EOL> return <EOL> if selected : <EOL> post_vars [ key ] = str ( selected ) <EOL> form . request_vars [ key ] = str ( selected ) <EOL> form . vars [ key ] = selected <EOL> s3db . update_super ( table , dict ( id = selected ) ) <EOL> auth = current . auth <EOL> auth . s3_set_record_owner ( table , selected ) <EOL> auth . s3_make_session_owner ( table , selected ) <EOL> onaccept = get_config ( "<STR_LIT>" ) or get_config ( "<STR_LIT>" ) <EOL> callback ( onaccept , _form , tablename = component ) <EOL> else : <EOL> form . errors [ key ] = current . T ( "<STR_LIT>" ) <EOL> return <EOL> def _linkto ( self , r , authorised = None , update = None , native = False ) : <EOL> """<STR_LIT>""" <EOL> c = None <EOL> f = None <EOL> s3db = current . s3db <EOL> prefix , name , table , tablename = r . target ( ) <EOL> permit = current . auth . s3_has_permission <EOL> if authorised is None : <EOL> authorised = permit ( "<STR_LIT>" , tablename ) <EOL> if authorised and update : <EOL> linkto = s3db . get_config ( tablename , "<STR_LIT>" , None ) <EOL> else : <EOL> linkto = s3db . get_config ( tablename , "<STR_LIT>" , None ) <EOL> if r . component and native : <EOL> c = prefix <EOL> f = name <EOL> if r . representation == "<STR_LIT>" : <EOL> if current . deployment_settings . get_ui_iframe_opens_full ( ) : <EOL> iframe_safe = lambda url : s3_set_extension ( url , "<STR_LIT:html>" ) <EOL> else : <EOL> iframe_safe = lambda url : s3_set_extension ( url , "<STR_LIT>" ) <EOL> else : <EOL> iframe_safe = False <EOL> def list_linkto ( record_id , r = r , c = c , f = f , <EOL> linkto = linkto , <EOL> update = authorised and update ) : <EOL> if linkto : <EOL> try : <EOL> url = str ( linkto ( record_id ) ) <EOL> except TypeError : <EOL> url = linkto % record_id <EOL> else : <EOL> if r . component : <EOL> if r . link and not r . actuate_link ( ) : <EOL> if str ( record_id ) . isdigit ( ) : <EOL> _id = r . link . table . _id <EOL> _id . represent = lambda opt , link = r . link , master = r . id : link . component_id ( master , opt ) <EOL> record_id = r . link . component_id ( r . id , record_id ) <EOL> if c and f : <EOL> args = [ record_id ] <EOL> else : <EOL> c = r . controller <EOL> f = r . function <EOL> args = [ r . id , r . component_name , record_id ] <EOL> if update : <EOL> url = str ( URL ( r = r , c = c , f = f , <EOL> args = args + [ "<STR_LIT>" ] , <EOL> ) ) <EOL> else : <EOL> url = str ( URL ( r = r , c = c , f = f , <EOL> args = args + [ "<STR_LIT>" ] , <EOL> ) ) <EOL> else : <EOL> args = [ record_id ] <EOL> get_vars = Storage ( ) <EOL> if "<STR_LIT>" in r . get_vars : <EOL> get_vars . viewing = r . get_vars [ "<STR_LIT>" ] <EOL> if update : <EOL> url = str ( URL ( r = r , c = c , f = f , <EOL> args = args + [ "<STR_LIT>" ] , <EOL> vars = get_vars <EOL> ) ) <EOL> else : <EOL> url = str ( URL ( r = r , c = c , f = f , <EOL> args = args + [ "<STR_LIT>" ] , <EOL> vars = get_vars <EOL> ) ) <EOL> if iframe_safe : <EOL> url = iframe_safe ( url ) <EOL> return url <EOL> return list_linkto <EOL> @ staticmethod <EOL> def _interim_save_button ( ) : <EOL> """<STR_LIT>""" <EOL> label = current . deployment_settings . get_ui_interim_save ( ) <EOL> if label : <EOL> _class = "<STR_LIT>" <EOL> if isinstance ( label , basestring ) : <EOL> label = current . T ( label ) <EOL> elif isinstance ( label , ( tuple , list ) ) and len ( label ) > <NUM_LIT:1> : <EOL> label , _class = label [ : <NUM_LIT:2> ] <EOL> elif not isinstance ( label , lazyT ) : <EOL> label = current . T ( "<STR_LIT>" ) <EOL> item = ( "<STR_LIT>" , label , _class ) <EOL> else : <EOL> return <EOL> settings = current . response . s3 . crud <EOL> if settings . custom_submit : <EOL> settings . custom_submit . insert ( <NUM_LIT:0> , item ) <EOL> else : <EOL> settings . custom_submit = [ item ] <EOL> return <EOL> @ classmethod <EOL> def _dl_ajax_delete ( cls , r , resource ) : <EOL> UID = current . xml . UID <EOL> delete = r . get_vars . get ( "<STR_LIT>" , None ) <EOL> if delete is not None : <EOL> dresource = current . s3db . resource ( resource , id = delete ) <EOL> deletable = dresource . get_config ( "<STR_LIT>" , True ) <EOL> if not deletable : <EOL> r . error ( <NUM_LIT> , current . ERROR . NOT_PERMITTED ) <EOL> authorised = current . auth . s3_has_permission ( "<STR_LIT>" , <EOL> dresource . table , <EOL> record_id = delete ) <EOL> if not authorised : <EOL> r . unauthorised ( ) <EOL> uid = None <EOL> if UID in dresource . table : <EOL> rows = dresource . select ( [ UID ] , <EOL> start = <NUM_LIT:0> , <EOL> limit = <NUM_LIT:1> , <EOL> as_rows = True ) <EOL> if rows : <EOL> uid = rows [ <NUM_LIT:0> ] [ UID ] <EOL> numrows = dresource . delete ( format = r . representation ) <EOL> if numrows > <NUM_LIT:1> : <EOL> message = "<STR_LIT>" % ( numrows , <EOL> current . T ( "<STR_LIT>" ) ) <EOL> elif numrows == <NUM_LIT:1> : <EOL> message = cls . crud_string ( dresource . tablename , <EOL> "<STR_LIT>" ) <EOL> else : <EOL> r . error ( <NUM_LIT> , dresource . error ) <EOL> current . response . view = "<STR_LIT>" <EOL> return current . xml . json_message ( message = message , uuid = uid ) <EOL> else : <EOL> r . error ( <NUM_LIT> , current . ERROR . BAD_RECORD ) <EOL> @ staticmethod <EOL> def _limits ( get_vars ) : <EOL> """<STR_LIT>""" <EOL> start = get_vars . get ( "<STR_LIT:start>" , None ) <EOL> limit = get_vars . get ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> if isinstance ( start , list ) : <EOL> start = start [ - <NUM_LIT:1> ] <EOL> if isinstance ( limit , list ) : <EOL> limit = limit [ - <NUM_LIT:1> ] <EOL> if limit : <EOL> if limit . lower ( ) == "<STR_LIT:none>" : <EOL> limit = None <EOL> else : <EOL> try : <EOL> start = int ( start ) if start is not None else None <EOL> limit = int ( limit ) <EOL> except ( ValueError , TypeError ) : <EOL> start , limit = None , <NUM_LIT:0> <EOL> else : <EOL> start = None <EOL> limit = <NUM_LIT:0> <EOL> return start , limit </s>
