def before_first(): app_logger().info('Handling database init') if application.debug: # Debug/local dev default_database(Database('sqlite', filename=project_file('.test.db'))) else: # Production! default_database(Database('dynamodb')) # Make sure we have our tables User.ensure_table() Transcript.ensure_table() Taxonomy.ensure_table() # Some debug data we might find useful if application.debug: TEST_EMAIL = application.config.get('TEST_EMAIL') me = first(User.find_by_index('idx_email', TEST_EMAIL)) if not me: me = User(name='Test User', email=TEST_EMAIL) me.save() if not Transcript.find_all(): ts1 = Transcript.from_xml_file( project_file('test/sample/SampleTranscript.xml') ) ts1.script_identifier = 'Original Owned' ts1.owner = me.id ts1.tagger = '' ts1.id = '' ts1.save() ts2 = Transcript.from_xml_file( project_file('test/sample/SampleTranscript.xml') ) ts2.script_identifier = 'New Assigned' ts2.owner = me.id ts2.tagger = me.id ts2.source_transcript = ts1.id ts2.id = '' # Ensure new id on save ts2.save()
# Note that once we get everything working, we'll have be able to use the # logging help in gluten.utils (like app_logger) if application.config.get('DEBUG', None): # Debug mode - running on a workstation application.debug = True logging.basicConfig(level=logging.DEBUG) else: # We are running on AWS Elastic Beanstalk (or something like it) application.debug = False # See .ebextensions/01logging.config logging.basicConfig( filename='/opt/python/log/gluten.log', level=logging.INFO ) app_logger().info('Application debug is %s', application.debug) # Register our blueprints application.register_blueprint(auth) application.register_blueprint(main) application.register_blueprint(admin) # This will be called before the first request is ever serviced @application.before_first_request def before_first(): app_logger().info('Handling database init') if application.debug: # Debug/local dev default_database(Database('sqlite', filename=project_file('.test.db')))