def answer(request, page): page = toInt(page) titleask = request.GET.get('titleask', '') if titleask == '': messages.info(request, u'Answer GET titleask is a NULL.') return render(request, 'blog/ask/ask.html', context=locals()) if request.method == 'POST': editor = request.POST['editor'] titleask = request.POST['titleask'] askrname = request.user #登录用户 if titleask == '': messages.info(request, u'Answer POST titleask is a NULL. ') return render(request, 'blog/ask/answer.html', context=locals()) else: answernumber = str( int(Ask.objects.get(titleask=titleask).answernumber) + 1) browsernumber = str( int(Ask.objects.get(titleask=titleask).browsernumber) + 1) askstatus = 'noreply' if answernumber == '0' else 'reply' date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") answers = Answer(titleask=titleask, askrname=askrname, \ editor=editor, answernumber = answernumber,browsernumber = browsernumber, date=date) Ask.objects.filter(titleask=titleask).update(askstatus=askstatus, answernumber=answernumber) answers.save() browsernumber = str( int(Ask.objects.get(titleask=titleask).browsernumber) + 1) Ask.objects.filter(titleask=titleask).update(browsernumber=browsernumber) ask_list = Ask.objects.filter(titleask=titleask) answer_list = Answer.objects.filter(titleask=titleask) answer_list, pageList, num_pages, page, offset, queryString = django_Page( request, answer_list, page, PAGE_NUM) #调用分页函数 return render(request, 'blog/ask/answer.html', context=locals())
def blogpage(request, page): page = toInt(page) if request.method == 'POST': cleanData = request.POST.dict() author = request.user id = cleanData.get('id', -1) subject = cleanData.get('subject', '') summary = cleanData.get('summary', '') content = cleanData.get('content', '') blog = Blogs.objects.filter(id=id) if blog: blog.update(author=author, subject=subject, summary=summary, content=content) else: blogs = Blogs(author=author, subject=subject, summary=summary, content=content) blogs.save() mylist = list(Blogs.objects.values().order_by( '-id')) #[(page-1)*PAGE_NUM:page*PAGE_NUM] kvs = [{'author': User}] #外键字典 mylist = list(get_model_values(mylist, kvs)) blogs_list, pageList, paginator, page = djangoPage(mylist, page, PAGE_NUM) offset = PAGE_NUM * (page - 1) data = dict(blogs=list(blogs_list), pageList=pageList, page=page, offset=offset) return JsonResponse(data, safe=True)
def noanswer(request, page): page = toInt(page) ask_list = Ask.objects.filter(askstatus='noreply') ask_list, pageList, num_pages, page, offset, queryString = django_Page( request, ask_list, page, PAGE_NUM) #调用分页函数 askProportion = askProportions(request) return render(request, 'blog/ask/list.html', context=locals())
def apiblogs(request, page): page = toInt(page) if request.method == 'POST': cleanData = request.POST.dict() author = request.user id = cleanData.get('id', -1) #print('========',id) subject = cleanData.get('subject', '') summary = cleanData.get('summary', '') content = cleanData.get('content', '') blog = Blogs.objects.filter(id=id) #print('========11',blog,id) if blog: blog.update(author=author, subject=subject, summary=summary, content=content) else: blogs = Blogs(author=author, subject=subject, summary=summary, content=content) blogs.save() mylist = list( Blogs.objects.values().order_by('-id'))[(page - 1) * PAGE_NUM:page * PAGE_NUM] kvs = [{'author': User}] #外键字典 return JsonResponse(list(get_model_values(mylist, kvs)), safe=False)
def users(request, page): page = toInt(page) Users = User.objects.all() #获得数据库记录 形式 users_list, pageList, paginator, page = djangoPage(Users, page, PAGE_NUM) offset = PAGE_NUM * (page - 1) return render(request, "blog_vue/user_list.html", context=locals())
def delete(request, id): id = toInt(id) Blogs.objects.filter(id=id).delete() return HttpResponseRedirect('/blog_vue/show/')
def show(request, page): page = toInt(page) return render(request, "blog_vue/show.html", context=locals())
def usersapi(request, page): page = toInt(page) mylist = list(User.objects.values())[(page - 1) * PAGE_NUM:page * PAGE_NUM] return JsonResponse(mylist, safe=False)