def write(request): board = Board() try: groupno = int(request.POST['groupno']) orderno = int(request.POST['orderno']) depth = int(request.POST['depth']) Board.objects.filter(groupno=groupno). \ filter(orderno__gte=orderno + 1). \ update(orderno=F('orderno') + 1) board.title = request.POST['title'] board.content = request.POST['content'] board.user_id = request.POST['user_id'] board.groupno = groupno board.orderno = orderno + 1 board.depth = depth + 1 except Exception as e: board.title = request.POST['title'] board.content = request.POST['content'] board.user_id = request.POST['user_id'] board.groupno = groupno_max() + 1 board.save() return HttpResponseRedirect('/board')
def add(request): if request.session.get('authuser') == None: return HttpResponseRedirect('/user/loginform') authuser = request.session['authuser'] paraentno = request.POST.get('parentno') if authuser is None: return HttpResponseRedirect('/board') board = Board() board.user_id = authuser['id'] board.title = request.POST.get('title') board.content = request.POST.get('contents') if paraentno != '': parent = Board.objects.get(id=paraentno) board.groupno = parent.groupno board.orderno = parent.orderno + 1 Board.objects.filter(groupno=board.groupno).filter(orderno__gte=board.orderno).update(orderno=F('orderno') + 1) board.depth = parent.depth + 1 else: lastboard = Board.objects.order_by('id').last() if lastboard == None: board.groupno = 1 else: board.groupno = lastboard.id +1 board.save() return HttpResponseRedirect('/board')
def write_reply(request, parent_id): authuser = check_login_auth(request) if authuser is None: return HttpResponseRedirect('/user/loginform') board = Board() parent = Board.objects.get(id=parent_id) groupno = parent.groupno orderno = parent.orderno + 1 depth = parent.depth + 1 results = Board.objects.filter(groupno=groupno).filter( orderno__gte=orderno).update(orderno=F('orderno') + 1) title = request.POST['title'] content = request.POST['content'] userid = request.session['authuser']['id'] board.title = title board.content = content board.user_id = userid board.groupno = groupno board.orderno = orderno board.depth = depth board.save() return HttpResponseRedirect('/board')
def board_write(request): parents_id = request.POST['parentsNo'] board = Board() if parents_id == "": value = Board.objects.aggregate(max_groupno=Max('groupno')) max_groupno = 0 if value["max_groupno"] is None else value["max_groupno"] board.groupno = max_groupno + 1 board.orderno = 1 board.depth = 0 else: value = Board.objects.filter(id=parents_id) # orderno를 하나씩 밀어주기 Board.objects.filter(orderno__gte=value[0].orderno + 1).update(orderno=F('orderno') + 1) board.groupno = value[0].groupno board.orderno = value[0].orderno + 1 board.depth = value[0].depth + 1 board.user_id = int(request.session['authuser']['id']) board.title = request.POST['title'] board.content = request.POST['content'] board.save() return HttpResponseRedirect('/board')
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']))
def write(request): board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board')
def add(request): board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.user_id = request.POST['user_id'] board.save() return HttpResponseRedirect('/board')
def write_post(request): pages = int(request.POST.get('pages', 1)) # 현재 페이지 kwd = str(request.GET.get('kwd', '')) # 검색어 # 공통 파라미터 -------------------------------------------------------------- # 로그인 확인 authuser = request.session['authuser'] if authuser is None: return HttpResponseRedirect('/board') board = Board() board.user_id = authuser['id'] board.title = request.POST['title'] board.content = request.POST['content'] # 스크립트를 무시하고 잘못된 정보를 줬을 때 if board.title == '': return HttpResponseRedirect('/board') if board.content == '': return HttpResponseRedirect('/board') # 부모id가 있으면 답글 parentno = int(request.POST.get('parentno', -1)) if parentno == -1: # groupno : 답글이 아니면 (Max+1) value = Board.objects.aggregate(max_groupno=Max('groupno')) max_groupno = 0 if value['max_groupno'] is None else value[ 'max_groupno'] board.groupno = max_groupno + 1 # orderno : 답글이 아니면 항상 1 board.orderno = 1 # depth : 답글이 아니면 항상 0 board.depth = 0 else: # 답글이면 일단 부모 객체를 가져온다 parents = Board.objects.get(id=parentno) # groupno : 답글이면 부모것과 같게 board.groupno = parents.groupno # orderno : 답글이면 (부모것+1) 보다 크거나 같은거 모두 (+1)해서 밀고 (부모것+1) board.orderno = parents.orderno + 1 Board.objects.filter(groupno=board.groupno).filter( orderno__gte=board.orderno).update(orderno=F('orderno') + 1) # depth : 답글이면 (부모것+1) board.depth = parents.depth + 1 # parentno : 답글이면 부모번호 board.parentno = parentno board.save() return HttpResponseRedirect('/board')
def create(request): board = Board() board.title = 'test' board.contents = 'test' board.user_id = 1 board.save() return HttpResponse('ok')
def add(request): board_txt = Board() board_txt.title = request.POST['title'] board_txt.content = request.POST['content'] board_txt.user_id = request.session['authuser']['id'] board_txt.hit = 0 board_txt.name = request.session['authuser']['name'] board_txt.save() return HttpResponseRedirect('/board')
def boardWrite_Save(request): # 리스트에 담아버림, 없으면 오류 writeSave = Board() writeSave.user_id = request.session['authuser'][ 'id'] # session 에서 authuser딕셔너리의 id 값을 받아옴 writeSave.name = request.session['authuser']['name'] writeSave.title = request.POST['title'] writeSave.content = request.POST['content'] writeSave.save() return HttpResponseRedirect('/board')
def add(request): if request.session.get('authuser') is None: return HttpResponseRedirect('/') board = Board() board.title = request.POST['title'] board.contents = request.POST['contents'] board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board')
def write(request): # 인증 체크 if request.session.get('authuser') is None: return HttpResponseRedirect('/user/loginform') board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board')
def write(request): board = Board() board.title = request.POST['title'] board.content = request.POST['content'] max = Board.objects.aggregate(max_groupno=Max('groupno')) board.groupno = (0 if max['max_groupno'] is None else max['max_groupno']) + 1 board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board')
def write(request): # update board set order_no = order_no + 1 # where group_no = {groupNo} and order_no !=0 and depth = {depth}+1 board = Board() if request.POST['new'] == 'True': # 그냥 리스트에서 새 글 쓸떄 value = Board.objects.aggregate(max_groupno=Max('groupno')) max_groupno = 0 if value["max_groupno"] is None else value[ "max_groupno"] board.title = request.POST['title'] board.content = request.POST['content'] board.hit = 0 board.groupno = max_groupno + 1 board.orderno = 0 board.depth = 0 board.user_id = request.session['authuser']['id'] else: # 답글 쓸때 value = Board.objects.filter(id=request.POST['id']) Board.objects.filter(orderno__gte=value[0].orderno + 1).update(orderno=F('orderno') + 1) board.groupno = value[0].groupno board.orderno = value[0].orderno + 1 board.depth = value[0].depth + 1 board.title = request.POST['title'] board.content = request.POST['content'] board.hit = 0 board.groupno = request.POST['groupno'] board.orderno = int(request.POST['orderno']) + 1 board.depth = int(request.POST['depth']) + 1 board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board/list')
def reply(request, id=0): original = Board.objects.get(id=id) board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.groupno = original.groupno board.orderno = original.orderno board.depth = original.depth + 1 board.user_id = request.session['authuser']['id'] Board.objects.filter(groupno=original.groupno).filter( orderno__gte=original.orderno).update(orderno=F('orderno') + 1) board.save() return HttpResponseRedirect('/board')
def add(request): # action ='' 에서 request가 들어온다 board = Board() # POST방식으로 가져온 값을 DB에 새롭게 입력한 값을 넣는다 #user = User() board.title = request.POST['title'] board.content = request.POST['content'] # title과 content는 write.html에서 작성하는 것이므로 user_id만 가져오면된다. board.user_id = request.session['authuser'][ 'id'] # user의 forienkey로 id를 가져온다. # board.name = request.session['authuser']['name'] # user앱의 model에서 name을 가져옴 name이 forienkey이므로 # # print('request.session:',type(request.session['authuser']['name'])) # print(type(board.name),'board.user.name : ' ,board.name) # mysql의 db에 있는 user name 정보를 가져다준다. board.save() return HttpResponseRedirect('/board')
def reply(request): #reply method 수정해야됨 value = Board.objects.aggregate(max_groupno=Max('groupno')) max_groupno = 0 if value["max_groupno"] is None else value["max_groupno"] board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.hit = 0 board.groupno = max_groupno + 1 board.orderno = 1 board.depth = 1 board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board/list')
def reple(request): new = Board() if request.method == 'POST': id = request.GET['id'] board = Board.objects.get(id=id) new.group_no = board.group_no new.title = request.POST['title'] new.content = request.POST['content'] new.order_no = board.order_no + 1 new.depth = board.depth + 1 authuser = request.session['authuser'] auth_username = authuser.get('name') auth_user_id = authuser.get('id') new.user_name = auth_username new.user_id = auth_user_id new.save() return HttpResponseRedirect("/board/list")
def write(request): # authuser = request.session['authuser'] # # if authuser is None: # return HttpResponseRedirect('/board') board_id = request.POST['id'] if board_id == '0': # 그냥 글쓰기이면 board = Board() board.title = request.POST['title'] board.content = request.POST['content'] value = Board.objects.aggregate( max_groupno=Max('groupno'))['max_groupno'] or 0 if board.groupno == 0: board.groupno = value + 1 user = User.objects.get(id=request.session['authuser']['id']) board.user = user board.save() else: # 답글이면 # 해당 board_id에 해당하는 객체 가져오기 board_parent = Board.objects.get(id=board_id) board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.groupno = board_parent.groupno board.orderno = board_parent.orderno + 1 Board.objects.filter(groupno=board.groupno).filter( orderno__gte=board.orderno).update(orderno=F('orderno') + 1) board.depth = board_parent.depth + 1 board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board')
def writereply(request): parentboard = Board.objects.get(id=request.POST['id']) board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.groupno = parentboard.groupno board.orderno = parentboard.orderno + 1 Board.objects.filter(groupno=board.groupno). \ filter(orderno__gte=board.orderno). \ update(orderno=F('orderno')+1) board.depth = parentboard.depth + 1 board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect(f'/board')
def add(request): board = Board() board.title = request.POST['title'] board.content = request.POST['content'] # 그룹넘버 구하기 g_no = Board.objects.aggregate(Max('group_no')) if (g_no['group_no__max'] == None): board.group_no = 1 else: board.group_no = g_no['group_no__max'] + 1 board.order_no = 1 board.depth = 0 authuser = request.session['authuser'] auth_username = authuser.get('name') auth_user_id = authuser.get('id') board.user_name = auth_username board.user_id = auth_user_id board.save() return HttpResponseRedirect("/board/")
def write_one(request): # 인증 authuser = request.session.get('authuser') if authuser is None: return HttpResponseRedirect('/board') board = Board() board.title = request.POST['title'] board.content = request.POST['content'] # max groupno value = Board.objects.aggregate(max_groupno=Max('groupno')) max_groupno = 0 if value['max_groupno'] is None else value['max_groupno'] board.groupno = max_groupno + 1 board.orderno = 1 board.depth = 1 board.user_id = request.session['authuser']['id'] board.save() # 기본 1페이지로 이동 return HttpResponseRedirect('/board')
def rewrite_one(request): # 인증 authuser = request.session.get('authuser') if authuser is None: return HttpResponseRedirect('/board') board = Board() board.title = request.POST['title'] board.content = request.POST['content'] # parent parent = Board.objects.get(id=request.POST['parentid']) # 같은 그룹 내 update orderno Board.objects.filter(groupno=parent.groupno).filter( orderno__gte=parent.orderno + 1).update(orderno=F('orderno') + 1) # 답글 저장 board.groupno = parent.groupno board.orderno = parent.orderno + 1 board.depth = parent.depth + 1 board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board')
def write(request): authuser = check_login_auth(request) if authuser is None: return HttpResponseRedirect('/user/loginform') board = Board() title = request.POST['title'] content = request.POST['content'] userid = request.session['authuser']['id'] orderno = 1 groupno = 1 groupnovalue = Board.objects.aggregate(max_groupno=Max('groupno')) if groupnovalue['max_groupno'] is not None: groupno = int(groupnovalue['max_groupno']) + 1 board.title = title board.content = content board.user_id = userid board.groupno = groupno board.orderno = orderno board.save() return HttpResponseRedirect('/board')
def write(request): result = auth(request) if result == True: return HttpResponseRedirect("/") if request.method == 'GET': return render(request, 'board/write.html') else: board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.hit = 0 groupno = Board.objects.aggregate(max_groupno=Max('groupno') + 1) if groupno['max_groupno'] is None: groupno['max_groupno'] = 1 board.groupno = groupno['max_groupno'] board.orderno = 1 board.depth = 0 board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board/list/')
def reply(request, id): result = auth(request) if result == True: return HttpResponseRedirect("/") if request.method == 'GET': data = {'id': id} return render(request, 'board/replyform.html', data) else: board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.hit = 0 parent_board = Board.objects.get(id=id) board.groupno = parent_board.groupno board.orderno = parent_board.orderno + 1 board.depth = parent_board.depth + 1 board.user_id = request.session['authuser']['id'] Board.objects.filter(groupno=board.groupno).filter( orderno__gte=board.orderno).update(orderno=F('orderno') + 1) board.save() return HttpResponseRedirect('/board/list/')