def get_conn(db_path): """Get current database connection. Will create the database if needed. :param db_path: Path to the sqlite file. :type db_path: str """ table_needed = True if os.path.exists(db_path): table_needed = False # connect to the db, creating it if needed conn = sqlite3.connect(db_path) # if its a new db we also need to create the schema if table_needed: schema_path = os.path.abspath(os.path.join( os.path.dirname(__file__), os.pardir, 'resources', 'create_table.sql')) # create the users table with APP.app_context(): sql = file(schema_path, mode='r').read() conn.cursor().executescript(sql) conn.commit() conn.row_factory = sqlite3.Row return conn
def get_conn(db_path): """Get current database connection. Will create the database if needed. :param db_path: Path to the sqlite file. :type db_path: str """ table_needed = True if os.path.exists(db_path): table_needed = False # connect to the db, creating it if needed conn = sqlite3.connect(db_path) # if its a new db we also need to create the schema if table_needed: schema_path = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, "resources", "create_table.sql") ) # create the users table with APP.app_context(): sql = file(schema_path, mode="r").read() conn.cursor().executescript(sql) conn.commit() conn.row_factory = sqlite3.Row return conn
def setUp(self): """Constructor.""" self.db_path = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'test_users.db')) APP.config['DATABASE'] = self.db_path APP.config['TESTING'] = True self.app = APP.test_client() self.user_to_add = dict(name='Akbar', email='*****@*****.**', website='http://www.ac.com', role=0, email_updates='true', latitude=12.32, longitude=-13.03)
def setUp(self): """Constructor.""" self.db_path = os.path.abspath(os.path.join( os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'test_users.db')) APP.config['DATABASE'] = self.db_path APP.config['TESTING'] = True self.app = APP.test_client() self.user_to_add = dict( name='Akbar', email='*****@*****.**', website='http://www.ac.com', role=0, email_updates='true', latitude=12.32, longitude=-13.03)
def send_mail(sender, recipients, subject, text_body, html_body): """To send a single email from sender to receiver synchronously :param sender: Sender of the email. :type sender: str :param recipients: Recipients email address. :type recipients: list :param subject: Subject of the email. :type subject: str :param text_body: Text of the body. :type text_body: str :param html_body: HTML of the body. :type html_body: str """ # Get mail server configuration message = Message(subject=subject, sender=sender, recipients=recipients) message.body = text_body message.html = html_body with APP.app_context(): mail.send(message)
# coding=utf-8 """Simple runner for our flask app. see http://flask.pocoo.org/docs/patterns/packages/#larger-applications """ import optparse from users import APP, LOGGER from users.static import static_file if __name__ == '__main__': parser = optparse.OptionParser() parser.add_option('-d', '--debug', dest='debug', default=False, help='turn on Flask debugging', action='store_true') options, args = parser.parse_args() if options.debug: print 'Running in debug mode' LOGGER.info('Running in debug mode') APP.debug = True # set up flask to serve static content APP.add_url_rule('/<path:path>', 'static_file', static_file) else: print 'Running in production mode' LOGGER.info('Running in production mode') print 'Starting.....' APP.run(host='0.0.0.0')