<s> from __future__ import absolute_import , division , print_function <EOL> from google . appengine . ext import ndb <EOL> class AppC ( ndb . Model ) : <EOL> grant_user = ndb . IntegerProperty ( ) <EOL> serial = ndb . StringProperty ( ) <EOL> status = ndb . IntegerProperty ( default = <NUM_LIT:0> ) <EOL> created_at = ndb . DateTimeProperty ( auto_now_add = True ) <EOL> updated_at = ndb . DateTimeProperty ( auto_now = True ) <EOL> @ classmethod <EOL> def grant ( cls , developer_id ) : <EOL> codes = cls . query ( cls . grant_user == developer_id ) . fetch ( <NUM_LIT:1> ) <EOL> if codes : <EOL> return codes [ <NUM_LIT:0> ] <EOL> codes = cls . query ( cls . status == <NUM_LIT:0> ) . fetch ( <NUM_LIT:1> ) <EOL> if not codes : <EOL> return None <EOL> code = codes [ <NUM_LIT:0> ] <EOL> code . grant_user = developer_id <EOL> code . status = <NUM_LIT:1> <EOL> code . put ( ) <EOL> return code <EOL> @ classmethod <EOL> def batch_import ( cls , serials ) : <EOL> codes = [ ] <EOL> for serial in serials : <EOL> appc_key = ndb . Key ( cls , serial ) <EOL> codes . append ( AppC ( serial = serial , key = appc_key ) ) <EOL> ndb . put_multi ( codes ) <EOL> @ classmethod <EOL> def get_list ( cls , page = <NUM_LIT:0> ) : <EOL> COUNT = <NUM_LIT:100> <EOL> offset = page * COUNT <EOL> return cls . query ( ) . order ( cls . status ) . fetch ( COUNT , offset = offset ) </s>
