<s> """<STR_LIT>""" <EOL> module = request . controller <EOL> if not settings . has_module ( module ) : <EOL> raise HTTP ( <NUM_LIT> , body = "<STR_LIT>" % module ) <EOL> def index ( ) : <EOL> "<STR_LIT>" <EOL> module_name = settings . modules [ module ] . name_nice <EOL> response . title = module_name <EOL> return dict ( module_name = module_name ) <EOL> def document ( ) : <EOL> """<STR_LIT>""" <EOL> def prep ( r ) : <EOL> s3db . gis_location_filter ( r ) <EOL> if r . method in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> doc_id = get_vars . get ( "<STR_LIT>" , None ) <EOL> if doc_id : <EOL> s3db . doc_document . doc_id . default = doc_id <EOL> return True <EOL> s3 . prep = prep <EOL> output = s3_rest_controller ( rheader = document_rheader ) <EOL> return output <EOL> def document_rheader ( r ) : <EOL> if r . representation == "<STR_LIT:html>" : <EOL> doc_document = r . record <EOL> if doc_document : <EOL> table = db . doc_document <EOL> rheader = DIV ( B ( "<STR_LIT>" % T ( "<STR_LIT:Name>" ) ) , doc_document . name , <EOL> TABLE ( TR ( <EOL> TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , table . file . represent ( doc_document . file ) , <EOL> TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , table . url . represent ( doc_document . url ) , <EOL> ) , <EOL> TR ( <EOL> TH ( "<STR_LIT>" % ORGANISATION ) , table . organisation_id . represent ( doc_document . organisation_id ) , <EOL> TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , table . person_id . represent ( doc_document . organisation_id ) , <EOL> ) , <EOL> ) , <EOL> ) <EOL> return rheader <EOL> return None <EOL> def document_tabs ( r ) : <EOL> """<STR_LIT>""" <EOL> tab_opts = [ { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> ] <EOL> tabs = [ ( T ( "<STR_LIT>" ) , None ) ] <EOL> crud_string = s3base . S3CRUD . crud_string <EOL> for tab_opt in tab_opts : <EOL> tablename = tab_opt [ "<STR_LIT>" ] <EOL> if tablename in db and document_id in db [ tablename ] : <EOL> table = db [ tablename ] <EOL> query = ( table . deleted == False ) & ( table . document_id == r . id ) <EOL> tab_count = db ( query ) . count ( ) <EOL> if tab_count == <NUM_LIT:0> : <EOL> label = crud_string ( tablename , "<STR_LIT>" ) <EOL> elif tab_count == <NUM_LIT:1> : <EOL> label = tab_opt [ "<STR_LIT>" ] <EOL> else : <EOL> label = T ( str ( tab_count ) + tab_opt [ "<STR_LIT>" ] ) <EOL> tabs . append ( ( label , tab_opt [ "<STR_LIT>" ] ) ) <EOL> return tabs <EOL> def image ( ) : <EOL> """<STR_LIT>""" <EOL> def prep ( r ) : <EOL> s3db . gis_location_filter ( r ) <EOL> if r . method in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> doc_id = get_vars . get ( "<STR_LIT>" , None ) <EOL> if doc_id : <EOL> s3db . doc_image . doc_id . default = doc_id <EOL> return True <EOL> s3 . prep = prep <EOL> output = s3_rest_controller ( ) <EOL> return output <EOL> def bulk_upload ( ) : <EOL> """<STR_LIT>""" <EOL> s3 . stylesheets . append ( "<STR_LIT>" ) <EOL> return dict ( ) <EOL> def upload_bulk ( ) : <EOL> """<STR_LIT>""" <EOL> tablename = "<STR_LIT>" <EOL> table = s3db [ tablename ] <EOL> import cgi <EOL> source = request . post_vars . get ( "<STR_LIT>" , None ) <EOL> if isinstance ( source , cgi . FieldStorage ) and source . filename : <EOL> name = source . filename <EOL> image = source . file <EOL> else : <EOL> if "<STR_LIT:name>" in request . vars : <EOL> name = request . vars . name <EOL> else : <EOL> HTTP ( <NUM_LIT> , "<STR_LIT>" ) <EOL> image = request . body . read ( ) <EOL> import cStringIO <EOL> image = cStringIO . StringIO ( image ) <EOL> source = Storage ( ) <EOL> source . filename = name <EOL> source . file = image <EOL> form = SQLFORM ( table ) <EOL> vars = Storage ( ) <EOL> vars . name = name <EOL> vars . image = source <EOL> vars . _formname = "<STR_LIT>" % tablename <EOL> onvalidation = s3db . get_config ( tablename , "<STR_LIT>" , <EOL> s3db . get_config ( tablename , "<STR_LIT>" ) ) <EOL> if form . accepts ( vars , onvalidation = onvalidation ) : <EOL> msg = Storage ( success = True ) <EOL> onaccept = s3db . get_config ( tablename , "<STR_LIT>" , <EOL> s3db . get_config ( tablename , "<STR_LIT>" ) ) <EOL> from gluon . tools import callback <EOL> callback ( onaccept , form , tablename = tablename ) <EOL> else : <EOL> error_msg = "<STR_LIT>" <EOL> for error in form . errors : <EOL> error_msg = "<STR_LIT>" % ( error_msg , error , form . errors [ error ] ) <EOL> msg = Storage ( error = error_msg ) <EOL> response . headers [ "<STR_LIT:Content-Type>" ] = "<STR_LIT>" <EOL> return json . dumps ( msg ) <EOL> def sitrep ( ) : <EOL> """<STR_LIT>""" <EOL> return s3_rest_controller ( ) <EOL> def ck_upload ( ) : <EOL> """<STR_LIT>""" <EOL> upload = request . vars . upload <EOL> if upload is None : <EOL> raise HTTP ( <NUM_LIT> , "<STR_LIT>" ) <EOL> if not hasattr ( upload , "<STR_LIT:file>" ) : <EOL> raise HTTP ( <NUM_LIT> , "<STR_LIT>" ) <EOL> path = os . path . join ( request . folder , "<STR_LIT>" ) <EOL> table = s3db . doc_ckeditor <EOL> form = SQLFORM . factory ( Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> uploadfolder = path , <EOL> ) , <EOL> table_name = "<STR_LIT>" , <EOL> ) <EOL> old_filename = upload . filename <EOL> new_filename = table . upload . store ( upload . file , <EOL> upload . filename ) <EOL> length = os . path . getsize ( os . path . join ( path , new_filename ) ) <EOL> mime_type = upload . headers [ "<STR_LIT>" ] <EOL> title = os . path . splitext ( old_filename ) [ <NUM_LIT:0> ] <EOL> result = table . validate_and_insert ( <EOL> title = title , <EOL> filename = old_filename , <EOL> upload = new_filename , <EOL> flength = length , <EOL> mime_type = mime_type <EOL> ) <EOL> if result . id : <EOL> text = "<STR_LIT>" <EOL> else : <EOL> text = result . errors <EOL> url = URL ( c = "<STR_LIT:default>" , f = "<STR_LIT>" , <EOL> args = [ new_filename ] ) <EOL> return dict ( text = text , cknum = request . vars . CKEditorFuncNum , url = url ) <EOL> def ck_browse ( ) : <EOL> """<STR_LIT>""" <EOL> table = s3db . doc_ckeditor <EOL> set = db ( table . id > <NUM_LIT:0> ) <EOL> rows = set . select ( orderby = table . title ) <EOL> return dict ( rows = rows , cknum = request . vars . CKEditorFuncNum ) <EOL> def ck_delete ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> filename = request . args [ <NUM_LIT:0> ] <EOL> except : <EOL> raise HTTP ( <NUM_LIT> , "<STR_LIT>" ) <EOL> table = s3db . doc_ckeditor <EOL> db ( table . upload == filename ) . delete ( ) <EOL> filepath = os . path . join ( request . folder , "<STR_LIT>" , filename ) <EOL> os . unlink ( filepath ) </s>
