def adduser(self, username, userpassword, userquestion, useranswer): session = DBSession() try: if username != "" and not self.checkuserexist(username): session.add( User(user_name=username, user_password=userpassword, user_question=userquestion, user_answer=useranswer)) session.commit() session.close() # 数据库表连接后,操作后,要关闭 session = DBSession() userid = session.query( User.user_id).filter_by(user_name=username).one() session.add( Userinfo(userinfo_userid=userid[0])) # 通过userid链接两个表 session.commit() session.close() return True else: return False except Exception as a: print(a)
def addattention(self,usertokenstr,userid): #增加关注 session = DBSession() try: userid1 = session.query(Usertoken.usertoken_userid).filter_by(usertoken_str=usertokenstr).one() session.add(Attention(attention_userid=userid,attention_fansid=userid1[0])) session.commit() session.close() return True except Exception as a: print(a) return False
def usertokenadd(self, username): session = DBSession() try: usertoken = str(uuid.uuid4()) print(usertoken) a = Userorml() userid = a.getidbyname(username) print(userid) session.add( Usertoken(usertoken_str=usertoken, usertoken_userid=userid)) session.commit() session.close() return usertoken except Exception as a: print(a) return "False"
def publishforum(self,usertoken,forumtitle,forumdesp): session = DBSession() try: userid = session.query(Usertoken.usertoken_userid).filter_by(usertoken_str=usertoken).one() userinfoid = session.query(Userinfo.userinfo_id).filter_by(userinfo_userid=userid[0]).one() nowtime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()) session.add(Forum(forum_userinfoid=userinfoid[0], forum_title=forumtitle, forum_publishtime=nowtime, forum_desp=forumdesp)) session.commit() session.close() return True except Exception as a: print(a) return "False"
def forumcommentpublish(self,usertoken,forumid,commentcontent):#发布帖子的评论 session = DBSession() try: userid = session.query(Usertoken.usertoken_userid).filter_by(usertoken_str=usertoken).one() userinfoid = session.query(Userinfo.userinfo_id).filter_by(userinfo_userid=userid[0]).one() nowtime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()) session.add(Comment(comment_forumid=forumid, comment_userinfoid=userinfoid[0], comment_content=commentcontent, comment_time=nowtime)) session.commit() session.close() return True except Exception as a: print(a) return "False"
def forumpraise(self,usertoken,forumid,praisestatus): session = DBSession() try: userid = session.query(Usertoken.usertoken_userid).filter_by(usertoken_str=usertoken).one() if int(praisestatus) == 1 and session.query(Forum).filter_by(forum_id = forumid).count()>0: session.query(Praise).filter_by(praise_forumid = forumid, praise_userid = userid[0]).delete() session.commit() session.close() return "0" elif int(praisestatus) == 0: if session.query(Praise).filter_by(praise_forumid =forumid,praise_userid = userid[0]).count()>0: return "False" else: nowtime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()) session.add(Praise(praise_forumid = forumid, praise_userid = userid[0])) session.commit() session.close() return "1" else: return "False" except Exception as a: print(a) return "False"
user_password="******", user_question="我读哪个大学", user_answer="贵大"), User(user_id=4, user_name="小绿", user_password="******", user_question="杜鹃花是什么颜色", user_answer="红色"), User(user_id=5, user_name="小黄", user_password="******", user_question="现在是几点", user_answer="起点") ] for i in userlist: session.add(i) if session.query(Userinfo).count() == 0: userinfolist = [ Userinfo(userinfo_id=1, userinfo_img="timer.jgp", userinfo_userid=1, userinfo_attentionnum=1, userinfo_fansnum=1), Userinfo(userinfo_id=2, userinfo_img="timer.jgp", userinfo_userid=2, userinfo_attentionnum=2, userinfo_fansnum=1), Userinfo(userinfo_id=3, userinfo_img="timer.jgp",