本文整理汇总了Python中models.Room.save方法的典型用法代码示例。如果您正苦于以下问题:Python Room.save方法的具体用法?Python Room.save怎么用?Python Room.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Room
的用法示例。
在下文中一共展示了Room.save方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handlefbrequestcallback
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
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
示例2: createRoom
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
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")
示例3: create_room
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
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))
示例4: submitRoom
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
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'))
示例5: makerobogame
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
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' )
示例6: optionnal_room
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
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
示例7: test_get_messages
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
def test_get_messages(self, *args, **kwargs):
username, password = self.username, self.userpwd
# login user
client = Client()
client.login(username=username, password=password)
# creates a room
room = Room()
room.save()
# message queue empty: check last_message_id
response = client.get('/chat/get_latest_msg_id/?room_id=%d' % room.id)
json_response = json.loads(response.content)
last_msg_id = json_response['id']
self.assertEquals(last_msg_id, -1)
# posts a message
post_response = client.post('/chat/send_message/',
{'room_id': room.pk,
'message': 'ABCD'},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEquals(post_response.status_code, 200)
json_response = json.loads(post_response.content)
timestamp = json_response['timestamp']
# gets list of messages
response = client.get(
'/chat/get_messages/?room_id=%d&latest_message_id=%d' % (
room.id, last_msg_id),
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEquals(response.status_code, 200)
json_response = json.loads(response.content)
expected_json = [{u'message_id': 1,
u'username': u'john',
u'date': timestamp,
u'content': u'ABCD', }]
self.assertEquals(expected_json, json_response)
# check last_message_id
response = client.get('/chat/get_latest_msg_id/?room_id=%d' % room.id)
json_response = json.loads(response.content)
last_msg_id = json_response['id']
self.assertEquals(last_msg_id, 1)
示例8: test_anonymous_access
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
def test_anonymous_access(self):
anon_room = Room(
allow_anonymous_access=True,
name="Anonymous Room",
slug="anonymous-room")
login_req_room = Room(
allow_anonymous_access=False,
name="Login required room",
slug="login-required-room")
anon_room.save()
login_req_room.save()
client = Client()
response = client.get(login_req_room.get_absolute_url())
# a login view may not have been implemented, so assertRedirects fails
self.assertEquals(response.status_code, 302)
url = response['Location']
expected_url = get_login_url(login_req_room.get_absolute_url())
e_scheme, e_netloc, e_path, e_query, e_fragment = urlparse.urlsplit(
expected_url)
if not (e_scheme or e_netloc):
expected_url = urlparse.urlunsplit(('http', 'testserver', e_path,
e_query, e_fragment))
self.assertEquals(url, expected_url)
response = client.get(
anon_room.get_absolute_url(),
follow=True)
# assert redirect
self.assertRedirects(
response,
'http://testserver/chat/setguestname/?room_slug=anonymous-room')
# post guestname
guestname_posted = client.post(
response.redirect_chain[0][0],
{'guest_name': 'guest',
'room_slug': 'anonymous-room'},
follow=True)
self.assertRedirects(
guestname_posted,
anon_room.get_absolute_url()
)
示例9: reset
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
def reset(request):
Room.objects.all().delete()
r = Room(name='testroom')
r.save()
Game.objects.all().delete()
g = Game(name='testgame',room=r)
g.save()
Player.objects.all().delete()
p = Player.objects.all()
print "Total number of players: %d" % len(p)
Member.objects.all().delete()
print "Hello"
m = Member(user_name='Cliff')
m.save()
m = Member(user_name='Eve')
m.save()
return HttpResponseRedirect( reverse('lupalo.views.login') ) # Redirect after POST
示例10: open_room
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
def open_room(request):
roomid = request.REQUEST.get('id', '')
idurl = request.REQUEST.get('idurl', '')
name = request.REQUEST.get('name', contactsdb.get_correspondent_nickname(idurl))
if roomid:
try:
roomid = int(roomid)
except:
lg.exc()
return Http404('incorrect Room ID')
try:
ThisRoom = get_object_or_404(Room, id=roomid)
except:
ThisRoom = Room(id=roomid,
idurl=idurl,
name=name)
ThisRoom.save()
# myname = settings.getNickName() or my_id.getIDName()
RoomMember.objects.create_member(idurl=my_id.getLocalID(),
# name=nameurl.GetName(my_id.getLocalID()),
room=ThisRoom)
return HttpResponseRedirect('/chat/room/%d' % ThisRoom.id)
if idurl:
try:
ThisRoom = get_object_or_404(Room, idurl=idurl)
except:
ThisRoom = Room(idurl=idurl,
name=name)
ThisRoom.save()
RoomMember.objects.create_member(idurl=my_id.getLocalID(),
# name=nameurl.GetName(my_id.getLocalID()),
room=ThisRoom)
return HttpResponseRedirect('/chat/room/%d' % ThisRoom.id)
return Http404('need to provide a room info')
示例11: test_chatview_attributes
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
def test_chatview_attributes(self):
"""Asserts new items are added to ChatView instance
when a new room is created, and these items are removed
when a room is deleted
"""
new_room = Room(name="New room",
slug="new-room")
new_room.save()
chatview = ChatView()
self.assertIn(new_room.id, chatview.new_message_events)
self.assertIn(new_room.id, chatview.messages)
self.assertIn(new_room.id, chatview.connected_users)
self.assertIn(new_room.id, chatview.counters)
self.assertIn(new_room.id, chatview.new_connected_user_event)
# works without a post_delete handler: somewhere the Django models
# collector gets rid of these items (awkward, not documented feat)
new_room.delete()
self.assertNotIn(new_room.id, chatview.new_message_events)
self.assertNotIn(new_room.id, chatview.messages)
self.assertNotIn(new_room.id, chatview.connected_users)
self.assertNotIn(new_room.id, chatview.counters)
self.assertNotIn(new_room.id, chatview.new_connected_user_event)
示例12: handlefbrequestcallback
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
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_id = ( request.GET.get('id') )
request_from = request.session['fb_id']
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']
instance = UserSocialAuth.objects.filter(provider='facebook',user=request.user.id).order_by('-id')[0]
graph = facebook.GraphAPI(instance.tokens["access_token"])
try:
profile = graph.get_object("me")
except:
logout(request)
return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
try:
m_to = Member.objects.get(fb_id=request_to)
except:
# need to make member
m_to = Member(fb_id=request_to)
# play against robot
if request_to == 'auto':
m_to.fb_first_name = 'auto'
m_to.fb_last_name = 'auto'
else:
profile = graph.get_object( str(request_to) )
m_to.fb_first_name = profile['first_name']
m_to.fb_last_name = profile['last_name']
m_to.save()
if m_to.fb_first_name == None or m_to.fb_last_name == None:
profile = graph.get_object( str(request_to) )
m_to.fb_first_name = profile['first_name']
m_to.fb_last_name = profile['last_name']
m_to.save()
try:
m_from = Member.objects.get(fb_id=request_from)
except:
# need to make member
m_from = Member(fb_id=request_from)
profile = graph.get_object( str(request_from) )
m_from.fb_first_name = profile['first_name']
m_from.fb_last_name = profile['last_name']
m_from.save()
if m_from.fb_first_name == None or m_from.fb_last_name == None:
profile = graph.get_object( str(request_from) )
m_from.fb_first_name = profile['first_name']
m_from.fb_last_name = profile['last_name']
m_from.save()
# name is set
gamename = "%s_%s_%s" % ( request_from, request_to, time.asctime(time.gmtime()) )
print >> fp, "gamename", gamename
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(member=m_from)
p.game=g
p.turn=0
p.save()
# TODO assumes two player game - generalize
p = Player( member = m_to )
p.game=g
p.turn=1
p.save()
#return HttpResponseRedirect('requestpage.html')
return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
示例13: loggedin
# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import save [as 别名]
def loggedin(request,**kwargs):
fp = open( 'tmp.2.log', 'w' )
try:
request_ids = request.session['fbrequests']
print >> fp, request_ids
print >> fp, "====================================="
except:
pass
print >> fp, request.method
print >> fp, request.user.first_name
print >> fp, request.user.last_name
print >> fp, request.user.username
print >> fp, request.user.id
print >> fp, request.user
if SOCIALAUTH_ON:
print >> fp,'A',[ x for x in UserSocialAuth.objects.filter(user=request.user.id).all()]
print >> fp,'B',[ x for x in UserSocialAuth.objects.all()]
print >> fp,'C',[ x for x in UserSocialAuth.objects.filter(provider='facebook',user=request.user.id).order_by('-id')]
instance = UserSocialAuth.objects.filter(provider='facebook',user=request.user.id).order_by('-id')[0]
#instance = UserSocialAuth.objects.filter(provider='facebook').get(user=request.user.id).order_by('-id')[0]
print >> fp, instance
print >> fp, instance.tokens
graph = facebook.GraphAPI(instance.tokens["access_token"])
try:
profile = graph.get_object("me")
except:
logout(request)
return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
friends = graph.get_connections("me", "friends")
print >> fp, profile
print >> fp, profile['id']
fb_id = profile['id']
print >> fp, friends
else:
fb_id = ROBOT1
request.session['fb_id'] = fb_id
print >> fp, "fb_id", fb_id
#graph.put_object("me","apprequests",message="Lup",redirect_uri="http://www.lupalo.com/foo/login/facebook")
#graph.put_object("me","apprequests",to="100004397774234",message="Lup",redirect_uri="http://www.lupalo.com/foo/login/facebook")
# TODO check if member exists with the same fb id
try:
#m = Member.objects.get(user_name=request.user.id)
m = Member.objects.get( fb_id=fp_id )
except Member.DoesNotExist:
m = None
if m == None:
try:
m = Member.objects.get( fb_id=request.session['fb_id'] )
m.user_name = profile['name']
m.fb_first_name = profile['first_name']
m.fb_last_name = profile['last_name']
m.save()
except Member.DoesNotExist:
m = None
return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
#return HttpResponseRedirect(reverse('lupalo.views.requestpage'))
if True:
#if request.method == 'POST': # If the form has been submitted...
#form = ContactForm(request.POST) # A form bound to the POST data
#print >> fp, "validating"
#print >> fp, form.is_valid()
#print >> fp, form.errors
#if form.is_valid():
if True:
#user = form.cleaned_data['user']
#user = request.user.id
user = request.user.username
t = time.gmtime()
name = time.asctime(t)
gamename = time.asctime(t)
#gamename = form.cleaned_data['room']
#newgame = form.cleaned_data['newgame']
newgame = True
print >> fp, "New Game", newgame
if newgame == True:
#Room.objects.all().delete()
r = Room(name=name)
r.save()
Game.objects.all().delete()
#.........这里部分代码省略.........