def post_new_game(request): secret_key = request.POST['secret_key'] player_name = request.POST['player_name'] print(f'{DEBUG}: data in new_game:', secret_key, player_name) new_game = False try: game = Game.objects.get(secret_key=secret_key) print(f'{DEBUG}: loaded game of key {secret_key}') except Game.DoesNotExist: game = Game(secret_key=secret_key) new_game = True game.save() # make sure this user does not already have a player in the game. context = {'secret_key': secret_key, 'player_name': player_name} if Player.objects.filter(game=game, name=player_name): # TODO: I want to pass a context here but I can't # It isi easy with render but then that's not "safe". # Need to figure out how to do this... # return HttpResponseRedirect(reverse('pages:new_game')) context[ 'error_message'] = "Diesen Namen hat schon jemand anderes benutzt!" return render(request, 'pages/new_game.html', context=context) elif Player.objects.filter(game=game, user=request.user): context[ 'error_message'] = f"Du ({request.user.username}) bist schon im Spiel!" return render(request, 'pages/new_game.html', context=context) player = Player(name=player_name, game=game, user=request.user) player.save() if new_game: print('creating new game') first_round = create_round(game) game.current_round = first_round game.save() return HttpResponseRedirect( reverse('pages:index_game', kwargs={'secret_key': game.secret_key}))
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, })
def _create_tags(self): count = 1000 i = 0 while i < count: src = 'eugene.jpg' if i % 2 == 0: src = 'Art.jpg' tlisp = Team(title='Mike' + str(i) ,text='seo',img = src) tlisp.save() i = i + 1 #tjava = Tag(name='Java') #tjava.save() i = 0 while i < count: login_ = 'Black' + str(i) password_ = 'qwerty' username_ = 'Wolf' + str(i) img_ = str ( i % 7 + 1) + ".jpg" new_user = MyUser(login = login_,password = password_,username = username_,img = img_) new_user.save() i = i + 1 i = 0 while i < count: title_ = 'Game number ' + str(i) text_ = 'Game text number ' + str(i) img_ = str(i % 5 + 1) + '_' + '1.jpg' download_link_ = 'http://mail.ru' play_link_ = 'http://yandex.ru' description_ = 'Game description number ' + str(i) new_game = Game(title = title_, text = text_, img = img_, download_link = download_link_, play_link = play_link_, description = description_) new_game.save() i = i + 1 i = 0 _id = 1 while i < count: i = i + 1 g = Game.objects.get(id=i) u = MyUser.objects.get(id=i) j = 0 while j < 10: print("i " + str(i)) print(" j" + str(j)) text_ = "Comment number " + str(j) + "game" + str(i) new_comment = Comment(text = text_) new_comment.save() print("ID " + str(_id)) e = Comment.objects.get(id=_id) g.comment_set.add(e) u.comment_set.add(e) _id = _id + 1 j = j + 1 i = 0 my_str = "abcdefghigklmnopqrstuvwxyz " while i < count: title_ = "Post " + str(i) img_ = str ( i % 7 + 1) + ".jpg" text_ = "" j = 0 while (j < 1000): text_ = my_str[math.trunc(random.random() * 36)] + text_ j = j + 1 new_post = BlogPost(title = title_, img = img_, text = text_) new_post.save() u = MyUser.objects.get(id=i + 1) e = BlogPost.objects.get(id=i + 1) u.blogpost_set.add(e) i = i + 1 i = 0 _id = 1 while i < count: i = i + 1 g = BlogPost.objects.get(id=i) u = MyUser.objects.get(id=i) j = 0 while j < 10: print("i " + str(i)) print(" j" + str(j)) text_ = "Comment number " + str(j) + "post" + str(i) new_comment_blog = CommentBlogPost(text = text_) new_comment_blog.save() print("ID " + str(_id)) e = CommentBlogPost.objects.get(id=_id) g.commentblogpost_set.add(e) u.commentblogpost_set.add(e) _id = _id + 1 j = j + 1 i = 0 _id = 1 while i < count: i = i + 1 p = BlogPost.objects.get(id=i) g = Game.objects.get(id=i) u = MyUser.objects.get(id=i) j = 0 while j < 10: if ( i % 2 == 0): content_object_ = g else: content_object_ = p mark_ = math.trunc(random.random() * 5) new_rating = Rating(mark = mark_, content_object = content_object_) new_rating.save() e = Rating.objects.get(id=_id) u.rating_set.add(e) _id = _id + 1 j = j + 1 i = 0 _id = 1 while i < count: i = i + 1 g = Game.objects.get(id=i) j = 1 while j < 11: game_ = g img_ = str(j) + ".jpg" new_img= Screenshot(game = game_, img = img_) new_img.save() e = Screenshot.objects.get(id=_id) g.screenshot_set.add(e) _id = _id + 1 j = j + 1
def _create_tags(self): count = 1000 i = 0 while i < count: src = 'eugene.jpg' if i % 2 == 0: src = 'Art.jpg' tlisp = Team(title='Mike' + str(i), text='seo', img=src) tlisp.save() i = i + 1 #tjava = Tag(name='Java') #tjava.save() i = 0 while i < count: login_ = 'Black' + str(i) password_ = 'qwerty' username_ = 'Wolf' + str(i) img_ = str(i % 7 + 1) + ".jpg" new_user = MyUser(password=password_, username=username_, img=img_) new_user.save() i = i + 1 i = 0 while i < count: title_ = 'Game number ' + str(i) text_ = 'Game text number ' + str(i) img_ = str(i % 5 + 1) + '_' + '1.jpg' download_link_ = 'http://mail.ru' play_link_ = 'http://yandex.ru' description_ = 'Game description number ' + str(i) new_game = Game(title=title_, text=text_, img=img_, download_link=download_link_, play_link=play_link_, description=description_) new_game.save() i = i + 1 i = 0 _id = 1 while i < count: i = i + 1 g = Game.objects.get(id=i) u = MyUser.objects.get(id=i) j = 0 while j < 10: print("i " + str(i)) print(" j" + str(j)) text_ = "Comment number " + str(j) + "game" + str(i) new_comment = Comment(text=text_) new_comment.save() print("ID " + str(_id)) e = Comment.objects.get(id=_id) g.comment_set.add(e) u.comment_set.add(e) _id = _id + 1 j = j + 1 i = 0 my_str = "abcdefghigklmnopqrstuvwxyz " while i < count: title_ = "Post " + str(i) img_ = str(i % 7 + 1) + ".jpg" text_ = "" j = 0 while (j < 1000): text_ = my_str[math.trunc(random.random() * 36)] + text_ j = j + 1 new_post = BlogPost(title=title_, img=img_, text=text_) new_post.save() u = MyUser.objects.get(id=i + 1) e = BlogPost.objects.get(id=i + 1) u.blogpost_set.add(e) i = i + 1 i = 0 _id = 1 while i < count: i = i + 1 g = BlogPost.objects.get(id=i) u = MyUser.objects.get(id=i) j = 0 while j < 10: print("i " + str(i)) print(" j" + str(j)) text_ = "Comment number " + str(j) + "post" + str(i) new_comment_blog = CommentBlogPost(text=text_) new_comment_blog.save() print("ID " + str(_id)) e = CommentBlogPost.objects.get(id=_id) g.commentblogpost_set.add(e) u.commentblogpost_set.add(e) _id = _id + 1 j = j + 1 i = 0 _id = 1 while i < count: i = i + 1 p = BlogPost.objects.get(id=i) g = Game.objects.get(id=i) u = MyUser.objects.get(id=i) j = 0 while j < 10: if (i % 2 == 0): content_object_ = g else: content_object_ = p mark_ = math.trunc(random.random() * 5) new_rating = Rating(mark=mark_, content_object=content_object_) new_rating.save() e = Rating.objects.get(id=_id) u.rating_set.add(e) _id = _id + 1 j = j + 1 i = 0 _id = 1 while i < count: i = i + 1 g = Game.objects.get(id=i) j = 1 while j < 11: game_ = g img_ = str(j) + ".jpg" new_img = Screenshot(game=game_, img=img_) new_img.save() e = Screenshot.objects.get(id=_id) g.screenshot_set.add(e) _id = _id + 1 j = j + 1