https://github.com/dev0x13/fgridview
Python GridView generator
https://github.com/dev0x13/fgridview
Last synced: 3 months ago
JSON representation
Python GridView generator
- Host: GitHub
- URL: https://github.com/dev0x13/fgridview
- Owner: dev0x13
- Created: 2014-07-16T11:47:56.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-11T09:37:12.000Z (almost 12 years ago)
- Last Synced: 2025-03-21T12:26:54.782Z (over 1 year ago)
- Language: Python
- Size: 180 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
FGridView
=========
FGridView generates YII-style GridView for Python web frameworks like Flask. CSS was partially taken from YII framework, but styles are replaceable.
Usage example:
data = [{"uid": 1, "name": "Porto", "comments": "The woman"},
{"uid": 2, "name": "Ghast", "comments": "The daemon"},
{"uid": 3, "name": "My page",
"comments": "My personal homepage"}]
columns = OrderedDict() # Important!
columns["name"] = {"label": "Name", "type": "html"}
columns["comments"] = "Misc"
actions = [{"link": "/entities/update/", "title": "Update",
"image": "/static/img/update.png", "id": "uid"},
{"link": "/entities/delete/", "title": "Delete",
"image": "/static/img/delete.png", "id": "uid"}]
def css_expression_func(row_number, row):
if row["is_error"] == 1:
return "err"
if row_number % 2 == 0:
return "odd"
else:
return "even"
# Example sorting handling
sorting_params = {}
sorting = "/users?sort=1&field="
if request.method == "GET":
if request.args.get("sort") and request.args.get("order") and request.args.get("field"):
sorting_params = {"field": request.args.get("field"), "order": request.args.get("order")}
# Your code with selecting data from source in due order
grid = FGridView.render_grid(data, columns, actions, sorting, css_expression_func, sorting_params)