예제 #1
0
def add(request):
    board = Board()
    user = User.objects.get(id=request.session['authuser']['id'])

    board.title = request.POST['title']
    board.content = request.POST['content']
    board.user_id = user

    #  만약 추가하는것이 첫 글쓰기일때
    if request.POST['add'] == 'write':
        g_no = Board.objects.aggregate(g_no=Max('g_no'))
        if g_no['g_no'] is None:
            g_no['g_no'] = 0
        board.g_no = g_no['g_no'] + 1
        board.o_no = 0
        board.depth = 0
    else:
        id = request.POST['id']
        p_board = Board.objects.get(id=id)
        board.g_no = p_board.g_no

        results = Board.objects.filter(o_no__gt=p_board.o_no,
                                       g_no=p_board.g_no)
        results.update(o_no=F('o_no') + 1)
        board.o_no = p_board.o_no + 1
        board.depth = p_board.depth + 1

    board.save()

    return HttpResponseRedirect('/board' + "?page=" +
                                str(request.session['session_page']))
예제 #2
0
파일: views.py 프로젝트: exizt/mysite02
def write(request):
    authuser = request.session.get('authuser')
    if authuser is None:
        # 유저가 아닌 접근이므로. 비정상 접근이거나 세션 해제된 상태.
        return HttpResponseRedirect('/')

    title = request.POST.get('title', '')
    contents = request.POST.get('contents', '')

    user = User.objects.get(id=authuser['id'])

    max_gno = Board.objects.aggregate(g_no=Max('g_no'))['g_no']
    if max_gno is None or max_gno == '':
        max_gno = 0

    # 저장 처리
    board = Board()
    board.title = title
    board.contents = contents
    board.user = user
    board.g_no = int(max_gno) + 1
    board.save()

    # board = Board(title=title, contents=contents, user=user)
    # board.save()

    # ret = Board.insert(data)
    # if ret != 1:
    #     return HttpResponse('오류 발생')

    return HttpResponseRedirect('/board/')
예제 #3
0
파일: views.py 프로젝트: exizt/mysite02
def reply(request):
    authuser = request.session.get('authuser')
    if authuser is None:
        # 유저가 아닌 접근이므로. 비정상 접근이거나 세션 해제된 상태.
        return HttpResponseRedirect('/')

    title = request.POST.get('title', '')
    contents = request.POST.get('contents', '')

    g_no = request.POST.get('g_no', 0)
    o_no = request.POST.get('o_no', 0)
    depth = request.POST.get('depth', 0)

    user = User.objects.get(id=authuser['id'])

    # 저장 처리
    board = Board()
    board.title = title
    board.contents = contents
    board.user = user
    board.g_no = int(g_no)
    board.o_no = int(o_no) + 1
    board.depth = int(depth) + 1
    board.save()

    # ret = Board.reply(data)
    # if ret != 1:
    #    return HttpResponse('오류 발생')

    return HttpResponseRedirect('/board/')