fixed issue 1340, bugs in as_dict, thanks Alan

This commit is contained in:
mdipierro
2013-02-17 09:49:44 -06:00
parent 4334ae38ed
commit 892471d8e5
3 changed files with 26 additions and 19 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.4.1-alpha.2+timestamp.2013.02.17.00.59.22
Version 2.4.1-alpha.2+timestamp.2013.02.17.09.49.04
+14 -7
View File
@@ -9325,13 +9325,12 @@ class Field(Expression):
float, tuple, bool, type(None))
def flatten(obj):
newobj = None
if flat:
if isinstance(obj, flatten.__class__):
return str(type(obj))
elif isinstance(obj, type):
try:
newobj = str(obj).split("'")[1]
return str(obj).split("'")[1]
except IndexError:
return str(obj)
elif not isinstance(obj, SERIALIZABLE_TYPES):
@@ -9340,11 +9339,14 @@ class Field(Expression):
newobj = dict()
for k, v in obj.items():
newobj[k] = flatten(v)
return newobj
elif isinstance(obj, (list, tuple, set)):
newobj = [flatten(v) for v in obj]
return [flatten(v) for v in obj]
else:
newobj = obj
return newobj
return obj
elif isinstance(obj, (dict, set)):
return obj.copy()
else: return obj
def filter_requires(t, r, options=True):
if sanitize and any([keyword in str(t).upper() for
@@ -9355,9 +9357,14 @@ class Field(Expression):
if options and hasattr(r, "options"):
if callable(r.options):
r.options()
newr = r.__dict__
newr = r.__dict__.copy()
else:
newr = r
newr = r.copy()
# remove options if not required
if not options and newr.has_key("labels"):
[newr.update({key:None}) for key in
("labels", "theset") if (key in newr)]
for k, v in newr.items():
if k == "other":
+11 -11
View File
@@ -660,7 +660,10 @@ class TestDALDictImportExport(unittest.TestCase):
"items":{"staff":{"items": {"name":
{"default":"Michael"},
"food":
{"default":"Spam"}}},
{"default":"Spam"},
"show":
{"type": "reference show"}
}},
"show":{"items": {"name":
{"default":mpfc},
"rating":
@@ -669,15 +672,18 @@ class TestDALDictImportExport(unittest.TestCase):
assert "staff" in db4.tables
assert "name" in db4.staff
assert db4.show.rating.type == "double"
assert db4.show.insert() is not None
assert (db4.show.insert(), db4.show.insert(name="Loriot"),
db4.show.insert(name="Il Mattatore")) == (1, 2, 3)
assert db4(db4.show).select().first().id == 1
assert db4(db4.show).select().first().name == mpfc
dbdict5 = {"uri": 'sqlite:memory:'}
db5 = DAL(dbdict5)
assert db5.tables in ([], None)
assert not (str(db5) in ("", None))
dbdict6 = {"items":{"staff":{},
dbdict6 = {"uri": 'sqlite:memory:',
"items":{"staff":{},
"show":{"items": {"name": {},
"rating":
{"type":"double"}}}}}
@@ -685,14 +691,8 @@ class TestDALDictImportExport(unittest.TestCase):
assert len(db6["staff"].fields) == 1
assert "name" in db6["show"].fields
# the following would fail (see issue 1332)
# assert db6.staff.insert() is not None
# assert db6(db6.staff).select().first().id == 1
dbdict7 = {}
db7 = DAL(dbdict7)
db7.tables() in (None, [])
assert not str(db7) in ("", None)
assert db6.staff.insert() is not None
assert db6(db6.staff).select().first().id == 1
db6.staff.drop()
db6.show.drop()