Paul's Programming Notes     Archive     Feed     Github

Possible Solution To Slow SQLalchemy + Flask Application

This stackoverflow thread talks about why you want to use scoped_session:
http://stackoverflow.com/questions/6519546/scoped-sessionsession-maker-or-plain-session-maker-in-sqlalchemy

Basically, your web application isn't thread-safe if you're not using scoped_session. It's much better than having you application use a new thread for every instance.

An example of scoped_session in use is available here: https://github.com/mjhea0/flask-boilerplate/blob/master/models.py

Hide Zero Value Points On Google Chart

I have a line chart which needed a series of points. I don't want points to show if the value is zero.

Here's my solution:

  • Set the series's lineWidth to zero and make the point larger than 0:
    series: {0: {lineWidth: 0, pointSize: 5}}
  • Make the viewWindow setting's min higher than 0 (to hide the 0 points):
    vAxis: { viewWindowMode:'explicit', viewWindow:{ min: 0.5 } },

Change Home Flask-Admin

This was the only thing I was able to get working: http://www.marteinn.se/blog/?p=637

Just putting index.html into an admin/ directory wouldn't work.

There's also an even shorter way to do it, for example:
admin = Admin(app, "G-Cal Manager", index_view=AdminIndexView(name='Home', template='admin/home.html', url='/'))

The example above will change the root url to / instead of /admin and it will use home.html from your templates/admin folder.

To fix the 404 errors on your stylesheets after the change, you will also need to change the static_folder in your flask object:
app = Flask(__name__, static_folder='admin')


Clone/Copy Table Schema From One Database To Another - SQLalchemy

I got the following code from slide 36 of this slideshow: http://www.slideshare.net/Stiivi/python-business-intelligence-pydata-2012-talk

SQLalchemy - Print Tables In Database (Show Tables)

from sqlalchemy import create_engine, Table, MetaData

engine = create_engine('mysql+mysqldb://username:password@111.111.111.111/databaseName')
metadata = MetaData(bind=engine)
metadata.reflect(engine)
print metadata.tables.keys()

You could also use that for looping through a list of the tables in the database.