diff --git a/hyde/ext/plugins/meta.py b/hyde/ext/plugins/meta.py index 1831e18..2433b1c 100644 --- a/hyde/ext/plugins/meta.py +++ b/hyde/ext/plugins/meta.py @@ -29,10 +29,10 @@ class Metadata(Expando): """ Updates the metadata with new stuff """ - if isinstance(data, dict): - super(Metadata, self).update(data) - else: + if isinstance(data, basestring): super(Metadata, self).update(yaml.load(data)) + else: + super(Metadata, self).update(data) class MetaPlugin(Plugin): diff --git a/hyde/model.py b/hyde/model.py index 9e84db4..16387cf 100644 --- a/hyde/model.py +++ b/hyde/model.py @@ -18,8 +18,11 @@ class Expando(object): Updates the expando with a new dictionary """ d = d or {} - for key, value in d.items(): - setattr(self, key, Expando.transform(value)) + if isinstance(d, dict): + for key, value in d.items(): + setattr(self, key, Expando.transform(value)) + elif isinstance(d, Expando): + self.update(d.__dict__) @staticmethod def transform(primitive): diff --git a/hyde/tests/test_model.py b/hyde/tests/test_model.py index df6c2c9..7db97f4 100644 --- a/hyde/tests/test_model.py +++ b/hyde/tests/test_model.py @@ -37,6 +37,11 @@ def test_expando_update(): assert x.b.c == d['b']['c'] assert x.b.d.e == d['b']['d']['e'] assert x.f == d["f"] + d2 = {"a": 789, "f": "opq"} + y = Expando(d2) + x.update(y) + assert x.a == 789 + assert x.f == "opq" TEST_SITE_ROOT = File(__file__).parent.child_folder('sites/test_jinja') import yaml