本文整理汇总了Python中models.Account.get_or_insert方法的典型用法代码示例。如果您正苦于以下问题:Python Account.get_or_insert方法的具体用法?Python Account.get_or_insert怎么用?Python Account.get_or_insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Account
的用法示例。
在下文中一共展示了Account.get_or_insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: home
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import get_or_insert [as 别名]
def home():
user = users.get_current_user()
login_url = users.create_login_url(request.path)
if not user:
return respond('home.html', {'login_url':login_url, 'user':user})
account = None
warn_msg = None
success_msg = None
account = Account.get_or_insert(user.user_id(), user_id = user.user_id())
if not account.email: # ensure this is set on account creation
account.email = user.email()
if request.forms.get('update_sites'):
site_urls = [request.forms.get('site' + str(i)) for i in range(1,6) if request.forms.get('site' + str(i))]
account.sites = site_urls
account.put()
elif request.forms.get('stripeToken'):
if account.upgraded:
logging.info("User {} attempted to pay for an already-paid account".format(user.email()))
warn_msg = "This account appears to have already paid"
else:
charge, msg = stripe_pay(500,request.forms.get('stripeToken'), user)
if charge is not None:
success_msg = msg
chargejson = {'method':'Stripe', 'id': charge.id, 'created': charge.created, 'amount':charge.amount,
'type':charge.card.type, 'balance_transaction':charge.balance_transaction,
'description':charge.description}
account.payment_info = json.dumps(chargejson)
account.upgraded = True
account.put()
else:
warn_msg = msg
return respond('home.html', {'login_url':login_url, 'user':user, 'account':account, 'warn_msg':warn_msg, 'success_msg':success_msg})
示例2: get
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import get_or_insert [as 别名]
def get(self):
# Userモデルに未登録だったら登録する
user_obj = users.get_current_user()
account = Account.get_or_insert(
user_obj.user_id(),
owner = user_obj,
user_id = user_obj.user_id() )
# 画面表示
Viewer.generate(Viewer(), self.response, TEMPLATE_PATH, {} )
示例3: get
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import get_or_insert [as 别名]
def get(self):
"""Handles both legs of OAuth authorization. On the first request, the
user is redirected to Facebook to authorize our application, with this
same URL as the return point. On the second request, a verification
code is given which will allow us to get an access code which we can
use to get the user's profile info from Facebook."""
logging.info('Logging in via Facebook...')
# See if we got a verification code from Facebook (which will happen
# when the callback is hit after the user authorizes the app on
# Facebook)
code = self.request.get('code')
# Figure out if we've got a "next" destination
next = self.request.get('next')
# Get a Facebook object to work with
fb = Facebook(self.request.path_url)
# If not, we need to redirect them to Facebook to authorize us
if not code:
logging.info('Auth URL: %s' % fb.auth_url)
if next:
self.set_secure_cookie('next', next)
return self.redirect(fb.auth_url)
# If so, we need to use the verification code to get an access code,
# and use that to create/update a user account.
else:
access_token = fb.get_access_token(code)
assert access_token, 'No access token for code %s' % code
profile = fb.get_profile(access_token)
assert profile, 'No profile for token %s' % access_token
key_name = 'facebook:%s' % profile['id']
acc = Account.get_or_insert(
key_name,
email=profile['email'],
first_name=profile['first_name'],
last_name=profile['last_name'],
oauth_token=access_token)
self.set_secure_cookie(
'account', str(acc.key()), max_age=COOKIE_AGE)
next = self.get_secure_cookie('next')
if next:
self.delete_cookie('next')
return self.redirect(next)
else:
return self.redirect_to('index')