本文整理匯總了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))