def createroom(anon, private): roomid = ''.join( random.choice(string.ascii_lowercase + string.digits) for i in range(6)) # random roomid string while Room.objects.filter(roomid=roomid).exists(): # ensure unique roomid roomid = ''.join( random.choice(string.ascii_lowercase + string.digits) for i in range(6)) # regenerate roomid key = ''.join( random.choice(string.ascii_letters + string.digits) for i in range(16)) room = Room(roomid=roomid, key=key, anonymous=anon, private=private) room.save() return room
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('polls.views.login') ) # Redirect after POST
def login(request): if request.method == 'POST': # If the form has been submitted... form = ContactForm(request.POST) # A form bound to the POST data if form.is_valid(): user = form.cleaned_data['user'] gamename = form.cleaned_data['room'] newgame = form.cleaned_data['newgame'] print "New Game", newgame if newgame == True: Room.objects.all().delete() r = Room(name='testroom') r.save() Game.objects.all().delete() g = Game(name='testgame',room=r) g.save() r = Room(name=gamename) r.save() g = Game(name=gamename,room=r) g.save() else: r = Room(name=gamename) g = Game(name=gamename,room=r) m = Member.objects.get(user_name=user) request.session['member_id'] = m.id game = Game.objects.all() g = game[0] request.session['game_id'] = g.id # TODO get room id from game r = g.room # TODO get player id from room #players = Player.objects.get(game=g) try: players = get_list_or_404(Player, game=g) except: players = None if players: turn = len(players) else: turn = 0 p = Player(game=g,turn=turn) p.member = m p.save() print "Player turn:", p.turn request.session['player_id'] = p.turn return HttpResponseRedirect( reverse('polls.views.lupalo') ) # Redirect after POST #return render(request, 'polls/login.html', { # 'form': form, #}) else: form = ContactForm() # An unbound form #m = Member.objects.get(user_name=request.POST['username']) #request.session['member_id'] = m.id return render(request, 'polls/login.html', { 'form': form, })