def InsertFuncOk(requset): if requset.method == 'POST': Guest( title = requset.POST.get('title'), content = requset.POST.get('content'), regdate = datetime.now() ).save() # insert 처리 return HttpResponseRedirect('/guest')
def InsertOkFunc(request): if request.method == 'POST': #print(request.POST.get('title')) #print(request.POST['title']) Guest(title=request.POST['title'], content=request.POST['content'], regdate=datetime.now()).save() #ORM의 추가 return HttpResponseRedirect('/guest') #추가 후 목록 보기 else: return HttpResponseRedirect('/guest/insert')
def InsertFuncOk(request): if request.method == "POST": Guest( # Guest 클래스로 다가. myno=request.POST.get("myno"), # 컬럼명 = 받는 값(넘어오는 파라미터 값). title=request.POST.get("title"), content=request.POST.get("content"), regdate=datetime.now(), ).save() # save를 쓰면 Insert가 됨. return HttpResponseRedirect("/guest") # 추가 후 목록 보기!!.
def InsertFuncOk(request): if request.method == 'POST' : print(request.POST.get('title')) print(request.POST['title']) # 위와 결과 동일 Guest( title= request.POST.get('title'), content = request.POST.get('content'), regdate = datetime.now() ).save() # 레코드 추가 insert into myguest_guest values(...)와 같음. # 수정 g = Guest.objects.get(id = 1) g.title = request.POST.get('title') g.save() # 바로 수정이 된다. update myguest_guest set title =...와 동일 # 삭제 g = Guest.objects.get(id =1) g.delete() # delete from myguest_guest whre id = 1 와 동일 return HttpResponseRedirect('/guest') # 추가 후 목록보기
def get(self, request, *args, **kwargs): code = request.GET.get('code') state = request.GET.get('state') if code and state: access_token = get_access_token(code, state) email, nick, avatar = get_user_info(access_token) guest = Guest.objects.filter(email=email) token = self.create_token() if guest.exists(): guest = guest[0] guest.token = token guest.save() else: status, avatar_path = save_image( avatar, '{0}{1}.png'.format(nick, unicode(time.time()).split('.')[0])) guest = Guest(email=email, nick=nick, token=token) guest.set_password('123456q_+|') if status: guest.avatar = avatar_path guest.save() comment = Comment.objects.filter(state=state) aid = 0 if not comment.exists(): comment = CommentReply.objects.filter(state=state) else: aid = comment[0].belong.id send_mail('新评论', '你有一条新评论, 登陆查看 www.rapospectre.com', '*****@*****.**', ['*****@*****.**'], fail_silently=True) if comment.exists(): comment = comment[0] comment.author = guest comment.review = True comment.save() if aid == 0: aid = comment.comment.belong.id send_html_mail('评论回复', comment.to, comment.comment.belong, [comment.to.email]) request.session['token'] = token return HttpResponseRedirect('/blog/{0}'.format(aid))
def get(self, request, *args, **kwargs): code = request.GET.get('code') state = request.GET.get('state') if code and state: access_token = get_access_token(code, state) gid, email, nick, avatar = get_user_info(access_token) guest = Guest.objects.filter(uid=gid) token = self.create_token() if guest.exists(): guest = guest[0] guest.token = token guest.save() else: # status, avatar_path = save_image(avatar, '{0}{1}.png'.format(nick, unicode(time.time()).split('.')[0])) guest = Guest(email=email, nick=nick, token=token, uid=gid) guest.set_password('123456q_+|') # if status: guest.avatar = avatar guest.save() comment = Comment.objects.filter(state=state) aid = 0 if not comment.exists(): comment = CommentReply.objects.filter(state=state) else: aid = comment[0].belong.id send_mail('新评论', '你有一条新评论, 登陆查看 www.rapospectre.com', '*****@*****.**', ['*****@*****.**'], fail_silently=True) if comment.exists(): comment = comment[0] comment.author = guest comment.review = True comment.save() if aid == 0: aid = comment.comment.belong.id send_html_mail('评论回复', comment.to, comment.comment.belong, [comment.to.email]) request.session['token'] = token return HttpResponseRedirect('/blog/{0}'.format(aid))