def submitThread(request): if request.user.is_authenticated(): user = request.user classify = request.POST.get('classify', '') title = request.POST.get('title', '') content = request.POST.get('content', '') if classify == '' or title == '' or content == '': return HttpResponse('some fields are empty') if classify == 'AN' and not user.is_staff: return HttpResponse('you are not manager') newThread = thread(title=title, content=content, readCount=0, likeCount=0, classify=classify, time=datetime.datetime.now(), lastTime=datetime.datetime.now()) newThread.author = user newThread.save() return HttpResponse('ok') else: return HttpResponse('please login')
def new(req, cid): cat = category.objects.get(id=cid) if req.method == 'GET': return rr('bbs/newthread.html', {'cat':cat,}, context_instance = RequestContext(req)) elif req.method == 'POST': _t = thread() _t.title = req.POST['threadname'] _t.text = req.POST['threadtext'] _t.user = req.user _t.posts = 0 _t.save() _ct = category_thread() _ct._t = _t _ct._c = cat _ct.save() return rd('/bbs/' + str(cid) + '/')