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): ...@@ -57,6 +57,9 @@ class User(db.Model):
def __str__(self): def __str__(self):
return "{}, {}".format(self.last_name, self.first_name) return "{}, {}".format(self.last_name, self.first_name)
def __repr__(self):
return "{}: {}".format(self.id, self.__str__())
class Pet(db.Model): class Pet(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
...@@ -159,6 +162,7 @@ inline_form_options = { ...@@ -159,6 +162,7 @@ inline_form_options = {
} }
class UserAdmin(sqla.ModelView): class UserAdmin(sqla.ModelView):
action_disallowed_list = ['delete', ]
column_display_pk = True column_display_pk = True
column_list = [ column_list = [
'id', 'id',
...@@ -202,9 +206,10 @@ class UserAdmin(sqla.ModelView): ...@@ -202,9 +206,10 @@ class UserAdmin(sqla.ModelView):
# Customized Post model admin # Customized Post model admin
class PostAdmin(sqla.ModelView): class PostAdmin(sqla.ModelView):
column_exclude_list = ['text'] column_list = ['id', 'user', 'title', 'date', 'tags']
column_default_sort = ('date', True) column_default_sort = ('date', True)
column_sortable_list = [ column_sortable_list = [
'id',
'title', 'title',
'date', 'date',
('user', ('user.last_name', 'user.first_name')), # sort on multiple columns ('user', ('user.last_name', 'user.first_name')), # sort on multiple columns
...@@ -223,6 +228,9 @@ class PostAdmin(sqla.ModelView): ...@@ -223,6 +228,9 @@ class PostAdmin(sqla.ModelView):
'tags', 'tags',
filters.FilterLike(Post.title, 'Fixed Title', options=(('test1', 'Test 1'), ('test2', 'Test 2'))), 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 # Pass arguments to WTForms. In this case, change label for text field to
# be 'Big Text' and add required() validator. # be 'Big Text' and add required() validator.
......
Flask Flask
Flask-Admin Flask-Admin
Flask-SQLAlchemy Flask-SQLAlchemy
tablib
...@@ -2330,12 +2330,12 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -2330,12 +2330,12 @@ class BaseModelView(BaseView, ActionsMixin):
if encoding: if encoding:
mimetype = '%s; charset=%s' % (mimetype, 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() count, data = self._export_data()
for row in 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) ds.append(vals)
try: try:
......
var AdminModelActions = function(actionErrorMessage, actionConfirmations) { var AdminModelActions = function(actionErrorMessage, actionConfirmations) {
// Actions helpers. TODO: Move to separate file // batch actions helpers
this.execute = function(name) { this.execute = function(name) {
var selected = $('input.action-checkbox:checked').length; var selected = $('input.action-checkbox:checked').length;
...@@ -48,6 +48,4 @@ var AdminModelActions = function(actionErrorMessage, actionConfirmations) { ...@@ -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