#NEWLINE# def fill_data( ) : #NEWLINE# #INDENT# countries = [ 'Portugal' , 'Germany' , 'Spain' , 'France' , 'USA' , 'China' , 'Russia' , 'Japan' ] #NEWLINE# politicals = [ 'Democratic' , 'Authorative' ] #NEWLINE# for country in countries : #NEWLINE# #INDENT# c = Country ( name = country ) #NEWLINE# try : #NEWLINE# #INDENT# db . session . add ( c ) #NEWLINE# db . session . commit ( ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# log . error ( 'Update ViewMenu error: {0}' . format ( str ( e ) ) ) #NEWLINE# db . session . rollback ( ) #NEWLINE# #UNINDENT# #UNINDENT# for political in politicals : #NEWLINE# #INDENT# c = PoliticalType ( name = political ) #NEWLINE# try : #NEWLINE# #INDENT# db . session . add ( c ) #NEWLINE# db . session . commit ( ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# log . error ( 'Update ViewMenu error: {0}' . format ( str ( e ) ) ) #NEWLINE# db . session . rollback ( ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# for x in range ( 1 , 20 ) : #NEWLINE# #INDENT# cs = CountryStats ( ) #NEWLINE# cs . population = random . randint ( 1 , 100 ) #NEWLINE# cs . unemployed = random . randint ( 1 , 100 ) #NEWLINE# cs . college = random . randint ( 1 , 100 ) #NEWLINE# year = random . choice ( range ( 1900 , 2012 ) ) #NEWLINE# month = random . choice ( range ( 1 , 12 ) ) #NEWLINE# day = random . choice ( range ( 1 , 28 ) ) #NEWLINE# cs . stat_date = datetime . datetime ( year , x , day ) #NEWLINE# cs . country_id = random . randint ( 1 , len ( countries ) ) #NEWLINE# cs . political_type_id = random . randint ( 1 , len ( politicals ) ) #NEWLINE# db . session . add ( cs ) #NEWLINE# db . session . commit ( ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# log . error ( 'Update ViewMenu error: {0}' . format ( str ( e ) ) ) #NEWLINE# db . session . rollback ( )