Export and import for MongoEngine model in Flask-Admin

| Comments

Another tip for Flask-Admin. The task’s requirements are:

  • possibility to choose some model’s objects and download them in JSON
  • possibility to upload them back

There is a ModelView property can_export, it adds an action to export in CSV or another format supported by tablib, but it does not allow to select records and there is no import. So for my task it’s not a solution.

The export is easy to do with an action decorathor.

An update for the productivity apps list

| Comments
An update for the productivity apps list

Several productivity apps I added to this list in the last month.

  • HazeOver - automatically highlights the front window by fading out all the background windows.
  • Hazel - watches whatever folders you tell it to, automatically organizing your files according to the rules you create.
  • Bartender - lets you organize your menu bar apps.
  • iStatMenus - adds system monitor to your menu bar.

For iTerm2 I failed to setup Automatic Profile Switching, but I found a good solution here - Change terminal color when SSH from OS-X.

Google Adsense and blog on subdomain

| Comments

This month I decided to try Google Adsense, just as an experiment. I expect no more 1-2$ in the next month. The process of adding adsense is easy, but the problem is that it requires a primary domain and on the primary domain sneawo.com I had a redirect to blog.sneawo.com. So the first attempt failed after 2 days of waiting. For a second attempt I put an html with a short text on the primary domain. This time it also took 2 days and was successfull.

Meanwhile, I looked some articles and almost all of them recommend to launch the blog in a subfolder, i.e. sneawo.com/blog. Maybe I’ll do it as next experiment.

A bootstrap for a microservice based on Flask with MongoDB

Starting a new project is a common task in microservices architecture. To do this it’s better to have a some template. I put my version to the flask-mongoengine-bootstrap repository. The key point are:

  • very basic, only flask, flask-mongoengine and structlog in requirements
  • configuration through environment variables
  • configured logging in JSON format
  • marking log records with request_id
  • possibility to run development version make dev and tests make test through docker
  • a template for Makefile
  • examples of model, api route and tests

If you’ll use it, do not forget to change SECRET_KEY.

Subscription to the blog updates

| Comments

This year I decided to spend some time on the blog marketing. I don’t know how to do it, but as a first step I’ve added a subscription to the monthly digest of updates. You can see it on the right.

I used MailChimp because:

  • it’s free up to 2,000 subscribers and 12,000 emails per month
  • there is a subscription form builder
  • there is an automatic campaign to send an email by schedule with the posts from RSS

The only problem was to choose an physical address, it’s a requirement for FTC’s CAN-SPAM Act. I don’t want to provide my home address or buy P.O. box for now, so I put my work address.

No-Cache headers in Flask

| Comments

The second line of “The Zen of Python” (try import this) says “Explicit is better than implicit.”. By default Flask response does not return any cache header and you can suppose that browsers will not cache, but some of them can decide for you. So it’s better to provide them, especially for API and it’s easy:

	@app.after_request
    def set_response_headers(response):
        response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
        response.headers['Pragma'] = 'no-cache'
        response.headers['Expires'] = '0'
        return response
« 2/8 »