Skip to content
Snippets Groups Projects
Commit 3f0a765b authored by legac's avatar legac
Browse files

Add a StoreModifier to deal with orderby directive.

parent d0c2d296
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,7 @@ plugins = PluginManager('dbui', ...@@ -54,6 +54,7 @@ plugins = PluginManager('dbui',
modifier_fields={}, modifier_fields={},
modifier_forms={}, modifier_forms={},
modifier_grids={}, modifier_grids={},
modifier_stores={},
modifier_viewports=Storage(extjs={})) modifier_viewports=Storage(extjs={}))
......
...@@ -11,9 +11,7 @@ dbui = local_import('plugin_dbui') ...@@ -11,9 +11,7 @@ dbui = local_import('plugin_dbui')
# add plugin to all grids and to all forms # add plugin to all grids and to all forms
# #
dbui.configure_grids(db, plugins=['pGridRowEditorConfirmDelete', dbui.configure_grids(db, plugins=['pGridRowEditorConfirmDelete',
'pGridRowEditorContextMenu', 'pGridRowEditorContextMenu'])
'pGridPaging',
'pGridMathJax'])
dbui.configure_forms(db, plugins=['pFormToolTip']) dbui.configure_forms(db, plugins=['pFormToolTip'])
...@@ -147,6 +145,7 @@ tpl = ['<b>{PublicationsTitle}</b><br>', ...@@ -147,6 +145,7 @@ tpl = ['<b>{PublicationsTitle}</b><br>',
] ]
gridModifier = dbui.GridModifier('publications') gridModifier = dbui.GridModifier('publications')
gridModifier.append_plugins('pGridPaging', 'pGridMathJax')
gridModifier.merge_columns('title', gridModifier.merge_columns('title',
'authors', 'authors',
'id_collaborations', 'id_collaborations',
...@@ -189,6 +188,11 @@ gridModifier.set_filters(*filters, ...@@ -189,6 +188,11 @@ gridModifier.set_filters(*filters,
plugins=['pFormToolTip'], plugins=['pFormToolTip'],
width=300) width=300)
#
# order store for technical table
#
storeModifier = dbui.StoreModifier('teams')
storeModifier.orderby(~db.teams.team)
# #
# The navigation tree # The navigation tree
......
...@@ -41,6 +41,7 @@ from extjs import (CheckBox, ...@@ -41,6 +41,7 @@ from extjs import (CheckBox,
from fieldsmodifier import FieldsModifier from fieldsmodifier import FieldsModifier
from formmodifier import configure_forms, FormModifier from formmodifier import configure_forms, FormModifier
from gridmodifier import configure_grids, GridModifier from gridmodifier import configure_grids, GridModifier
from storemodifier import StoreModifier
from helper import (as_list, from helper import (as_list,
decode_field, decode_field,
encode_field, encode_field,
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Author: R. Le Gac Author: R. Le Gac
""" """
import gluon.dal
import re import re
from extjs import * from extjs import *
...@@ -484,7 +485,7 @@ def to_gridPanel(table, **kwargs): ...@@ -484,7 +485,7 @@ def to_gridPanel(table, **kwargs):
if filter: if filter:
cfg = GridWithFilter(panelCfg=dict(cfg), cfg = GridWithFilter(panelCfg=dict(cfg),
selectorCfg=filter) selectorCfg=filter)
return cfg return cfg
...@@ -553,6 +554,23 @@ def to_jsonstore(table, **kwargs): ...@@ -553,6 +554,23 @@ def to_jsonstore(table, **kwargs):
nt = (tablename, fieldname, k_tablename, k_key) nt = (tablename, fieldname, k_tablename, k_key)
base_params['where'].append("[%s.%s] == [%s.%s]" % nt) base_params['where'].append("[%s.%s] == [%s.%s]" % nt)
# configuration options from the store modifier
# namely the order by directive
modifier_stores = PluginManager('dbui').dbui.modifier_stores
if tablename in modifier_stores:
base_params['orderby'] = []
for el in modifier_stores[tablename].orderby:
if isinstance(el, gluon.dal.Field):
field, dir = el, 'ASC'
elif isinstance(el, gluon.dal.Expression):
field, dir = el.first, 'DESC'
base_params['orderby'].append([field.tablename, field.name, dir])
# configuration options from the keyword arguments # configuration options from the keyword arguments
cfg.update(kwargs) cfg.update(kwargs)
......
...@@ -333,6 +333,11 @@ class DbSvc(BaseSvc): ...@@ -333,6 +333,11 @@ class DbSvc(BaseSvc):
An AND is performed between the different An AND is performed between the different
elements of the list. elements of the list.
orderby (optional)
order directive
A list of fields [(table1, field1, dir), (table2, field3, dir), ...]
where dir is either ASC or DESC
The dictionary can also contains parameters useful for paging. The dictionary can also contains parameters useful for paging.
For more detail see Ext.PagingToolbar. For more detail see Ext.PagingToolbar.
start start
...@@ -376,9 +381,17 @@ class DbSvc(BaseSvc): ...@@ -376,9 +381,17 @@ class DbSvc(BaseSvc):
limit = int(arg['limit']) limit = int(arg['limit'])
kwargs['limitby'] = (start, start+limit) kwargs['limitby'] = (start, start+limit)
# handle the orderby directive ['[table1, field2, dir]', ....]
if 'orderby' in arg:
kwargs['orderby'] = []
for tablename, fieldname, dir in arg['orderby']:
el = db[tablename][fieldname]
if dir == 'DESC':
el = ~el
kwargs['orderby'].append(el)
# interrogate the database and serialize the records as a list: # interrogate the database and serialize the records as a list:
# [{TableField: value, }, {...}, ...] # [{TableField: value, }, {...}, ...]
rows = db(query).select(*fields, **kwargs) rows = db(query).select(*fields, **kwargs)
li = rows_serializer(rows) li = rows_serializer(rows)
......
""" Author: R. Le Gac
"""
from gluon.storage import Storage
from modifier import Modifier
MODIFIER_STORES = 'modifier_stores'
class StoreModifier(Modifier):
"""Helper tool to customize the store associated to a table.
"""
def __init__(self, tablename):
"""Initialize the modifier persistent data.
"""
Modifier.__init__(self, MODIFIER_STORES, tablename)
self.data.orderby = []
def orderby(self, *fields):
"""Order the store according to the list of database fields.
"""
self.data.orderby.extend(fields)
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
HEAD HEAD
- Add a StoreModifier to handle the orderby directive
0.4.7.3 (Jun 2012) 0.4.7.3 (Jun 2012)
- Consolidation version - Consolidation version
- Add options in App.BasePanelWithSelector to control the selector shape. - Add options in App.BasePanelWithSelector to control the selector shape.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment