<s> import datetime <EOL> from google . appengine . ext import ndb <EOL> MAX_PAY_TIME = <NUM_LIT:16> * <NUM_LIT> <EOL> def NOW ( ) : <EOL> return datetime . datetime . utcnow ( ) <EOL> class DecimalProperty ( ndb . PickleProperty ) : <EOL> pass <EOL> class MyInvoice ( ndb . Model ) : <EOL> """<STR_LIT>""" <EOL> created_at = ndb . DateTimeProperty ( auto_now_add = True ) <EOL> token = ndb . StringProperty ( indexed = True ) <EOL> amount = DecimalProperty ( required = True ) <EOL> amount_cct = ndb . StringProperty ( required = True ) <EOL> payable = DecimalProperty ( required = True ) <EOL> payable_cct = ndb . StringProperty ( choices = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> label = ndb . StringProperty ( ) <EOL> show_fiat = ndb . BooleanProperty ( ) <EOL> pubkey = ndb . StringProperty ( required = True ) <EOL> ck_refnum = ndb . StringProperty ( required = True ) <EOL> paid_at = ndb . DateTimeProperty ( default = None ) <EOL> @ classmethod <EOL> def recent_invoices ( cls ) : <EOL> return cls . query ( ) . order ( - cls . created_at ) <EOL> @ classmethod <EOL> def get_by_token ( cls , token_key ) : <EOL> return cls . query ( cls . token == token_key ) . get ( ) <EOL> def get_url ( self ) : <EOL> return '<STR_LIT>' % self . token <EOL> @ property <EOL> def has_no_conversion ( self ) : <EOL> return self . payable_cct == self . amount_cct <EOL> @ property <EOL> def is_expired ( self ) : <EOL> if self . has_no_conversion : return False <EOL> return ( NOW ( ) - self . created_at ) . total_seconds ( ) > MAX_PAY_TIME <EOL> @ property <EOL> def is_recent ( self ) : <EOL> return ( NOW ( ) - self . created_at ) . total_seconds ( ) < <NUM_LIT:30> <EOL> def get_time_left ( self ) : <EOL> if self . has_no_conversion : return MAX_PAY_TIME <EOL> return max ( <NUM_LIT:0> , MAX_PAY_TIME - ( NOW ( ) - self . created_at ) . total_seconds ( ) ) </s>
