本文整理汇总了Python中models.Room.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Room.get_by_key_name方法的具体用法?Python Room.get_by_key_name怎么用?Python Room.get_by_key_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Room
的用法示例。
在下文中一共展示了Room.get_by_key_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import get_by_key_name [as 别名]
def __init__(self, request):
user = users.get_current_user()
room_key = request.get('room_id')
if not room_key:
room_key = request.get('g') #TODO - Remove with old page
if user and room_key:
self.room = Room.get_by_key_name(room_key)
示例2: get
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import get_by_key_name [as 别名]
def get(self):
user = users.get_current_user()
if user:
room_key = self.request.get('g')
if not room_key:
room_key = user.user_id()
room = Room(key_name = room_key,
current_user = user)
room.put()
else:
if room_key == "vr":
self.redirect("/vr-room")
return
if room_key == "demo":
self.redirect("/demo")
return
room = Room.get_by_key_name(room_key)
if room:
#Check if the crowdee already exists for this user and room.
crowdeeQuery = Crowdee.all()
crowdeeQuery.filter("user =", user)
crowdeeQuery.filter("room =", room_key)
crowdee = crowdeeQuery.get()
#If the crowdee doesn't exist...
if not crowdee:
#Create the crowdee for the user and room.
crowdee = Crowdee(user = user,
room = room_key,
channel = room_key + "_" + user.user_id(),
direction = "None",
weight = 1)
crowdee.put()
token = channel.create_channel(room_key + "_" + user.user_id())
template_values = {'token': token,
'current_user_id': user.user_id(),
'room_key': room_key,
'weight': 1,
'initial_message': RoomUpdater(room).get_room_message()
}
#Add tokbox tokens if they exist.
if room.session_id:
template_values.update({'tokbox_api_key': tokbox_api_key,
'tokbox_session_id': room.session_id,
'tokbox_token': room.sub_token
})
template = jinja_environment.get_template('nav-room-base.html')
self.response.out.write(template.render(template_values))
else:
self.response.out.write('No such room')
else:
self.redirect(users.create_login_url(self.request.uri))
示例3: post
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import get_by_key_name [as 别名]
def post(self):
channel_token = self.request.get('from')
user_crowd = Crowdee.all().filter("channel =", channel_token)
#Although there should only be one user, it will still be received as a list.
for user_crowdee in user_crowd:
room = Room.get_by_key_name(user_crowdee.room)
user_id = user_crowdee.user.user_id()
user_crowdee.delete()
if room:
RoomUpdater(room).delete_move(user_id)
room_list = Room.all()
for room in room_list:
if room.key().name() == channel_token:
room.active = False
room.put()
示例4: put
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import get_by_key_name [as 别名]
def put(self):
"""Used by the crowdee to enter the existing room information."""
user = users.get_current_user()
if not user:
#Handle the user not being logged in. TODO
return
#Get the room.
room_key = self.request.get('room_id')
room = Room.get_by_key_name(room_key)
if not room:
#Handle the room not existing.
return
#Check if the crowdee already exists for this user and room.
crowdeeQuery = Crowdee.all()
crowdeeQuery.filter("user =", user)
crowdeeQuery.filter("room =", room_key)
crowdee = crowdeeQuery.get()
#If the crowdee doesn't exist...
if not crowdee:
#Create the crowdee for the user and room.
crowdee = Crowdee(user = user,
room = room_key,
channel = room_key + "_" + user.user_id(),
direction = "None",
weight = 1)
crowdee.put()
token = channel.create_channel(room_key + "_" + user.user_id())
#Compile the crowdee data.
crowdee_data = {
'channel_token': token,
'user_id': user.user_id(),
'user_name': user.nickname(),
'room_key': room_key,
'user_weight': 1,
'tokbox_api_key': tokbox_api_key,
'tokbox_session_id': room.session_id,
'tokbox_token': room.sub_token,
}
#Respond with the json.
self.response.out.write(json.dumps(crowdee_data))