It’s possible to optimize the usage of Microsoft Graph Api by batching requests. There is a limitation for 20 requests in one batch request.
Here is a simplified examle:
Another tip for Flask-Admin. The task’s requirements are:
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.
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
The problem with translation in a Celery task is that there is no request context and
None. For Flask-Babel there is a force_locale context manager which solves this problem. But Flask-Security uses Flask-BabelEx and it does not work well with Flask-Babel.
Here is an example how to create a context manager which provides dummy request context.
Suppose there are several similar MongoEngine models and there is a need to modify them through REST. Here is an example how to create a set of such similar resources.
Here is the examples how to install some packages in python:alpine image. Some dependencies should be installed permanently and some only for package build and removed after.
RUN apk add --no-cache jpeg-dev zlib-dev
RUN apk add --no-cache postgresql-dev
RUN apk add --no-cache libmemcached-dev zlib-dev
Then to install:
RUN apk add --no-cache --virtual .build-deps build-base linux-headers \ && pip3 install pip --upgrade \ && pip3 install <packages list> \ && apk del .build-deps
Usually, even a small web application should send some emails: errors, registration, restore password, invitations, etc.
There are 3 solutions:
For some my small projects i choosed mailgun, it provides 10000 emails in month for free, for my needs it’s more than enough and after that it’s also not expensive. For django there is a email backend django-mailgun and it takes two minutes to switch to it.
© 2018 Andrey Zhukov's Tech Blog.