Paul's Programming Notes PostsRSSGithub

Datatables - Uncaught TypeError: Cannot read property 'style' of undefined

If you see this error in datatables: “Uncaught TypeError: Cannot read property ‘style’ of undefined”

It’s likely that you’re missing a header column in your table. Make sure you have the same number of <th> elements as items in the “columns” section of your datatables initialization.

Javascript Data Tables

Editing HSTORE and JSON columns - Flask-Admin

Postgres has a couple of column types for semi-structured data, and Flask-Admin didn’t have a good way to edit them. I added support for both.

For HSTORE (Postgres key-value pairs), I reused the existing InlineFieldList and InlineFormField with a few changes (#1158). Instead of editing a raw string, you get a row of key/value inputs you can add to and remove from.

class ServerView(ModelView):
    form_columns = ['name', 'metadata']  # metadata is an HSTORE column

For JSON columns, there was already a JSONField in the GeoAlchemy backend. I moved it into flask_admin/form/fields.py so both backends could use it, and made it handle non-ASCII characters and show a clear error on malformed JSON instead of blowing up (#1245).

Ansible Vault - storing secrets in repos

When others are deploying a project for you, it’s easy for mistakes to be made when secrets must be updated in environmental variables. Ansible-vault takes a different approach and encrypts the secrets - allowing you to store the secrets in your repo.

To encrypt a file: ansible-vault encrypt secrets.py
To decrypt a file: ansible-vault decrypt secrets.py

More documentation is available here: https://docs.ansible.com/projects/ansible/latest/vault_guide/vault_encrypting_content.html