#NEWLINE# @ staticmethod #NEWLINE# def irs_ushahidi_import( r , **attr ) : #NEWLINE# #INDENT# '\n            Import Incident Reports from Ushahidi\n\n            @ToDo: Deployment setting for Ushahidi instance URL\n        ' #NEWLINE# T = current . T #NEWLINE# auth = current . auth #NEWLINE# request = current . request #NEWLINE# response = current . response #NEWLINE# session = current . session #NEWLINE# system_roles = session . s3 . system_roles #NEWLINE# ADMIN = system_roles . ADMIN #NEWLINE# if ( not auth . s3_has_role ( ADMIN ) ) : #NEWLINE# #INDENT# auth . permission . fail ( ) #NEWLINE# #UNINDENT# if ( ( r . representation == 'html' ) and ( r . name == 'ireport' ) and ( not r . component ) and ( not r . id ) ) : #NEWLINE# #INDENT# url = r . get_vars . get ( 'url' , 'http://' ) #NEWLINE# title = T ( 'Import Incident Reports from Ushahidi' ) #NEWLINE# form = FORM ( TABLE ( TR ( TH ( B ( ( '%s: ' % T ( 'URL' ) ) ) ) , INPUT ( _type = 'text' , _name = 'url' , _size = '100' , _value = url , requires = [ IS_URL ( ) , IS_NOT_EMPTY ( ) ] ) , TH ( DIV ( SPAN ( '*' , _class = 'req' , _style = 'padding-right: 5px;' ) ) ) ) , TR ( TD ( B ( ( '%s: ' % T ( 'Ignore Errors?' ) ) ) ) , TD ( INPUT ( _type = 'checkbox' , _name = 'ignore_errors' , _id = 'ignore_errors' ) ) ) , TR ( '' , INPUT ( _type = 'submit' , _value = T ( 'Import' ) ) ) ) ) #NEWLINE# rheader = DIV ( P ( ( '%s: http://wiki.ushahidi.com/doku.php?id=ushahidi_api' % T ( 'API is documented here' ) ) ) , P ( ( '%s URL: http://ushahidi.my.domain/api?task=incidents&by=all&resp=xml&limit=1000' % T ( 'Example' ) ) ) ) #NEWLINE# output = dict ( title = title , form = form , rheader = rheader ) #NEWLINE# if form . accepts ( request . vars , session ) : #NEWLINE# #INDENT# import_count = [ 0 ] #NEWLINE# def count_items( job , import_count = import_count ) : #NEWLINE# #INDENT# if ( job . tablename == 'irs_ireport' ) : #NEWLINE# #INDENT# import_count [ 0 ] += 1 #NEWLINE# #UNINDENT# #UNINDENT# current . s3db . configure ( 'irs_report' , deduplicate = count_items ) #NEWLINE# vars = form . vars #NEWLINE# ushahidi_url = vars . url #NEWLINE# import os #NEWLINE# stylesheet = os . path . join ( request . folder , 'static' , 'formats' , 'ushahidi' , 'import.xsl' ) #NEWLINE# if ( os . path . exists ( stylesheet ) and ushahidi_url ) : #NEWLINE# #INDENT# ignore_errors = vars . get ( 'ignore_errors' , None ) #NEWLINE# try : #NEWLINE# #INDENT# success = r . resource . import_xml ( ushahidi_url , stylesheet = vars , ignore_errors = ignore_errors ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# import sys #NEWLINE# e = sys . exc_info ( ) [ 1 ] #NEWLINE# response . error = e #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if success : #NEWLINE# #INDENT# count = import_count [ 0 ] #NEWLINE# if count : #NEWLINE# #INDENT# response . confirmation = ( '%s %s' % ( import_count [ 0 ] , T ( 'reports successfully imported.' ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# response . information = T ( 'No reports available.' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# response . error = self . error #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# response . view = 'create.html' #NEWLINE# return output #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise HTTP ( 405 , current . ERROR . BAD_METHOD )