Ejemplo n.º 1
0
def board_edit(request, board_id=None):

    user = request.user.pk
    user_type = request.user.profile.type

    if board_id:
        board = get_object_or_404(Board, pk=board_id)
    else:
        board = Board()

    if request.method == "POST":
        # POST 된 request 데이터를 가지고 Form 생성
        form = BoardForm(request.POST, instance=board)
        if form.is_valid():
            board = form.save(commit=False)
            board.board_id = Board(board_id)
            board.writer = User(user)
            if not board_id:
                board.category = user_type
            board.save()
            # request 없이 페이지 이동만 한다.
        return redirect('board:list')
    else:
        # book instance에서 Form 생성
        form = BoardForm(instance=board)
        # 사용자의 request를 가지고 이동한다.
        return render(request, 'board/board_edit.html',
                      dict(form=form, board=board))
Ejemplo n.º 2
0
def write(request, page=1):
    # 인증
    authuser = request.session.get('authUser')
    if authuser is None:
        return HttpResponseRedirect('/board/list')
    board = Board()
    board.title = request.POST['title']
    board.content = request.POST['content']
    board.category = request.POST.get('category')
    board.user = User.objects.get(id=request.session['authUser']['id'])
    # return redirect('/detail/' + str(post.id))

    # 새글 작성
    if request.POST['no'] == '-1':
        value = Board.objects.aggregate(max_groupno=Max('groupno'))
        board.groupno = value["max_groupno"] + 1
        board.save()

    # 답글 작성
    else:
        board2 = Board.objects.get(id=request.POST['no'])
        Board.objects.filter(orderno__gte=board2.orderno +
                             1).update(orderno=F('orderno') + 1)
        board.groupno = board2.groupno
        board.orderno = board2.orderno + 1
        board.depth = board2.depth + 1
        board.save()

    for img in request.FILES.getlist('imgs'):
        photo = Photo()
        photo.post = board
        photo.image = img
        photo.save()
    data = {'page': 1}
    # 검색어

    kwd = request.GET.get('kwd')
    print(kwd, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
    if kwd is None:
        data['kwd'] = json.dumps(kwd)
    else:
        data['kwd'] = kwd
    return HttpResponseRedirect(f'/board/list/{page}?kwd={kwd}')