Skip to content
Snippets Groups Projects
Commit 8483a9b9 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Upgrade to run with alias tables.

parent 40b5e154
No related branches found
No related tags found
No related merge requests found
......@@ -110,8 +110,12 @@ def dbui_conf():
di[action].append({'name': method, 'len': nargs})
# the stores configuration (static, for each table,...)
# NOTE: the interface require a store for all tables including alias.
# The only way to extract them is to scan the attributes list of
# the DAL since the method db.tables() or any variant return
# tables but not the alias one
storeCfgs = plugins.dbui.static_stores
for table in db:
for table in dbui.get_all_tables(db):
cfg = dbui.to_jsonstore(table)
storeCfgs[cfg['storeId']] = cfg
......
......@@ -50,6 +50,7 @@ from storemodifier import AddStore, StoreModifier
from helper import (as_list,
decode_field,
encode_field,
get_all_tables,
get_create_id,
get_field_validators,
get_file_paths,
......
......@@ -10,6 +10,7 @@ from gluon.contrib import simplejson as json
from gluon.storage import Storage
from helper import (encode_field,
decode_field,
get_all_tables,
get_foreign_field,
is_foreign_field,
rows_serializer)
......@@ -168,6 +169,7 @@ class DbSvc(BaseSvc):
def _is_fields_values_valid(self, table, fields):
"""Helper method to check each field value against its validators.
Return an empty dictionary when everything is OK or a dictionary
with fields failing check: {field1: error1, field2: error2,...}
......@@ -176,6 +178,14 @@ class DbSvc(BaseSvc):
db = self.environment['db']
for (field, val) in fields.items():
# NOTE: checks are not applied to foreign fields since
# consistency is garanty by the interface via the use of
# combobox. This approach help when running with alias table
# since validation crashed in that case.
if is_foreign_field(db[table][field]):
continue
errmsg = db[table][field].validate(val)[1]
if errmsg:
di[encode_field(table, field)] = errmsg
......@@ -183,12 +193,17 @@ class DbSvc(BaseSvc):
return di
def _is_table_in_db(self, table):
def _is_table_in_db(self, tablename):
"""Helper method to check that a table exist in the database.
The method handles regular and alias tables.
Raise the DbSvcException if not.
"""
if table not in self.environment['db'].tables:
db = self.environment['db']
tablenames = [table._tablename for table in get_all_tables(db)]
if tablename not in tablenames:
raise DbSvcException(TABLE_NOT_IN_DB % table)
......@@ -439,12 +454,14 @@ class DbSvc(BaseSvc):
query = self._encode_query(arg['where'])
# Count the number of record in the table --require for the paging
# NOTE: the usual method db(db.table).count() failed with alias table
# it is why we use a more complicated approach.
if query:
nrecords = db(query).count()
nrecords = len(db(query).select())
else:
table = arg['tableName']
nrecords = db(db[table].id).count()
nrecords = db(db[table]).count()
# handle paging options (see Ext.PagingToolbar)
kwargs = {}
......
......@@ -8,6 +8,7 @@ import subprocess
import tempfile
from gluon import current
from gluon.dal import Table
from gluon.http import HTTP
from gluon.validators import (IS_DATE_IN_RANGE,
IS_DATETIME_IN_RANGE,
......@@ -65,6 +66,19 @@ def encode_field(*args):
return ''.join([el[0].upper()+el[1:].lower() for el in args if len(el)])
def get_all_tables(dal):
"""Helper function to return a list of all gluon.dal.Table
house by the DAL object. The list includes alias table.
It is recommend to use standard iterator provided by
the DAL object. However by contruction, they ignore
alias table.
"""
li = [dal[attr] for attr in dir(dal) if isinstance(dal[attr], Table)]
return li
def get_create_id(table, **kwargs):
"""Helper function to find the id of a row identified by
a set of field value pairs.
......
--------------------------------- CHANGE LOG ----------------------------------
HEAD
- Upgrade to run with alias table.
0.4.10.3 (Mar 2013)
- Fix a bug in App.BasePanelWithSelector for IE.
......
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