<s> from django . contrib . auth import authenticate <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . sites . models import Site <EOL> from django . db import models <EOL> from socialregistration . signals import connect <EOL> class GoogleProfile ( models . Model ) : <EOL> user = models . ForeignKey ( User , unique = True ) <EOL> site = models . ForeignKey ( Site , default = Site . objects . get_current ) <EOL> google_id = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> def __unicode__ ( self ) : <EOL> try : <EOL> return u'<STR_LIT>' % ( self . user , self . google_id ) <EOL> except User . DoesNotExist : <EOL> return u'<STR_LIT:None>' <EOL> def authenticate ( self ) : <EOL> return authenticate ( google_id = self . google_id ) <EOL> class GoogleAccessToken ( models . Model ) : <EOL> profile = models . OneToOneField ( GoogleProfile , related_name = '<STR_LIT>' ) <EOL> access_token = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> def save_google_token ( sender , user , profile , client , ** kwargs ) : <EOL> try : <EOL> GoogleAccessToken . objects . get ( profile = profile ) . delete ( ) <EOL> except GoogleAccessToken . DoesNotExist : <EOL> pass <EOL> GoogleAccessToken . objects . create ( access_token = client . get_access_token ( ) , <EOL> profile = profile ) <EOL> connect . connect ( save_google_token , sender = GoogleProfile , <EOL> dispatch_uid = '<STR_LIT>' ) </s>
