<s> """<STR_LIT>""" <EOL> import urllib <EOL> import datetime <EOL> from django . db import models <EOL> from django . conf import settings <EOL> from base import Object , Principal , APP_LABEL <EOL> class Share ( Object ) : <EOL> """<STR_LIT>""" <EOL> record = models . ForeignKey ( '<STR_LIT>' , related_name = '<STR_LIT>' , null = True ) <EOL> with_app = models . ForeignKey ( <EOL> '<STR_LIT>' , related_name = '<STR_LIT>' , null = True ) <EOL> authorized_at = models . DateTimeField ( null = True , blank = True ) <EOL> authorized_by = models . ForeignKey ( <EOL> '<STR_LIT>' , null = True , related_name = '<STR_LIT>' ) <EOL> offline = models . BooleanField ( default = False ) <EOL> class Meta : <EOL> app_label = APP_LABEL <EOL> unique_together = ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , ) <EOL> def new_access_token ( self , token_str , token_secret ) : <EOL> """<STR_LIT>""" <EOL> expires_at = datetime . datetime . utcnow ( <EOL> ) + datetime . timedelta ( minutes = <NUM_LIT> ) <EOL> return AccessToken . objects . create ( <EOL> token = token_str , <EOL> token_secret = token_secret , <EOL> share = self , <EOL> expires_at = expires_at <EOL> ) <EOL> class Token ( object ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> vars = { <EOL> '<STR_LIT>' : self . token , <EOL> '<STR_LIT>' : self . token_secret <EOL> } <EOL> return urllib . urlencode ( vars ) <EOL> @ property <EOL> def secret ( self ) : <EOL> return self . token_secret <EOL> to_string = __str__ <EOL> class AccessToken ( Principal , Token ) : <EOL> token = models . CharField ( max_length = <NUM_LIT> ) <EOL> token_secret = models . CharField ( max_length = <NUM_LIT> ) <EOL> expires_at = models . DateTimeField ( null = True ) <EOL> share = models . ForeignKey ( '<STR_LIT>' ) <EOL> smart_connect_p = models . BooleanField ( default = False ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> self . email = "<STR_LIT>" % self . token <EOL> super ( AccessToken , self ) . save ( * args , ** kwargs ) <EOL> @ property <EOL> def effective_principal ( self ) : <EOL> return self . share . with_app <EOL> def __str__ ( self ) : <EOL> vars = { <EOL> '<STR_LIT>' : self . token , <EOL> '<STR_LIT>' : self . token_secret <EOL> } <EOL> if ( self . share . record is not None ) : <EOL> vars [ '<STR_LIT>' ] = self . share . record . id <EOL> if ( self . share . authorized_by is not None ) : <EOL> vars [ '<STR_LIT>' ] = self . share . authorized_by . id <EOL> return urllib . urlencode ( vars ) <EOL> to_string = __str__ <EOL> @ property <EOL> def secret ( self ) : <EOL> return self . token_secret <EOL> @ property <EOL> def passalong_params ( self ) : <EOL> c = { } <EOL> c [ '<STR_LIT>' ] = settings . SITE_URL_PREFIX <EOL> c [ '<STR_LIT>' ] = self . token <EOL> c [ '<STR_LIT>' ] = self . secret <EOL> c [ '<STR_LIT>' ] = self . share . authorized_by . email <EOL> c [ '<STR_LIT>' ] = self . share . with_app . email <EOL> if self . share . record : <EOL> c [ '<STR_LIT>' ] = self . share . record . id <EOL> return c <EOL> class ReqToken ( Principal , Token ) : <EOL> token = models . CharField ( max_length = <NUM_LIT> ) <EOL> token_secret = models . CharField ( max_length = <NUM_LIT> ) <EOL> verifier = models . CharField ( max_length = <NUM_LIT> ) <EOL> oauth_callback = models . CharField ( max_length = <NUM_LIT> , null = True ) <EOL> app = models . ForeignKey ( '<STR_LIT>' ) <EOL> record = models . ForeignKey ( '<STR_LIT>' , null = True ) <EOL> authorized_at = models . DateTimeField ( null = True ) <EOL> authorized_by = models . ForeignKey ( <EOL> '<STR_LIT>' , null = True , related_name = "<STR_LIT>" ) <EOL> share = models . ForeignKey ( '<STR_LIT>' , null = True ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> self . email = "<STR_LIT>" % self . token <EOL> super ( ReqToken , self ) . save ( * args , ** kwargs ) <EOL> @ property <EOL> def effective_principal ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . app <EOL> @ property <EOL> def authorized ( self ) : <EOL> return self . authorized_at is not None </s>
