本文整理汇总了Python中model.user.User.query方法的典型用法代码示例。如果您正苦于以下问题:Python User.query方法的具体用法?Python User.query怎么用?Python User.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.user.User
的用法示例。
在下文中一共展示了User.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_dict
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def to_dict(self):
one_q = User.query(User.user_id == self.friend_1)
friend_1_nickname = one_q.get().nickname
two_q = User.query(User.user_id == self.friend_2)
friend_2_nickname = two_q.get().nickname
return {
'friends_id': self.key.urlsafe(),
'friend_1': self.friend_1,
'friend_1_nickname': friend_1_nickname,
'friend_2': self.friend_2,
'friend_2_nickname': friend_2_nickname,
'creation_date': str(self.creation_date)
}
示例2: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def get(self):
user = users.get_current_user()
if not self.request.get('user_id'):
self.error(400)
return
if not user:
self.error(401)
return
# Check if user is requesting data of someone else
if self.request.get('user_id') is not user.user_id() and not users.is_current_user_admin():
self.error(401)
return
# Check that there exists a user with the specified user_id
user_qry = anna_user.query(anna_user.user_id == self.request.get('user_id'))
if not user_qry.count() > 0:
self.error(404)
return
# Query the database for the friend request that correspond to this user
request_qry = anna_friend_request.query(anna_friend_request.receiver_id == self.request.get('user_id')).order(-anna_friend_request.creation_date)
requests = request_qry.fetch()
# Make a list of the friend requests
reqs = []
for request in requests:
reqs.append(request.to_dict())
# Send the the friend requests in json
self.response.headers['Content-type'] = 'application/json'
self.response.out.write(json.dumps(reqs))
示例3: join
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def join(self, gid):
query = Game.query(Game.gid == gid)
name = self.getPOSTorRandom('username', User)
# Look for the game
if query.count() != 1:
self.stderr('Unknown Game')
else:
game = query.fetch(1)[0]
if game.running:
self.stderr('Game has started')
elif len(game.members) >= game.maxPlayers:
self.stderr('The maximum number of players has been reached')
elif User.query(User.name==name, User.gid==gid).count() != 0:
self.stderr('Username already exists')
else:
sid = self.join_game(game, name)
game.put()
self.json['status'] = 'joined'
# Not sure why either of these are needed
self.json['token'] = game.gid
self.json['session'] = sid
示例4: attack
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def attack(self, city, num):
if not self.checkLogin(): return
query = User.query(User.uid==city)
num = int(num)
self.user.updateValues()
if self.user.military == False:
self.stderr('You don\'t have military building')
elif self.user.peopleAtMilitary < num:
self.stderr('You don\'t have enough people to attack')
elif query.count() != 1:
self.stderr('Attacking City doesn\'t exist')
else:
user = query.fetch()[0]
queueO = Queue(queueType = Queue.TYPE_ATTACK)
queueO.attackTo = user.uid
queueO.number = num
self.user.addQueue(queueO, 20)
self.user.peopleAtMilitary -= num
self.user.put()
queueO.put()
self.json = {
"status" : "sent",
"time" : 20
}
示例5: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def get(self):
user = users.get_current_user()
if user:
# Update the last login attribute if user exists already
qry = anna_user.query(anna_user.user_id == user.user_id())
if qry.count() > 0:
queried_user = qry.fetch()[0]
queried_user.last_login = datetime.datetime.now()
queried_user.put()
# Create logout url
logout_url = users.create_logout_url('/')
template_values = {
'user': user,
'logout_url': logout_url,
}
# Feed the template to the user
template = JINJA_ENVIRONMENT.get_template('template/index.html')
self.response.write(template.render(template_values))
else:
# Redirect the user to login page
login_url = users.create_login_url('/')
self.redirect(login_url)
return
示例6: get_game
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def get_game(self, gid):
query = Game.query(Game.gid == gid)
# Look for the game
if query.count() != 1:
self.stderr('Unknown Game')
else:
game = query.fetch(1)[0]
self.json['status'] = 'running' if game.running else 'waiting'
self.json['full'] = (len(game.members) >= game.maxPlayers)
self.json['users'] = game.members
if game.running and self.checkLogin(False):
self.json['game'] = { }
self.json['game']['data'] = {
'status' : 'running' if game.running else 'waiting',
'token' : game.gid,
'secret' : self.user.secret
}
self.json['player'] = self.user.toDict()
self.json['game']['maps'] = {
"world" : Map(game.gmap).toDict(),
"city" : Map(self.user.homeMap).toDict()
}
self.json['game']['maps']['world']['players'] = { }
for user in User.query(User.gid == game.gid).fetch():
self.json['game']['maps']['world']['players'][user.uid] = {
"id" : user.uid,
"name" : user.name,
"level" : user.level
}
示例7: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def get(self):
query_id = self.request.get('user_id')
current_user = users.get_current_user()
# Check if user is logged in
if current_user:
# Respond with 400 if user_id is not provided in get
if not query_id:
self.error(400)
return
# Only allow self and admins to query user information
if current_user.user_id() == query_id or users.is_current_user_admin():
# Query the current user from the database
qry = anna_user.query(anna_user.user_id == query_id)
# If current user is admin and there are no results return 404
if qry.count() == 0 and users.is_current_user_admin():
# Create admin user in database if he doesn't exist at the moment
qry = anna_user.query(anna_user.user_id == current_user.user_id())
if qry.count() == 0:
create_new_user(current_user)
# Raise the error and stop execution
self.error(404)
return
# Create a new user in the database if we have no results
if qry.count() == 0:
queried_user = create_new_user(current_user)
# Fetch the current user if it exists
else:
queried_user = qry.fetch()[0]
# Send the users data in json
self.response.headers['Content-type'] = 'application/json'
self.response.out.write(json.dumps(queried_user.to_dict()))
# If current user is asking for not self and is not admin
else:
self.error(401)
# If user is not logged in we respond with 401 (Unauthorized)
else:
self.error(401)
示例8: to_dict
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def to_dict(self):
# Poster nickname query
user_qry = anna_user.query(anna_user.user_id == self.user_id)
user_nickname = user_qry.get().nickname
return {
'comment_id': self.key.urlsafe(),
'poster_nickname': user_nickname,
'post_id': self.post_id,
'content': self.content,
'creation_date': str(self.creation_date)
}
示例9: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def post(self):
isUser = User.query(User.username == self.request.get('username')).get()
if((isUser is None) and (self.request.get('confirm') == self.request.get('password')) and validation(self.request.get('email'))):
hashsum = hashlib.md5(self.request.get('password')).hexdigest()
users = User(username = self.request.get('username'),
password=hashsum )
users.put()
return webapp2.redirect('/')
else:
templatevalues = {
'user_log' : checkcookies(self),
}
template = jinja_environment.get_template('error.html')
self.response.out.write(template.render({'templatevalues':templatevalues}))
示例10: cron
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def cron(self):
for user in User.query(User.positionOnMap != None).fetch():
user.updateValues()
immigrants = \
random.randrange(-2.0, 2.0) / 10.0 \
+ user.satisfactionRate()
immigrants = int(immigrants)
if immigrants < -1 * user.peopleAtHome:
immigrants = -1 * user.peopleAtHome
user.peopleAtHome += immigrants
user.put()
self.sendMessageTo(user, 'receiveDailyStatistics', {"gold":user.gold, "people":user.peopleAtHome})
示例11: send
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def send(self, city, num):
self.json = {
"action" : "send",
"city" : city,
"num" : num
}
if self.user.military == False:
self.stderr('You don\'t have military building')
elif self.user.peopleAtMilitary < num:
self.stderr('You don\'t have enough people')
else:
user = User.query(User.uid==city).fetch()[0]
user.peopleAtMilitary += num
self.user.peopleAtMilitary -= num
self.user.put()
user.put()
示例12: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def post(self):
user = users.get_current_user()
if not user:
self.abort(401)
# Try to use the ticket if an id is provided
if self.request.get("ticket_code"):
ticket = anna_ticket.query(anna_ticket.ticket_code == self.request.get("ticket_code")).get()
if not ticket:
self.abort(404)
# Query the current user
ticket_user = anna_user.query(anna_user.user_id == user.user_id()).get()
if not ticket_user:
self.abort(401)
ticket_user.credit += ticket.value
ticket_user.put()
ticket.key.delete()
self.response.set_status(204)
return
# Try to create a ticket from provided JSON
else:
if not users.is_current_user_admin():
self.abort(401)
try:
new_ticket = json.loads(self.request.body)
if 'ticket_code' not in new_ticket or 'value' not in new_ticket:
raise KeyError
if (int(new_ticket['value']) > 0) is False:
raise KeyError
except Exception, e:
self.abort(400)
db_ticket = anna_ticket(ticket_code = new_ticket['ticket_code'], value = new_ticket['value'])
db_ticket.put()
self.response.headers['Content-type'] = 'application/json'
self.response.out.write(json.dumps(db_ticket.to_dict()))
示例13: to_dict
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def to_dict(self):
user = User.query(User.user_id == self.user_id).get()
return {
'project_id': self.key.urlsafe(),
'user_nickname': user.nickname,
'title': self.title,
'description': self.description,
'img': self.img,
'category': self.category,
'tags': self.tags,
'location': self.location,
'collected_amount': self.collected_amount,
'requested_amount': self.requested_amount,
'due_date': str(self.due_date),
'creation_date': str(self.creation_date),
}
示例14: start
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def start(self, gid):
# You must be the owner of a game to start it, so we should
# check if they are loged on
if not self.checkLogin(): return
query = Game.query(Game.gid == gid)
if query.count() != 1:
self.stderr('Unknown Game')
else:
game = query.fetch(1)[0]
if game.owner != self.user.uid:
self.stderr('You are not authorised to start this game')
else:
game.running = True
savedCMap = None
# Pick places for each of the players and set their
# lastUpdated value to the start of the game so they can
# load resources
mapObj = Map(game.gmap)
for user in User.query(User.gid == game.gid).fetch():
cMap = Map.generateCityMap()
user.positionOnMap = mapObj.pickRandomTile(user)
user.lastUpdated = datetime.datetime.now()
user.homeMap = cMap.toString()
user.put()
if user.uid == self.user.uid:
savedCMap = cMap
game.gmap = mapObj.toString()
game.put()
self.json['game'] = { }
self.json['game']['data'] = {
"status" : 'started',
"token" : game.gid
}
self.json['player'] = self.user.toDict()
self.json['game']['maps'] = {
"world" : mapObj.toDict(),
"city" : cMap.toDict()
}
示例15: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import query [as 别名]
def post(self):
email = self.request.get('email')
pw = self.request.get('pw')
user = User.query(User.email == email).get()
if user:
validPw = User.verifyPw(pw, user.pwHash)
if validPw:
createSecureCookie(
self.response,
str(user.key.id()) + str(user.created),
user.tag
)
self.redirect('/feed')
else:
self.error(400)
else:
self.error(400)