Commit 5066d6d2 authored by PJ Janse van Rensburg's avatar PJ Janse van Rensburg

Merge branch 'master' into sqlalchemy-utils-types

parents 0fefc1c8 519ab4d2
......@@ -57,6 +57,9 @@ class User(db.Model):
def __str__(self):
return "{}, {}".format(self.last_name, self.first_name)
def __repr__(self):
return "{}: {}".format(self.id, self.__str__())
class Pet(db.Model):
id = db.Column(db.Integer, primary_key=True)
......@@ -159,6 +162,7 @@ inline_form_options = {
}
class UserAdmin(sqla.ModelView):
action_disallowed_list = ['delete', ]
column_display_pk = True
column_list = [
'id',
......@@ -202,9 +206,10 @@ class UserAdmin(sqla.ModelView):
# Customized Post model admin
class PostAdmin(sqla.ModelView):
column_exclude_list = ['text']
column_list = ['id', 'user', 'title', 'date', 'tags']
column_default_sort = ('date', True)
column_sortable_list = [
'id',
'title',
'date',
('user', ('user.last_name', 'user.first_name')), # sort on multiple columns
......@@ -223,6 +228,9 @@ class PostAdmin(sqla.ModelView):
'tags',
filters.FilterLike(Post.title, 'Fixed Title', options=(('test1', 'Test 1'), ('test2', 'Test 2'))),
]
can_export = True
export_max_rows = 1000
export_types = ['csv', 'xls']
# Pass arguments to WTForms. In this case, change label for text field to
# be 'Big Text' and add required() validator.
......
Flask
Flask-Admin
Flask-SQLAlchemy
tablib
......@@ -2330,12 +2330,12 @@ class BaseModelView(BaseView, ActionsMixin):
if encoding:
mimetype = '%s; charset=%s' % (mimetype, encoding)
ds = tablib.Dataset(headers=[c[1] for c in self._export_columns])
ds = tablib.Dataset(headers=[csv_encode(c[1]) for c in self._export_columns])
count, data = self._export_data()
for row in data:
vals = [self.get_export_value(row, c[0]) for c in self._export_columns]
vals = [csv_encode(self.get_export_value(row, c[0])) for c in self._export_columns]
ds.append(vals)
try:
......
var AdminModelActions = function(actionErrorMessage, actionConfirmations) {
// Actions helpers. TODO: Move to separate file
// batch actions helpers
this.execute = function(name) {
var selected = $('input.action-checkbox:checked').length;
......@@ -48,6 +48,4 @@ var AdminModelActions = function(actionErrorMessage, actionConfirmations) {
});
});
};
if ($('#actions_confirmation').length == 1) {
var modelActions = new AdminModelActions(JSON.parse($('#message-data').text()), JSON.parse($('#actions-confirmation-data').text()));
}
var modelActions = new AdminModelActions(JSON.parse($('#message-data').text()), JSON.parse($('#actions-confirmation-data').text()));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment