def create_thread(self, author, subject, message, readperm=1, attaches=[], tags=None): subject = escape(subject) xss = XssParser() xss.feed(message) message = xss.result at_users = xss.at_users print at_users hasAttach = (len(attaches)>0) post = Post(author=author, authorip=author.loginip, \ subject=subject, message=message, position=0, hasattach=hasAttach, \ readperm=readperm) thread = Thread(author=author, subject=subject, abstract="abstract", \ hasattach=hasAttach, tags=tags) try : thread.save() post.thread = thread post.save() except Exception, e: raise PostException(cause=e)
def writethread(request): if request.method =='POST' and _is_user: title = request.POST['title'] post = Thread.objects(title=title) # try: # post = Thread.objects(title=title) # except Thread.DoesNotExist: # return HttpResponse(u'failed') # if post: # return HttpResponse(u'failed') postobj = Thread(title=title) postobj.user_id = ObjectId(request.POST['user_id']) # if request.POST['thread_id']: postobj.thread_id = ObjectId(request.POST['thread_id']) postobj.content = request.POST['content'] postobj.save() repost = dumps({'title':postobj.title,'id':str(postobj.id)}, ensure_ascii=False, indent=2) return HttpResponse(repost) else: return HttpResponse(u'failed')
def insert_thread(cls): author = MotssUser.objects.all()[1] thread = Thread(author=author, subject='test insert thread') thread.save() return thread