本文整理汇总了Python中models.Room类的典型用法代码示例。如果您正苦于以下问题:Python Room类的具体用法?Python Room怎么用?Python Room使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Room类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:anathomical,项目名称:watchwithme,代码行数:7,代码来源:controllers.py
示例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")
开发者ID:punchagan,项目名称:tree-house,代码行数:32,代码来源:views.py
示例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))
开发者ID:cyang,项目名称:crowd-navigation,代码行数:35,代码来源:controllers.py
示例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))
开发者ID:cyang,项目名称:crowd-navigation,代码行数:34,代码来源:controllers.py
示例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
开发者ID:JanetGuo,项目名称:lupalo,代码行数:58,代码来源:views.old.py
示例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")
开发者ID:jaceyen,项目名称:vocmon,代码行数:10,代码来源:views.py
示例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))
开发者ID:robgolding,项目名称:mydebate,代码行数:55,代码来源:views.py
示例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'))
开发者ID:CSC301H-Fall2013,项目名称:JuakStore,代码行数:11,代码来源:views.py
示例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))
开发者ID:alexweaver,项目名称:tdp-hackathon-2016,代码行数:53,代码来源:main.py
示例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))
开发者ID:alexweaver,项目名称:tdp-hackathon-2016,代码行数:53,代码来源:main.py
示例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' )
开发者ID:cliffmeyer,项目名称:lupalo,代码行数:51,代码来源:views.py
示例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
开发者ID:bjdag1234,项目名称:django-schedule-rooms,代码行数:14,代码来源:signals.py
示例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()
开发者ID:ShihengJiang666,项目名称:CS169CombatingSnake,代码行数:7,代码来源:views.py
示例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)
开发者ID:cyang,项目名称:crowd-navigation,代码行数:7,代码来源:controllers.py
示例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
开发者ID:BU-Computing,项目名称:radar,代码行数:26,代码来源:data_handler.py
示例16: start_game
def start_game(room_code):
sessid = request.cookies.get("sessid")
room = Room.select(Room).join(Player, on=Room.owner).where(Player.sessid == sessid, Room.code == room_code).get()
init_game(room)
message_data = {"url": "/game/%s" % room_code}
post_message([Msg("start", message_data)], room=room)
return redirect("/game/%s" % room_code)
开发者ID:warownia1,项目名称:TheResistance,代码行数:7,代码来源:views.py
示例17: get
def get(self):
tenant_key = self.request.get('tenant_key')
tenant = Tenant.get(tenant_key)
room = Room()
vacantRooms=room.getVacantRooms()
if vacantRooms:
tenant_data_list = tenant.getTenantProfile()
rooms_data_list = room.getRoomsProfile(vacantRooms)
data_list = []
data_list.append({'tenantProfile': tenant_data_list, 'roomsProfile': rooms_data_list})
output_json = json.dumps(data_list)
self.response.out.write(output_json)
else:
noVacancyResponse = {'noVacancyResponse':'Sorry, All rooms are occupied!'}
noVacancyResponse_json = simplejson.dumps(noVacancyResponse)
return self.response.out.write(noVacancyResponse_json)
开发者ID:cnherald,项目名称:rentalHouseManagement2,代码行数:16,代码来源:rentalManager.py
示例18: post
def post(self, request, *args, **kwargs):
'''
Create room
'''
user = fetch_user(request)
room = Room.create_by(user).save()
return OKResponse(room.to_dict())
开发者ID:ShihengJiang666,项目名称:CS169CombatingSnake,代码行数:7,代码来源:views.py
示例19: index
def index():
form = SearchForm()
if form.validate_on_submit():
room = Room()
form.populate_obj(room)
# Change room_pref and room_type if they are None
if not room.room_pref:
room.room_pref = 0 if room.is_available else 1
if not room.room_type:
room.room_type = 1 if room.is_available else 0
# Search for matching rooms
rooms_distance = Room.search_rooms(room)
return render_template("found.html", rooms_distance=rooms_distance)
return render_template("autoform.html", form=form, title="Search Acco.", submit="Search ad")
开发者ID:punchagan,项目名称:tree-house,代码行数:17,代码来源:views.py
示例20: post
def post(self, request, *args, **kwargs):
"""
Create room
"""
user = fetch_user(request)
room = Room.create_by(user).save()
user.enter_room(room).save()
return OKResponse(room.to_dict())
开发者ID:jacky8hyf,项目名称:CS169CombatingSnake,代码行数:8,代码来源:views.py
注:本文中的models.Room类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论