Paul's Programming Notes PostsRSSGithub

Checkmark "column_formatters" - Flask-Admin

Updated 2026-08-29: flask.ext was removed in Flask 0.11, and the Bootstrap 2 icon class no longer renders under Flask-Admin’s Bootstrap 4 templates.

In your custom ModelView, you need to add the following lines:

from flask_admin.model.template import macro
column_formatters = dict(your_column=macro('render_your_column'))
list_template = 'list.html'

In your custom list.html template, you need to add the following jinja2 code:

{% macro render_your_column(model, column) %}
    {% if model.your_column%}<i class="fa fa-check glyphicon glyphicon-ok"></i>{% endif %}
{% endmacro %}

If your row has a value in your_column, then it will show as a checkmark. You need to make a new macro for each column.

Flask-Migrate

https://github.com/miguelgrinberg/Flask-Migrate

Flask-Migrate is exactly what I’ve been looking for when it comes to database migrations. When I create PHP applications with MVC frameworks, the changes in the database need to be done manually when the model is changed. Flask-Migrate handles changes to the database (like adding/removing columns) so your models reflect your database.

This is a big advantage Flask has over PHP frameworks.

Pip Not Working From Powershell

If you have strawberry perl installed, you may get one of these errors when you try to use pip from powershell:

  • Did not provide a command
  • Unknown or unsupported command ‘install’

This is the result of a conflict between strawberry perl’s pip and python’s pip. You need to remove anything related to strawberry perl from your path environmental variable and ensure you have C:\Python27\Scripts and C:\Python27\Scripts in your environmental variables.

Tableau's Frustrating Licensing Program

Tableau’s licensing program is crazy.

I was planning to use “Trusted Authentication” to share an embedded chart with lots of users (not all of whom have licenses). Some of those users will only look at the chart maybe once a year, and we can’t justify buying them an entire license to look at a chart once.

This page says “everyone who visits the page must be a licensed user on Tableau Server”: http://onlinehelp.tableausoftware.com/v7.0/server/en-us/trusted_auth.htm

If you want more details on how to implement Trusted Authentication using PHP, first visit the following folder on your server: C:\Program Files\Tableau\Tableau Server\8.1\extras\embedding\php

It has some sample code, but you need to install version 1.x of pecl_http to make it work. The guides for that are:

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')

Adminer - Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user

Updated 2026-08-08: explained the cause and replaced the trust line, which hands anyone on the box a superuser login.

This is what I originally suggested putting in pg_hba.conf:

local   all             postgres                                trust

It works, and on a shared or internet-facing machine you should not leave it there. trust means the server accepts the connection with no credentials at all, so any local user (including anything running as the web server) can connect as the postgres superuser just by asking.

The reason the default fails is that Debian and Ubuntu ship local all postgres peer. Peer authentication asks the kernel for the operating system username behind the socket connection and requires it to match the PostgreSQL role being requested. Adminer runs under the web server’s user, usually www-data, so asking for the postgres role fails the match and you get Peer authentication failed for user "postgres".

Password authentication is the fix that doesn’t involve trusting every local process:

local   all             postgres                                scram-sha-256

Then reload with sudo systemctl reload postgresql or SELECT pg_reload_conf(); and give Adminer the password. scram-sha-256 has been the default for password_encryption since PostgreSQL 14; on anything older than 10, use md5. Setting a password on a role that never had one is ALTER ROLE postgres WITH PASSWORD 'something';.

Better still, don’t log into Adminer as the superuser. Create a role that owns only the database you’re browsing, and the blast radius of that password stops there.