fixed issue 1340, bugs in as_dict, thanks Alan
This commit is contained in:
@@ -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
@@ -9325,13 +9325,12 @@ class Field(Expression):
|
|||||||
float, tuple, bool, type(None))
|
float, tuple, bool, type(None))
|
||||||
|
|
||||||
def flatten(obj):
|
def flatten(obj):
|
||||||
newobj = None
|
|
||||||
if flat:
|
if flat:
|
||||||
if isinstance(obj, flatten.__class__):
|
if isinstance(obj, flatten.__class__):
|
||||||
return str(type(obj))
|
return str(type(obj))
|
||||||
elif isinstance(obj, type):
|
elif isinstance(obj, type):
|
||||||
try:
|
try:
|
||||||
newobj = str(obj).split("'")[1]
|
return str(obj).split("'")[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return str(obj)
|
return str(obj)
|
||||||
elif not isinstance(obj, SERIALIZABLE_TYPES):
|
elif not isinstance(obj, SERIALIZABLE_TYPES):
|
||||||
@@ -9340,11 +9339,14 @@ class Field(Expression):
|
|||||||
newobj = dict()
|
newobj = dict()
|
||||||
for k, v in obj.items():
|
for k, v in obj.items():
|
||||||
newobj[k] = flatten(v)
|
newobj[k] = flatten(v)
|
||||||
|
return newobj
|
||||||
elif isinstance(obj, (list, tuple, set)):
|
elif isinstance(obj, (list, tuple, set)):
|
||||||
newobj = [flatten(v) for v in obj]
|
return [flatten(v) for v in obj]
|
||||||
else:
|
else:
|
||||||
newobj = obj
|
return obj
|
||||||
return newobj
|
elif isinstance(obj, (dict, set)):
|
||||||
|
return obj.copy()
|
||||||
|
else: return obj
|
||||||
|
|
||||||
def filter_requires(t, r, options=True):
|
def filter_requires(t, r, options=True):
|
||||||
if sanitize and any([keyword in str(t).upper() for
|
if sanitize and any([keyword in str(t).upper() for
|
||||||
@@ -9355,9 +9357,14 @@ class Field(Expression):
|
|||||||
if options and hasattr(r, "options"):
|
if options and hasattr(r, "options"):
|
||||||
if callable(r.options):
|
if callable(r.options):
|
||||||
r.options()
|
r.options()
|
||||||
newr = r.__dict__
|
newr = r.__dict__.copy()
|
||||||
else:
|
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():
|
for k, v in newr.items():
|
||||||
if k == "other":
|
if k == "other":
|
||||||
|
|||||||
+11
-11
@@ -660,7 +660,10 @@ class TestDALDictImportExport(unittest.TestCase):
|
|||||||
"items":{"staff":{"items": {"name":
|
"items":{"staff":{"items": {"name":
|
||||||
{"default":"Michael"},
|
{"default":"Michael"},
|
||||||
"food":
|
"food":
|
||||||
{"default":"Spam"}}},
|
{"default":"Spam"},
|
||||||
|
"show":
|
||||||
|
{"type": "reference show"}
|
||||||
|
}},
|
||||||
"show":{"items": {"name":
|
"show":{"items": {"name":
|
||||||
{"default":mpfc},
|
{"default":mpfc},
|
||||||
"rating":
|
"rating":
|
||||||
@@ -669,15 +672,18 @@ class TestDALDictImportExport(unittest.TestCase):
|
|||||||
assert "staff" in db4.tables
|
assert "staff" in db4.tables
|
||||||
assert "name" in db4.staff
|
assert "name" in db4.staff
|
||||||
assert db4.show.rating.type == "double"
|
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().id == 1
|
||||||
assert db4(db4.show).select().first().name == mpfc
|
assert db4(db4.show).select().first().name == mpfc
|
||||||
|
|
||||||
dbdict5 = {"uri": 'sqlite:memory:'}
|
dbdict5 = {"uri": 'sqlite:memory:'}
|
||||||
db5 = DAL(dbdict5)
|
db5 = DAL(dbdict5)
|
||||||
assert db5.tables in ([], None)
|
assert db5.tables in ([], None)
|
||||||
|
assert not (str(db5) in ("", None))
|
||||||
|
|
||||||
dbdict6 = {"items":{"staff":{},
|
dbdict6 = {"uri": 'sqlite:memory:',
|
||||||
|
"items":{"staff":{},
|
||||||
"show":{"items": {"name": {},
|
"show":{"items": {"name": {},
|
||||||
"rating":
|
"rating":
|
||||||
{"type":"double"}}}}}
|
{"type":"double"}}}}}
|
||||||
@@ -685,14 +691,8 @@ class TestDALDictImportExport(unittest.TestCase):
|
|||||||
assert len(db6["staff"].fields) == 1
|
assert len(db6["staff"].fields) == 1
|
||||||
assert "name" in db6["show"].fields
|
assert "name" in db6["show"].fields
|
||||||
|
|
||||||
# the following would fail (see issue 1332)
|
assert db6.staff.insert() is not None
|
||||||
# assert db6.staff.insert() is not None
|
assert db6(db6.staff).select().first().id == 1
|
||||||
# assert db6(db6.staff).select().first().id == 1
|
|
||||||
|
|
||||||
dbdict7 = {}
|
|
||||||
db7 = DAL(dbdict7)
|
|
||||||
db7.tables() in (None, [])
|
|
||||||
assert not str(db7) in ("", None)
|
|
||||||
|
|
||||||
db6.staff.drop()
|
db6.staff.drop()
|
||||||
db6.show.drop()
|
db6.show.drop()
|
||||||
|
|||||||
Reference in New Issue
Block a user