Skip to content

Instantly share code, notes, and snippets.

@sxslex
Created June 15, 2015 23:21
Show Gist options
  • Save sxslex/d029752b656b8a4a1834 to your computer and use it in GitHub Desktop.
Save sxslex/d029752b656b8a4a1834 to your computer and use it in GitHub Desktop.
exemplo de retornos diferentes para atraves de views
dados = [dict(id=1,name='slex',year=25+i) for i in xrange(10)]
def view1(items):
return [
dict(
id=item['id'],
name=item['name'],
year=item['year'],
)
for item in items
]
def view2(items):
return [
dict(
nome=item['name'],
idade='%d anos' % item['year'],
)
for item in items
]
def get(view='view1'):
views = {
'view1': view1,
'view2': view2
}
return views[view](dados)
if __name__ == '__main__':
import pprint
pprint.pprint(get('view1'))
pprint.pprint(get('view2'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment