def startGame(args, username, channel): usernameX = username # X is the user that ran startGame command if (Board.objects.filter(active=True, channel=channel)): return generateJsonResponse( 'There is already an active game in this channel. Please wait til the current game is finished to start a new game. To view current game, use /tictactoe showBoard.', error=True) if (len(args) < 2): return generateJsonResponse( 'Please specify username of player you would like to play with.', error=True) usernameO = args[1] # O is the user that usernameX chose to play with playerX = findPlayer(usernameX, channel) playerO = findPlayer(usernameO, channel) # Create new board for new game. board = Board(active=True, channel=channel, playerX=playerX, playerO=playerO) board.save() return generateJsonResponse( 'New Tic Tac Toe game between %s and %s!' % (usernameX, usernameO), generateBoardWithNextPlayerString(board))
def show_board(request): if request.method == "GET": boards = Board.objects.filter(user=request.user) form = Boardform() shared = ReadPermissions.objects.filter(username=request.user.username) ret = render(request, "issueview/boards.html", { "form": form, "boards": boards, "shared": shared }) add_never_cache_headers(ret) return ret form = Boardform(request.POST) if form.is_valid(): if valid_board(form.cleaned_data["board"], request.user): board = Board() board.board = form.cleaned_data["board"] board.user = request.user board.save() form = Boardform() else: form.add_error( None, "board names should be unique and should only use small case digits, alphabet and underscore." ) boards = Board.objects.filter(user=request.user) shared = ReadPermissions.objects.filter(username=request.user.username) ret = render(request, "issueview/boards.html", { "form": form, "boards": boards, "shared": shared }) add_never_cache_headers(ret) return ret
def new_board(request): board = Board() board.radius = Decimal(request.POST['radius']) board.lat = Decimal(request.POST['lat']) board.lng = Decimal(request.POST['lng']) board.name = request.POST['name'] board.save() return redirect('/')
def new(request): if request.method == 'POST': title = request.POST.get('title') content = request.POST.get('content') file = request.FILES.get('file') board = Board(title=title, content=content, file=file) board.save() return redirect('boards:detail', board.pk) else: return render(request, 'boards/new.html')
def createNewBoard(request): username = request.GET.get('user') role = "Admin" board = Board(userid=username,role=role) board.save() bId = board.boardid issuccess = True return JsonResponse({'boardId':bId,'issuccess':issuccess})
def addBoardView(request): if request.method == 'POST': # se la richiesta e una POST e il form e valido aggiungi board user = User.objects.get(username=request.user.username) form = AddBoardForm(request.POST) form.setUser(user) if form.is_valid(): boardname = form.cleaned_data.get('boardname') newBoard = Board(name=boardname) newBoard.save() newBoard.users.add(user) return redirect(newBoard.get_absolute_url()) else: # se la richiesta e una GET publica Form vuoto form = AddBoardForm() return render(request, 'addboard.html', {'form': form})
def addRole(request): admin = request.GET.get('admin') newuser = request.GET.get('newuser') rolein = request.GET.get('role') boardrequest = request.GET.get('boardid') board = Board(boardid = boardrequest, userid = newuser, role = rolein) filtered = Board.objects.filter(boardid__exact=boardrequest) if filtered.filter(userid__exact=admin).exists(): board.save() return JsonResponse({'issuccess':True}) else: return JsonResponse({'issuccess':False})
def startGame(args, username, channel): usernameX = username # X is the user that ran startGame command if (Board.objects.filter(active=True, channel=channel)): return generateJsonResponse('There is already an active game in this channel. Please wait til the current game is finished to start a new game. To view current game, use /tictactoe showBoard.', error=True) if (len(args) < 2): return generateJsonResponse('Please specify username of player you would like to play with.', error=True) usernameO = args[1] # O is the user that usernameX chose to play with playerX = findPlayer(usernameX, channel) playerO = findPlayer(usernameO, channel) # Create new board for new game. board = Board(active=True, channel=channel, playerX=playerX, playerO=playerO) board.save() return generateJsonResponse('New Tic Tac Toe game between %s and %s!' % (usernameX, usernameO), generateBoardWithNextPlayerString(board))
def WritePostView(request): if request.method == 'POST': if request.user.is_superuser: form = AdminPostForm(request.POST) else: form = PostForm(request.POST) if form.is_valid(): post = Board(user=request.user, category=form.cleaned_data['category'], title=form.cleaned_data['title'], content=form.cleaned_data['content']) post.save() return HttpResponseRedirect('/board/') else: if request.user.is_superuser: form = AdminPostForm(initial=request.GET) else: form = PostForm(initial=request.GET) return render(request, 'board/write_post.html', dict(form=form))
def board(request): response = {} result = {} if request.method == "POST": member_id = request.data["memberId"] title = request.data["title"] content = request.data["content"] if member_id is None or title is None or content is None: response["STS"] = ERR_USER_PARAM response["MSG"] = MSG[ERR_USER_PARAM] return Response(response) board = Board(member_id=member_id, title=title, content=content) board.save() response["STS"] = SUCCESS response["MSG"] = MSG[SUCCESS] response["DAT"] = board.id return Response(response) if request.method == "GET": paginator = PageNumberPagination() board_list = Board.objects.order_by("-id").all() result_page = paginator.paginate_queryset(board_list, request) board_list_serializer = BoardListSerializer(result_page, many=True) result["board_list"] = board_list_serializer.data result["total_cnt"] = len(board_list) response["STS"] = SUCCESS response["MSG"] = MSG[SUCCESS] response["DAT"] = result return Response(response)
def add_board(): if check_admin(request) == 1: return abort(403, "You are not allowed to do this.") name = request.forms.get("name").strip().lower() if any(char in list(punctuation + ' ') for char in name): return abort(400, "Boards can't have symbols in their name.") if Board.select().where(Board.name == name).exists(): return abort(400, "A board with this name already exists.") data = { "name": name, "nsfw": bool(request.forms.get("nsfw")), "title": request.forms.get("title").strip() } board = Board(**data) board.save() board_directory(name) return redirect(f'{basename}/admin')
def new_board(): if request.method == 'GET': return render_template('board_form.html') # else POST name = request.form.get('name') desc = request.form.get('desc', '') items = request.form.getlist('item') b = Board(name=name, desc=desc) saved = b.save() board_id = int(b.id) for item in items: if not item: continue i = Item(name=item, board_id=board_id) saved = i.save() # print 'saved?', saved # print 'Item: {} - saved? {}'.format(item, saved) flash('New board created.') return redirect(url_for('board', board_id=int(b.id)))
def get(self): board_id = uuid.uuid4().hex[:8] b = Board(id=uuid.uuid4(), board_id=board_id, read_only=uuid.uuid4()) b.save() self.redirect('/%s' % str(b.board_id))
def writedb(request): db = Board(name = request.GET['name'], title = request.GET['title'], text = request.GET['text'],) db.save() return HttpResponseRedirect("/board/")