Renderer returning data, with appended default context as dict (#6870)

This commit is contained in:
Serghei Mihai 2015-03-31 20:01:44 +02:00
parent bf976e8ad9
commit 7d32047694
1 changed files with 14 additions and 0 deletions

View File

@ -124,6 +124,20 @@ class DictRenderer(Renderer):
return context
class DictRendererWithDefault(DictRenderer):
"""
Same as DictRender but each dict item contains data under "data" key and
the config defaults unde "default" key
"""
def get_sources(self, context):
for source in self.config['sources']:
slug = '{0}.{1}'.format(self.slug, source['slug'])
result = source.get('default', {})
result['data'] = Data(slug, self.config, source, context)
yield source['slug'], result
class Data(object):
'''Encapsulate data from a source'''