Paul's Programming Notes PostsRSSGithub

Override ModelView Class - Flask-Admin

The Flask-Admin docs show how to override your base ModelView (wrap shared logic in a base class all your views inherit): flask-admin.readthedocs.io/en/latest/introduction

You would want to do this if you wanted to add something to all of your admin classes. Use cases:

  • If you wanted to require login by overriding is_accessible for all of your ModelViews.
  • If you wanted to add an export method to all of your ModelViews.

Get Column and Row Labels In selectHandler - Google Charts / Visualization API

For a more complete example of using selectHandler, see this page: https://developers.google.com/chart/interactive/docs/basic_interactivity

My example below get the labels from the row and the columns. I used this to send the user to another link and drill-down.

// this is an example of a bar chart's selectHandler function
function selectHandler() {
    var selection = chart.getSelection();
    var item = selection[0];

    if (item.row != null && item.column != null) {
    var rowLabel = parseInt(data.getValue(item.row, 0));
    var columnLabel = data.getColumnLabel(item.column);
        }
}
google.visualization.events.addListener(chart, 'select', selectHandler);

Ordered Post Data - Python Requests

Here’s an example of how to send ordered data with python’s Requests library, for when the order of your post request data matters:

import requests
from collections import OrderedDict

payload = OrderedDict([("username", "admin"), ("pwd", "password")]) # the order matters!
r = requests.post('http://1.1.1.1/example', data=payload)
print r.text