本文整理汇总了Python中models.Room类的典型用法代码示例。如果您正苦于以下问题:Python Room类的具体用法?Python Room怎么用?Python Room使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Room类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self, room_id):
room = Room(room_id)
if not room.exists():
self.redirect('/')
self.render("views/room.html", video_key=room.get_video_id(),
user_email=create_signed_value(APPLICATION['cookie_secret'], 'user_email', self.current_user.email),
user_token=create_signed_value(APPLICATION['cookie_secret'], 'user_token', self.current_user.token))
示例2: post_ad
def post_ad(state="available"):
is_available = state == "available"
if is_available:
form = AvailableAdForm()
else:
form = WantedAdForm()
form.starting.flags.is_date = True
if request.method == "GET":
form.email.data = g.user.email
if form.validate_on_submit():
room = Room(user=g.user, is_available=is_available)
if room.is_available:
form.room_pref.data = product(form.room_pref.data)
else:
form.room_type.data = product(form.room_type.data)
form.populate_obj(room)
room.urlname = str(uuid4())[:8]
db.session.add(room)
db.session.commit()
# Search for matching rooms
rooms_distance = Room.search_rooms(room)
# Send emails to interested users
for r, distance in rooms_distance:
if room.is_available: # ad poster is looking for a person
send_email_found_room(r.user, room, distance)
else: # ad poster is looking for a room.
send_email_found_person(r.user, room, distance)
flash("Your ad has been posted!", category="info")
return render_template("found.html", room=room, rooms_distance=rooms_distance)
return render_template("autoform.html", form=form, title="Post a new advertisement", submit="Post ad")
示例3: post
def post(self):
"""Used by the host to create the room."""
user = users.get_current_user()
if not user:
#Handle the user not being logged in. TODO
return
#Setup tokbox tokens.
tokbox_session_id = opentok_sdk.create_session().session_id
tokbox_token = opentok_sdk.generate_token(tokbox_session_id)
sub_tokbox_token = opentok_sdk.generate_token(tokbox_session_id, OpenTokSDK.RoleConstants.SUBSCRIBER)
#Create the room.
room_key = user.user_id()
room = Room(key_name = room_key,
current_user = user,
session_id = tokbox_session_id,
pub_token = tokbox_token,
sub_token = sub_tokbox_token
)
room.put()
#Create the channel token.
token = channel.create_channel(room_key)
#Respond with room information.
room_data = {'token': token,
'tokbox_api_key': tokbox_api_key,
'tokbox_session_id': tokbox_session_id,
'tokbox_token': tokbox_token,
'room_key': room_key,
'initial_message': RoomUpdater(room).get_room_message_for_room(),
}
self.response.out.write(json.dumps(room_data))
示例4: get
def get(self):
user = users.get_current_user()
#Redirect the user if they aren't logged in.
if not user:
self.redirect(users.create_login_url(self.request.uri))
return
#Setup tokbox tokens.
tokbox_session_id = opentok_sdk.create_session().session_id
tokbox_token = opentok_sdk.generate_token(tokbox_session_id)
sub_tokbox_token = opentok_sdk.generate_token(tokbox_session_id, OpenTokSDK.RoleConstants.SUBSCRIBER)
#Create the room.
room_key = user.user_id()
room = Room(key_name = room_key,
current_user = user,
session_id = tokbox_session_id,
pub_token = tokbox_token,
sub_token = sub_tokbox_token
)
room.put()
#Display the template.
token = channel.create_channel(room_key)
template_values = {'token': token,
'tokbox_api_key': tokbox_api_key,
'tokbox_session_id': tokbox_session_id,
'tokbox_token': tokbox_token,
'room_key': room_key,
'initial_message': RoomUpdater(room).get_room_message_for_room(),
}
template = jinja_environment.get_template('nav-pub-with-playback.html')
self.response.out.write(template.render(template_values))
示例5: handlefbrequestcallback
def handlefbrequestcallback(request):
fp = open( 'tmp.3.log', 'w' )
print >> fp, request
request_str = ( request.GET.get('request') )
request_to = ( request.GET.get('to') )
#request_from = ( request.GET.get('from') )
request_id = ( request.GET.get('id') )
request_from = request.session['fb_id']
#if request_to:
# request_to = int(request_to.encode('ascii'))
#if request_from:
# request_from = int(request_from.encode('ascii'))
#if request_id:
# request_id = int(request_id.encode('ascii'))
print >> fp, "request id", request_id
print >> fp, "request string", request_str
print >> fp, "request to", request_to
print >> fp, "request from", request_from
print >> fp, "request fb id", request.session['fb_id']
try:
m_to = Member.objects.get(fb_id=request_to)
except:
# need to make member
m_to = Member(fb_id=request_to)
try:
m_from = Member.objects.get(fb_id=request_from)
except:
# need to make member
m_from = Member(fb_id=request_from)
# name is set
gamename = "%s_%s_%s" % ( request_from, request_to, time.asctime(time.gmtime()) )
r = Room(name=gamename)
r.fb_request_id = request_id
r.save()
g = Game(room=r)
# game name and room name duplicated
g.name = gamename
g.save()
p = Player(game=g,turn=0)
p.member = m_from
p.save()
# TODO assumes two player game - generalize
p = Player(game=g,turn=1)
p.member = m_to
p.save()
#return HttpResponseRedirect('requestpage.html')
return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
示例6: createRoom
def createRoom(request):
if request.method == "POST":
req = json.loads(request.body)
master = Trainer.objects.get(name=req['trainer'])
new_room = Room(master=master)
new_room.save()
response_data = {}
response_data['msg'] = 'success'
response_data['channel'] = new_room.id
return HttpResponse(json.dumps(response_data), content_type="application/json")
示例7: create_room
def create_room(request, extra_context={}):
"""
View for creating a room. Uses a clever combination of PollForm, RoomForm and ChoiceFormSet to achieve
3-way model creation:
- PollForm allows the user to specify the question
- ChoiceFormSet allows the user to specify an arbitrary number of "choices" to go with the question
(each one represented by its own DB object)
- RoomForm gives more advanced "tweaks" for the room, for example:
- period length (how long each period lasts, default is 30)
- join threshold (the amount of time that a room is in lock mode before a poll begins)
"""
if request.method == "POST":
# if the user has submitted the form, get the data from all three
poll_form = PollForm(request.POST, request.FILES)
choice_formset = ChoiceFormSet(request.POST, request.FILES)
room_form = RoomForm(request.POST, request.FILES)
if poll_form.is_valid() and choice_formset.is_valid() and room_form.is_valid():
# if all 3 forms are valid, create a new question object and save it
q = Question(text=poll_form.cleaned_data['question'])
q.save()
# create a new poll object that points to the question, and save it
p = Poll(question=q)
p.save()
# for every choice the user has inputted
for form in choice_formset.forms:
# create a new choice object, and point it at the question created earlier
c = Choice(question=q, text=form.cleaned_data['choice'])
c.save()
# finally, create the room itself, pointing to the question object, with the creator of the
# currently logged in user, and the period length & join threshold as specified in the form
# data.
r = Room(question=q, opened_by=request.user, controller=request.user,
period_length=room_form.cleaned_data['period_length'],
join_threshold=room_form.cleaned_data['join_threshold'])
r.save()
# redirect the user to their newly created room
return HttpResponseRedirect(r.get_absolute_url())
else:
# if the user has not submitted the form (i.e. wishes to fill the form in)
# then initialise the 3 forms with no data
poll_form = PollForm()
choice_formset = ChoiceFormSet()
room_form = RoomForm()
# put the forms into a context dictionary (and update that with any extra context we have been given)
data = {'poll_form': poll_form, 'choice_formset': choice_formset, 'room_form': room_form}
data.update(extra_context)
# render the page
return render_to_response('rooms/room_form.html', data, context_instance=RequestContext(request))
示例8: submitRoom
def submitRoom(request):
if request.method == "POST":
f = RoomForm(request.POST)
if f.is_valid():
newRoom = Room(name=request.POST['name'], info=request.POST['info'])
newRoom.save()
return HttpResponseRedirect(reverse('juakstore:roomDetail', args=(newRoom.id,)))
else:
return render(request, 'juakstore/room_add.html', {'form' : f})
else:
return HttpResponseRedirect(reverse('juakstore:roomCreate'))
示例9: post
def post(self):
user = users.get_current_user()
if user is None:
login_url = users.create_login_url('/home')
template_data = {}
template_data['login_url'] = login_url
template = JINJA_ENVIRONMENT.get_template('login.html')
self.response.write(template.render(template_data))
return
residence = Residence.get_residence_by_user(user)
category = self.request.get('category')
name = self.request.get('name')
price = self.request.get('price')
room_name = self.request.get("room")
if name.strip() == '' or category.strip() == '':
if room_name == "miscellaneous":
self.redirect("home")
else:
self.redirect("/room-tour?room=" + urllib.quote(room_name))
return
price = float(price)
inventory = Inventory.get_inventory_by_user(user)
item = Item(category=category, name=name, price=price, parent=inventory.key)
item.put()
residence = Residence.get_residence_by_user(user)
room = Room.query(ancestor=residence.key).filter(Room.name==room_name).get()
if room is None:
room = Room(name=room_name, parent=residence.key)
room.put()
relation = ItemRoomRelation(item=item.key, room=room.key, parent=inventory.key)
relation.put()
if room_name == "miscellaneous":
self.redirect("/home")
return
self.redirect("/room-tour?room=" + urllib.quote(room_name))
示例10: get
def get(self):
user = users.get_current_user()
if user is None:
login_url = users.create_login_url('/welcome')
self.response.write('<html><body>{}</body></html>'.format('<a href="' + login_url + '">Sign in</a>'))
return
residence = Residence.get_residence_by_user(user)
inventory = Inventory.get_inventory_by_user(user)
other_homes = Residence.query(Residence.own==residence.own).fetch()
logging.error(other_homes)
rooms = []
for home in other_homes:
rooms += Room.query(ancestor=home.key).filter(Room.name!="miscellaneous").fetch()
room_count = {}
for room in rooms:
name = room.name
if name in room_count:
room_count[name] += 1
continue
room_count[name] = 1
room_count_final = {}
for room in room_count:
my_count = Room.query(ancestor=residence.key).filter(Room.name==room).count()
if my_count == 0:
room_count_final[str(room)] = ("", room_count[room] / max(len(other_homes), 1))
else:
up_count = str(my_count + 1)
my_tail = ""
if up_count[-1:] in ["0", "4", "5", "6", "7", "8", "9"]:
my_tail = "th"
elif up_count[-1:] in ["2"]:
my_tail = "nd"
elif up_count[-1:] in ["1"]:
my_tail = "st"
elif up_count[-1:] in ["3"]:
my_tail = "rd"
room_count_final[str(room)] = (" (" + up_count + my_tail + ")", room_count[room] / max(len(other_homes), 1) - 2 * my_count)
room_count_final = sorted(room_count_final.items(), key=lambda x: x[1][1], reverse=True)
template = JINJA_ENVIRONMENT.get_template('tourRoomPage.html')
template_data = {'rooms': room_count_final}
self.response.write(template.render(template_data))
示例11: makerobogame
def makerobogame(request):
fb_id = ROBOT1
request.session['fb_id'] = fb_id
# make robot player 1
try:
m_from = Member.objects.get( fb_id=ROBOT1 )
except Member.DoesNotExist:
m_from = Member(fb_id=ROBOT1)
m_from.user_name = 'Robo1'
m_from.fb_first_name = 'Robo1'
m_from.fb_last_name = 'Robo1'
m_from.save()
# make robot player 2
try:
m_to = Member.objects.get( fb_id=ROBOT2 )
except Member.DoesNotExist:
m_to = Member(fb_id=ROBOT2)
m_to.user_name = 'Robo2'
m_to.fb_first_name = 'Robo2'
m_to.fb_last_name = 'Robo2'
m_to.save()
# name is set
request_from = 'Robo1'
request_to = 'Robo2'
gamename = "%s_%s_%s" % ( request_from, request_to, time.asctime(time.gmtime()) )
r = Room(name=gamename)
r.fb_request_id = ROBOREQUEST
r.save()
g = Game(room=r)
# game name and room name duplicated
g.name = gamename
g.save()
p = Player(member=m_from) # player in game, link to member
p.game=g # game
p.turn=0 # static order of player in game
p.save()
request.session['player_id'] = p.turn
# TODO assumes two player game - generalize
p = Player( member = m_to )
p.game=g
p.turn=1
p.save()
return HttpResponse( simplejson.dumps( { "gamename": gamename } ), mimetype='application/javascript' )
示例12: optionnal_room
def optionnal_room(sender, **kwargs):
reservation = kwargs.pop('instance')
if not isinstance(reservation, Reservation):
return True
if not reservation.room:
try:
room = Room._default_manager.get(name='default')
except Room.DoesNotExist:
room = Room(name='default', slug='default')
room.save()
reservation.room = room
return True
示例13: put
def put(self, request, roomId, memberId, *args, **kwargs):
user = fetch_user(request)
if memberId != user.strId:
return errors.PERMISSION_DENIED
room = Room.find_by_id(str(roomId)).raise_if_cannot_join(user)
user.enter_room(room).save()
return OKResponse()
示例14: __init__
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)
示例15: query_rooms
def query_rooms():
'''returns each room and its availability status'''
response = []
# loop through the rooms
rooms = Room.get_all()
if rooms:
for r in rooms:
# get current day/time stuff
current_day = datetime.datetime.now().strftime('%A').lower()
current_time = datetime.datetime.fromtimestamp(time.time()).strftime('%H:%M')
# get room use times
room_times = Timetable.get_by_room_id(r.room_id)
# determine usage
use_flag = True
for t in room_times:
if t.day == current_day:
if (current_time >= t.start_time) and (current_time <= t.end_time):
use_flag = False
response.append({"room_id": r.room_id, "room_number": r.room_number, "available": use_flag})
else:
response.append({})
return response