本文整理汇总了Python中models.Account.query方法的典型用法代码示例。如果您正苦于以下问题:Python Account.query方法的具体用法?Python Account.query怎么用?Python Account.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Account
的用法示例。
在下文中一共展示了Account.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_current_account
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def get_current_account():
"""Retrieve the Account entity associated with the current user."""
user = endpoints.get_current_user()
if user is None:
return None
email = user.email().lower()
# Try latest recorded auth_email first
accounts = Account.query(Account.auth_email == email).fetch(1)
if len(accounts) > 0:
return accounts[0]
# Try the user's default email next
accounts = Account.query(Account.email == email).fetch(1)
if len(accounts) > 0:
# Store auth email for next time
accounts[0].auth_email = email
accounts[0].put()
return accounts[0]
# Try via the user's Google ID
user_id = _getUserId()
accounts = Account.query(Account.gplus_id == user_id).fetch(1)
if len(accounts) > 0:
# Store auth email for next time
accounts[0].auth_email = email
accounts[0].put()
return accounts[0]
return None
示例2: test_Account_initialization
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def test_Account_initialization(self):
try:
Account().put()
self.assertEqual(1,2)
except BadValueError:
pass
try:
Account(username='Captain Blackbeard').put()
self.assertEqual(1,2)
except BadValueError:
pass
try:
Account(email='[email protected]').put()
self.assertEqual(1,2)
except BadValueError:
pass
# test contructor
Account(username='Captain BlackBeard', email='[email protected]').put()
self.assertEqual(1, len(Account.query().fetch(2)))
# test add new user
request = AccountRequest('First Mate', '[email protected]')
Account.add_new_user(request)
self.assertEqual(2, len(Account.query().fetch(3)))
示例3: get
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def get(self):
"""Create tasks."""
logging.info('crons/harvest_ga')
accounts = Account.query()
user_count = 0
for account in accounts:
# only process valid account types
if account.type not in VALID_ACCOUNT_TYPES:
continue
# uncomment this for testing against Mark's / Patrick's accounts
# Patrick
if account.gplus_id != "117346385807218227082":
# Mark
# if account.gplus_id != "115064340704113209584":
continue
user_count += 1
taskqueue.add(queue_name='gplus',
url='/tasks/harvest_ga',
params={'key': account.key.urlsafe()})
logging.info(
'crons/harvest_ga created tasks for {} users.'.format(user_count))
示例4: basicinfo
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def basicinfo(user, self):
if user:
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
nickname = user.nickname()
accounts = Account.query(Account.guser == user).fetch()
if len(accounts) == 0: # if no Account object exists for user
new_account = Account(
guser=user,
modules_completed=[],
projects_completed=[]
)
new_account.put()
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'
nickname = None
template_values = {
'title': config.SITE_NAME,
'url': url,
'url_linktext': url_linktext,
'nickname': nickname
}
return template_values
示例5: site_checks
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def site_checks():
account_query = Account.query()
for account in account_query.iter():
taskqueue.add(
url='/queue/site_check/{}'.format(account.user_id),
params={},
method="GET"
)
示例6: admin
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def admin():
users = list(User.query())
accounts = {}
for a in Account.query():
if a.user_id not in accounts:
accounts[a.user_id] = []
accounts[a.user_id].append(a)
return render_template('admin.html', **locals())
示例7: get_account
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def get_account():
user = users.get_current_user()
if user:
accounts = Account.query(Account.guser == user).fetch()
if len(accounts) > 0:
account = accounts[0]
return account
return None
示例8: get_account
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def get_account():
"""Return one account and cache account key for future reuse if needed"""
global _account_key
if _account_key:
return _account_key.get()
acc = Account.query().get()
_account_key = acc.key
return acc
示例9: account_page
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def account_page(request):
if request.method == 'POST':
aid=request.POST['aid']
aname=request.POST['aname']
accin= Account()
accin.aid=int(aid)
accin.aname=aname
accin.put()
return HttpResponseRedirect('/account')
if request.method == 'GET':
accout= Account.query(Account.aid>0).fetch()
return render(request, 'account.html',{'acc':accout})
示例10: summary
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def summary():
global symbols
user = request.args.get('user')
if user:
if not current_user.is_admin():
return 'WTF?'
if user:
user = User.query_one({'_id': user})
else:
user = current_user
accounts = list(Account.query({'user_id': user._id}))
ps = [p for p in
Position.query({'user_id': user._id},
sort=[('date', 1)])]
os = [o for o in
Order.query({'user_id': user._id},
sort=[('date', 1)])]
dates = list(reversed([p.date for p in ps]))
total_profit = 0
for o in os:
for oo in o.order_list:
if oo.symbol in symbols:
total_profit += oo.profit
today = request.args.get('today')
if today:
today = datetime.strptime(today, '%Y-%m-%d %H:%M:%S')
else:
d = datetime.utcnow() + timedelta(hours=8)
if d.hour == 9 and 20 <= d.minute <= 40:
return '跌零时间段, 不可查看'
if d.hour < 9:
d -= timedelta(days=1)
today = d.replace(hour=0, minute=0, second=0, microsecond=0)
try:
position_list = Position.query_one({'user_id': user._id,
'date': today}).position_list
status_list = Status.query_one({'user_id': user._id,
'date': today}).status_list
order_list = Order.query_one({'user_id': user._id,
'date': today}).order_list
except:
pass
locals()['symbols'] = symbols
return render_template('summary.html', **locals())
示例11: get
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def get(self):
user = users.get_current_user()
# check if there is an account
# use .get() because there should 1 record only
acct = Account.query(Account.userId == user.user_id()).get()
if not acct:
# create one
Account(name=user.nickname(), userId=user.user_id(), email= user.email()).put()
template = JINJA_ENVIRONMENT.get_template('upload.html')
self.response.out.write(template.render({}))
示例12: home
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def home(request):
#return http.HttpResponse('Hello World! A')
#return render(request, 'index.html')
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
instance=myurl(myurl="%s"%now,status='OK')
instance.put()
form = CommentForm(auto_id=False)
accout= Account.query(Account.aid>0).fetch()
message=Message.query().fetch()
nodeall=Nodeall.query(Nodeall.ntemp=='T').fetch()
total=dict(j=0,d=0)
for node in nodeall:
total['j']=total['j']+node.nd
total['d']=total['d']+node.nd
return render(request, 'index.html',{'form':form,'acc':accout,'message':message,'nodeall':nodeall,'total':total})
示例13: get_account
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def get_account(self):
user = users.get_current_user()
if user:
url = users.create_logout_url('/')
url_linktext = "Sign out"
# check if user in db
qry = Account.query()
acc = []
for x in qry:
if x.email == user.email():
acc = x
break
# if user not in db then add it
if not acc:
acc = Account(email = user.email())
acc.put()
return acc
示例14: test_account
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def test_account(self):
user = Account(username='Captain BlackBeard', email='[email protected]')
user.put()
self.assertEqual(1, len(Account.query().fetch(2)))
# test find by username
found_user = Account.find_by_username('Captain BlackBeard')
self.assertEqual(user, found_user, 'Failed to find user based on username')
# test update email
Account.update_email(user.key.id(), '[email protected]')
self.assertEqual('[email protected]',
Account.find_by_username('Captain BlackBeard').email,
'Failed to update email')
# test find by id
found_user = Account.find_by_id(user.key.id())
self.assertEqual(user, found_user, 'Failed to find user based on id')
示例15: get
# 需要导入模块: from models import Account [as 别名]
# 或者: from models.Account import query [as 别名]
def get(self):
"""Create tasks."""
logging.info('crons/new_gplus')
accounts = Account.query()
user_count = 0
for account in accounts:
# don't process admin users
if account.type == "administrator":
continue
# don't process inactive users
if account.type != "active":
continue
user_count += 1
taskqueue.add(queue_name='gplus',
url='/tasks/new_gplus',
params={'gplus_id': account.gplus_id})
logging.info('crons/new_gplus created tasks for %s users' % user_count)