def get(self): user = users.get_current_user() if user == None: self.redirect("/") else: # Look for the user's information user_id = user.user_id() name_info = user.nickname() stored_user = User.query(User.id_user == user_id) if stored_user.count() == 0: # Store the information img = User(id_user=user_id, name=name_info) img.put() time.sleep(1) accounts = Account.query(Account.id_user == user_id).order(Account.name) template_values = { 'title': "Accounts", 'accounts': accounts, 'user_nickname': user.nickname(), 'user_logout': users.create_logout_url("/"), 'user_id': user.user_id() } template = JINJA_ENVIRONMENT.get_template("accounts.html") self.response.write(template.render(template_values));
def CountRemaining(futurekey, cursor): logging.debug("Got here") accounts, cursor, kontinue = Account.query().fetch_page( 100, start_cursor=cursor) numaccounts = len(accounts) if kontinue: lonallchildsuccessf = GenerateOnAllChildSuccess( futurekey, numaccounts, lambda a, b: a + b) future(CountRemaining, parentkey=futurekey, queue="background", onallchildsuccessf=lonallchildsuccessf)(cursor) logging.debug("raising") setlocalprogress(futurekey, numaccounts) if kontinue: raise FutureReadyForResult("still calculating") else: logging.debug("leaving") return numaccounts
def AddFreeCredit(creditamount): def IncrementBalance(account, headers): # headers = kwargs.get("headers") logging.debug("headers: %s" % headers) account.balance += creditamount account.put() ndbshardedmap(IncrementBalance, Account.query(), includeheaders = True)
def AddFreeCredit(creditamount): def IncrementBalance(futurekey, account): account.balance += creditamount account.put() return 1 futureobj = futurendbshardedmap(IncrementBalance, Account.query(), queue="background") return futureobj.key
def ProcessOnePage(cursor): accounts, cursor, kontinue = Account.query().fetch_page( 100, start_cursor=cursor) for account in accounts: account.balance += creditamount ndb.put_multi(accounts) if kontinue: ProcessOnePage(cursor)
def Go(): def DeleteAccount(account): account.key.delete() ndbshardedmap(DeleteAccount, ndbquery=Account.query())