def addJoke(self,userid,tagid,title,content,code): tagArr=self.selectAllTag() userArr=self.selectAllUser() if userid=='' or tagid=='' or content=='' or code=='': self.render('admin/addjoke.html',info='',tags=tagArr,users=userArr) elif code != 'mingle': self.render('admin/addjoke.html',info='Code error',tags=tagArr,users=userArr) elif not self.checkUser(userid): self.render('admin/addjoke.html',info='Userid error',tags=tagArr,users=userArr) elif not self.checkTag(tagid): self.render('admin/addjoke.html',info='Tagid error',tags=tagArr,users=userArr) else: jokeid=uuid.uuid1().hex newjoke=Joke() newjoke.jokeid=jokeid newjoke.userid=userid newjoke.title=title newjoke.tagid=tagid newjoke.content=content self.db.add(newjoke) self.db.commit() self.db.close() self.render('admin/addjoke.html',info='Success',tags=tagArr,users=userArr)
def addJoke(self, userid, title, content, tagid): if userid == '': self.status = 201 self.message = 'userid不能为空' jsonStr = self.getJsonResult() self.write(jsonStr) elif tagid == '': self.status = 201 self.message = 'tagid不能为空' jsonStr = self.getJsonResult() self.write(jsonStr) elif not self.checkUser(userid): self.status = 201 self.message = '该userid不存在' jsonStr = self.getJsonResult() self.write(jsonStr) elif not self.checkTag(tagid): self.status = 201 self.message = '该tagid不存在' jsonStr = self.getJsonResult() self.write(jsonStr) elif content == '': self.status = 201 self.message = 'content不能为空' jsonStr = self.getJsonResult() self.write(jsonStr) else: jokeid = uuid.uuid1().hex newjoke = Joke() newjoke.jokeid = jokeid newjoke.userid = userid newjoke.title = title newjoke.tagid = tagid newjoke.content = content self.db.add(newjoke) self.db.commit() self.db.close() jokes = self.db.query( Joke.jokeid, Joke.title, Joke.content, User.username, Tag.content).filter(Joke.jokeid == jokeid).filter( Joke.userid == User.userid).filter( Joke.tagid == Tag.tagid).all() joke = jokes[0] dic = {} dic['jokeid'] = joke[0] dic['title'] = joke[1] dic['content'] = joke[2] dic['username'] = joke[3] dic['tagcontent'] = joke[4] self.status = 200 jsonStr = self.getJsonResult(result=jokes) self.write(jsonStr)