Exemple #1
0
def data():
    html = ""
    try:
        db_instance = config.get_database_instance()
        shower = Shower()

        table = request.args.get('table')
        attr = request.args.get('attr')
        key = request.args.get('key')
        links = {}
        links['BAid'] = '?table=BAInfo&attr=BAid&key='
        links['WellEvent'] = '?table=WellInfo&attr=Well&key='

        tables = db_instance.get_table_names()
        header = None
        rows = None
        print('Table:', table)
        if table:
            header = shower.show_columns(table)
            rows = shower.show_table(table, attr, key)
        html = render_template('data.html',
                               table=table,
                               tables=tables,
                               header=header,
                               rows=rows,
                               links=links)
    except Exception as e:
        print('views.data: ***Error:', e)
        traceback.print_exc(file=sys.stdout)
    return html
def data():
    html =""
    try:
        db_instance = config.get_database_instance()
        shower = Shower()

        table=request.args.get('table')
        attr=request.args.get('attr')
        key=request.args.get('key')
        links = {}
        links['BAid'] = '?table=BAInfo&attr=BAid&key='
        links['WellEvent'] = '?table=WellInfo&attr=Well&key='

        tables = db_instance.get_table_names()
        header = None
        rows = None
        print('Table:',table)
        if table:
            header = shower.show_columns(table)
            rows = shower.show_table(table,attr,key)
        html = render_template('data.html',table=table,tables=tables,header=header,rows=rows,links=links)
    except Exception as e:
        print('views.data: ***Error:',e)
        traceback.print_exc(file=sys.stdout)
    return html
    def test_run(self):
        #Testing loading an Excel spreadsheet into an sqlite3 database.
#         print ("Creating temporary database %s" % self.TEST_DATABASE)

        self.assertEqual(config.get_environment(),'unittest') # Distructive Tests must run in unittest enviornment

        dbu = DatabaseUtilities()
        dbc = DatabaseCreate()
        loader = Loader()
        dbu.delete_all_tables()
        dbc.create_all()
        dbi = config.get_database_instance()
        
        
        loader.connect()
        loader.open_excel(self.TEST_SPREADSHEET)
        shower = Shower()
        shower.connect()

        #Test that the worksheet has x number of tabs
        self.assertEqual(len(loader.wb.get_sheet_names()), 2)

        #Test that each tab has x number of columns
        self.assertEqual(len(loader.wb['Well'].columns), 12)
        self.assertEqual(len(loader.wb['Royalty Master'].columns), 11)

        #Test that each tab has x number of rows
        self.assertEqual(len(loader.wb['Well'].rows), 9)
        self.assertEqual(len(loader.wb['Royalty Master'].rows), 11)

#         print(dbi.get_table_names())
#         self.assertEqual(len(dbi.get_table_names()), 0)
# 
#         #Test that we have x number of tables
        loader.load_all_sheets()
#         self.assertEqual(len(dbi.get_table_names()), 2)

        #test that each table has x number of columns
        self.assertEqual(len(shower.show_table('Well')), 8)
        self.assertEqual(len(shower.show_table('RoyaltyMaster')), 10)

        #test that each table has x number of row
        self.assertEqual(len(shower.show_columns('Well')), 12)
        self.assertEqual(len(shower.show_columns('RoyaltyMaster')), 11)

        #test column type
        self.assertEqual(shower.column_type('Well', 'ID'), 'integer')
        loader.commit()
Exemple #4
0
class AppServer(object):
    
    print('we are running a class level in AppServer')
    app = Flask(__name__) 
#     appinfo.debug = True
    shower = Shower()
    db = config.get_database()
    
    def __init__(self):
#         AppServer.appinfo = Flask(__name__)
        print("in init of AppServer")
        
    @staticmethod
    @app.route("/")
    def hello():
        print('should be at root')
        return "hello World! v4"
    
    @staticmethod
    @app.route("/hello/<username>")
    def helloab(username):
        print('should be at /ab/')
        return "hello World/hello/" + username
    
    
    @staticmethod
    @app.route("/data/linkxxx/",methods=['GET','POST']) 
    def xxx_link():
        print('AppServer.link2 running',request.method)
        tablename = None
        attrname = None
        linkname = None
        try:
            if request.method == 'POST':
                print('  It was a post')
                tablename = request.form['tablename']
                attrname = request.form['attrname']
                linkname = request.form['linkname']
            
                error = False
                if tablename == '':
                    error = True
                    flash('Table name must be entered.')
                if attrname == '':
                    error = True
                    flash('Attribute name must be entered.')
                if linkname == '':
                    error = True
                    flash('Link name must be entered.')
                    
                if not error:
                    AppServer.shower.insert_link(tablename, attrname, linkname,0,'id')
                    return render_template('closeme.html')
            else:   
                print('  It was a get')
                tablename = AppServer.reqorblank('tablename')
                attrname = AppServer.reqorblank('attrname')
                linkname = AppServer.reqorblank('linkname')
            
            html = render_template('link.html',tablename=tablename,attrname=attrname,linkname=linkname)
            
        except Exception as e:
            print('AppServer.link: ***Error:',e)
            traceback.print_exc(file=sys.stdout)
        return html

    
    @staticmethod
    def reqorblank(reqname):
        a = request.args.get(reqname)
        print('value of a:',a)
        if a:
            return a
        else:
            return ''
        
        
    @staticmethod
    def run(dbName):
        print("Starting AppServer.run")
        AppServer.shower.connect()
#         AppServer.db = config.get_database()
        print('starting the run method of AppServer')
        AppServer.app.secret_key = 'secret'
        AppServer.app.run()
        print('after the run in run in AppServer')