Fixes issue on tablefields + add
@@ -201,8 +201,9 @@ class RestAPI(object):
get_vars = get_vars or {}
post_vars = post_vars or {}
# validate incoming request
- if not tablename in self.db.tables:
- raise InvalidFormat("Invalid table name: %s" % tablename)
+ tname, tfieldnames = RestAPI.parse_table_and_fields(tablename)
+ if not tname in self.db.tables:
+ raise InvalidFormat("Invalid table name: %s" % tname)
if self.policy:
self.policy.check_if_allowed(method, tablename, id, get_vars, post_vars)
if method in ["POST", "PUT"]:
@@ -332,6 +333,7 @@ class RestAPI(object):
offset = 0
limit = 100
model = False
+ options_list = False
table = db[tname]
queries = []
if self.policy:
@@ -364,6 +366,8 @@ class RestAPI(object):
lookup = {item[0]: {} for item in RestAPI.re_lookups.findall(value)}
elif key == "@model":
model = str(value).lower()[:1] == "t"
+ elif key == "@options_list":
+ options_list = str(value).lower()[:1] == "t"
else:
key_parts = key.rsplit(".")
if not key_parts[-1] in (
@@ -531,7 +535,16 @@ class RestAPI(object):
row[lkey] = drows.get(row.id, [])
response = {}
+ response["table"] = table._tablename
+ if not options_list:
response["items"] = rows.as_list()
+ else:
+ if table._format:
+ response["items"] = [dict(value=row.id, text=(
+ table._format % row)) for row in rows]
+ else:
+ response["items"] = [dict(value=row.id, text=row.id)
+ for row in rows]
if offset == 0:
response["count"] = db(query).count()
if model:
