Browse Source

Added ability to update Expando's with an Expando

main
Lakshmi Vyasarajan 14 years ago
parent
commit
2de38e373a
3 changed files with 13 additions and 5 deletions
  1. +3
    -3
      hyde/ext/plugins/meta.py
  2. +5
    -2
      hyde/model.py
  3. +5
    -0
      hyde/tests/test_model.py

+ 3
- 3
hyde/ext/plugins/meta.py View File

@@ -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):


+ 5
- 2
hyde/model.py View File

@@ -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):


+ 5
- 0
hyde/tests/test_model.py View File

@@ -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


Loading…
Cancel
Save