Example of custom filters - Flask-Admin
Update: I got this example added to the project: sqla-custom-filter example
This Github issue has an example of how to use custom filters in Flask-Admin: https://github.com/pallets-eco/flask-admin/issues/400
Update: I got this example added to the project: sqla-custom-filter example
This Github issue has an example of how to use custom filters in Flask-Admin: https://github.com/pallets-eco/flask-admin/issues/400
You need to manually change the endpoint like MrJoes says in issue 480: https://github.com/pallets-eco/flask-admin/issues/480
Here’s an example:
admin.add_view(MyModelView(model.CsvTable, db.session, endpoint="duplicate_view"))
You can now visit your view by going to 0.0.0.0/admin/duplicate_view
In your custom ModelView, you need to add the following lines:
from flask.ext.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="icon-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.
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.
If you have strawberry perl installed, you may get one of these errors when you try to use pip from powershell:
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 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:
pecl_http 1.x (php.net manual note, archived)pecl_http 2.x which is too different to work)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
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:
series: {0: {lineWidth: 0, pointSize: 5}}vAxis: { viewWindowMode:'explicit', viewWindow:{ min: 0.5 } },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')
Try putting ?charset=utf8 at the end of your connection string, like:
'mysql+mysqldb://user:pass@111.111.111.111/rf?charset=utf8'