Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.shortcuts import render
- import random
- from django_web.models import *
- from django.views.decorators.csrf import csrf_exempt
- # Create your views here.
- name_list = ['赵四','刘能','谢大脚','谢长贵']
- global com_index
- com_index = 0
- # POST : {'tag':'java','sub_tag':'basic'}
- def index(request):
- tag = request.POST.get('tag')
- comments = Comment.objects(tag='a')
- com_list = {'Comment': comments}
- #for item in comments:
- # print(item.com_id)
- return render(request, 'website.html', com_list)
- #POST : {'tag':'java'}
- def get_comment(request):
- tag = request.POST.get('tag')
- comments = Comment.objects(tag='tag')
- com_list = {'Comment': comments}
- return render(request, 'website.html', com_list)
- #POST : {'tag':'java','content':'java is fun','time':'2017/11/28'}
- def post_comment(request):
- tag = request.POST.get('tag')
- content = request.POST.get('content')
- cur_time = request.POST.get('time')
- user_name = name_list[random.randint(0,len(name_list)-1)]
- global com_index
- new_comment = Comment(tag,user_name,content,[],com_index,cur_time)
- com_index = com_index + 1
- new_comment.save()
- return render(request,'website.html')
- def add_to_list(com, _user_name, _content):
- # print(_content)
- for item in com:
- # print(item.user_name + "!!!!!!!!!" + item.content)
- item.rep_list.append(Reply(user_name=_user_name, content=_content))
- item.save()
- #POST {'com_id':23, 'content':'is fun','time':''}
- def post_reply(request):
- _obj_id = request.POST.get('com_id')
- # print(_obj_id)
- comment = Comment.objects(com_id = _obj_id)
- # print(len(comment))
- add_to_list(comment,name_list[random.randint(0,len(name_list)-1)], request.POST.get('content'))
- return render(request, 'website.html')
- def modify(request):
- if request.user.username.find('TG') == -1:
- # print("user cannot login")
- return render(request,'website.html')
- else:
- #print("login")
- return render(request, 'tg_admin.html')
- #{'tag':'java','sub_tag':'basic'}
- def get_article(request):
- objts = Article.objects(tag=request.POST.get('tag'),sub_tag = request.POST.get('sub_tag'))
- #print(len(objts))
- art_list = {'Article': objts}
- return render(request, 'tg_admin.html',art_list)
- #{'tag':'java','sub_tag':'basic',content:''}
- def post_article(request):
- Article.objects(tag=request.POST.get('tag'), sub_tag=request.POST.get('sub_tag')).delete()
- obt = Article(tag=request.POST.get('tag'), sub_tag=request.POST.get('sub_tag'),content = request.POST.get('content'))
- obt.save()
- #print(obt.tag + ' ' + obt.sub_tag + ' ' + obt.content)
- return render(request, 'tg_admin.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement