Created
June 15, 2015 23:21
-
-
Save sxslex/d029752b656b8a4a1834 to your computer and use it in GitHub Desktop.
exemplo de retornos diferentes para atraves de views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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