Nice tip! Thank you Bruno.
On Mon, Jan 24, 2011 at 7:10 PM, Bruno Rocha <[email protected]> wrote: > Hi, this is a simple tip on how you can use pyGravatar to get user profile > picture. > > 1. First download pyGravatar > https://bitbucket.org/gridaphobe/pygravatar/src > Put the > gravatar,py<https://bitbucket.org/gridaphobe/pygravatar/raw/ae9fd2d3b56c/gravatar.py>in > gluon/contrib > > (if you prefer you can do pip install pyGravatar ) > > 2. In your model import Gravatar > try: > from gravatar import Gravatar > except ImportError: > from gluon.contrib.gravatar import Gravatar > > 3. If you are using scaffold app, edit default/user.html view > {{extend 'layout.html'}} > <h2>{{=T( request.args(0).replace('_',' ').capitalize() )}}</h2> > <div id="web2py_user_form"> > *{{if 'profile' in request.args(0):}}* > * <img src='{{=Gravatar(auth.user.email).thumb}}'>* > *{{pass}}* > {{=form}} > > 4. You now have a profile page like that: > > http://awesomescreenshot.com/0d66e8k05 > > [image: profilepage.png] > > So simple, in any page you want the user avatar you just need to use > > *<img src='{{=Gravatar(auth.user.email).thumb}}'>* > * > * > *<img src='{{=Gravatar('[email protected]').thumb}}'>* > * > * > * > * > > You can go further and get the user profile bio from gravatar.com > > *In default/user.html* > > {extend 'layout.html'}} > <h2>{{=T( request.args(0).replace('_',' ').capitalize() )}}</h2> > <div id="web2py_user_form"> > *{{if 'profile' in request.args(0):}}* > * <img src='{{=Gravatar(auth.user.email).thumb}}'>* > * <blockquote style='width:300px;'>* > * {{try:}}* > * {{=Gravatar(**auth.user.email**).profile['aboutMe']}}* > * {{except Exception:}}* > * No profile* > * {{pass}}* > * </blockquote>* > *{{pass}*} > > Then you get this: http://awesomescreenshot.com/0106e94c4 > > [image: profilepage2.png] > > You can also get extra services your user have registered in gravatar > > *in views default/user.html* > > {{if 'profile' in request.args(0):}} > <img src='{{=Gravatar(auth.user.email).thumb}}'> > <blockquote style='width:400px;'> > {{try:}} > {{=Gravatar(auth.user.email).profile['aboutMe']}} > {{services = Gravatar(auth.user.email).profile.get('accounts',{})}} > {{if services:}} > {{=UL(*[LI(service['shortname'],' - > ',A(service['url'],_href=service['url']) ) > for service in services])}} > {{pass}} > {{except Exception:}} > No profile > {{pass}} > </blockquote> > {{pass}} > > and then: > http://awesomescreenshot.com/0206eam01 > > [image: profilepage3.png] > > > > > Hope this can be usefull for somebody. > > Tell your users to register in gravatar.com > > > ---- > Bruno Rocha > http://about.me/rochacbruno/bio > http://en.gravatar.com/rochacbruno >

