-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from lamenezes/master
add ModelAdmin.list_display
- Loading branch information
Showing
13 changed files
with
75 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ cov: | |
py.test --cov=bottle_admin tests/ | ||
covgui: cov | ||
duvet | ||
clean: | ||
find bottle_admin/ tests/ -name *.pyc | xargs rm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# coding: utf-8 | ||
from bottle_admin.options import ModelAdmin | ||
|
||
|
||
class RoleAdmin(ModelAdmin): | ||
list_display = ('role', 'level') | ||
|
||
|
||
class UserAdmin(ModelAdmin): | ||
list_display = ('username', 'role', 'email_addr', 'creation_date', 'last_login') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# coding: utf-8 | ||
|
||
|
||
def get_object_as_list(obj): | ||
row_list = [] | ||
for col in obj.__table__.columns: | ||
row_list.append((col.name, getattr(obj, col.name))) | ||
return row_list | ||
def get_object_as_list(model, obj): | ||
"""Get the SQLAlchemy query result as a list of tuples""" | ||
|
||
list_display = model.get_list_display() | ||
result = [('id', obj.id)] | ||
result += [(col, getattr(obj, col)) for col in list_display] | ||
print(result) | ||
return result | ||
|
||
def get_objects_as_list(objs): | ||
results = [] | ||
for obj in objs: | ||
obj = get_object_as_list(obj) | ||
results.append(obj) | ||
return results | ||
|
||
def get_objects_as_list(model, objs): | ||
"""Get a list of SQLAlchemy queries as a list of list of tuples""" | ||
return [get_object_as_list(model, obj) for obj in objs] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.