Beispiel #1
0
	def add(cls, session_id, value):
		obj = cls(session_id = session_id, value = value, add_time = long(time.time()))
		session = DBSession()
		session.add(obj)
		session.commit()
		session.close()
		return True
Beispiel #2
0
	def add(cls, name, url):
		obj = cls(uid = uid, name = name, url = url, add_time = long(time.time()))
		session = DBSession()
		session.add(obj)
		session.commit()
		session.close()
		return True
Beispiel #3
0
	def addAnswer(cls, questionId, answerContent, userId):
		obj = cls(question_id = questionId, answer_content = answerContent, uid = userId, add_time = long(time.time()))
		session = DBSession()
		session.add(obj)
		session.commit()
		session.close()
		return True
Beispiel #4
0
	def addAnswerComment(cls, answer_id, uid, message):
		obj = cls(answer_id = answer_id, uid = uid, message = message)
		session = DBSession()
		session.add(obj)
		session.commit()
		session.close()
		return True
Beispiel #5
0
	def add(cls, userid, linkid, type):
		obj = cls(user_id = userid, link_id = linkid, type = type, add_time = long(time.time()))
		session = DBSession()
		session.add(obj)
		session.commit()
		session.close()
		return True
Beispiel #6
0
	def addAnswerVote(cls, answer_id, answer_uid, vote_uid, vote_value):
		obj = cls(answer_id = answer_id, answer_uid = answer_uid, vote_uid = vote_uid, add_time = long(time.time()), vote_value = vote_value, reputation_factor = 1)
		session = DBSession()
		session.add(obj)
		session.commit()
		session.close()
		return True
Beispiel #7
0
 def addQuestion(cls, question_content, question_detail, published_uid):
     obj = cls(question_content = question_content, question_detail = question_detail, 
         published_uid = published_uid, add_time = long(time.time()), update_time = long(time.time()))
     session = DBSession()
     session.add(obj)
     session.commit()
     session.close()
     return True
Beispiel #8
0
	def addUser(cls, username, email, password):
		hashed_password = bcrypt.hashpw(tornado.escape.utf8(password), bcrypt.gensalt())
		print hashed_password
		ret = cls(name = username, email = email, hashed_password = hashed_password)
		session = DBSession()
		session.add(ret)
		session.commit()
		session.close()
		return True
Beispiel #9
0
	def follow(cls, fansUid, friendUid):
		''' 
		添加关注
		同时更新用户表的粉丝数和关注数
		'''
		ret = cls(fans_uid = fansUid, friend_uid = friendUid)
		session = DBSession()
		session.add(ret)
		session.commit()
		session.close()


		# 更新uid为fansUid的关注人数和粉丝数
		following = cls.countFollowing(fansUid)
		follower = cls.countFollower(fansUid)
		Users.updateFollowCount(fansUid, follower, following)

		# 更新uid为friendUid的关注人数和粉丝数
		following = cls.countFollowing(friendUid)
		follower = cls.countFollower(friendUid)
		Users.updateFollowCount(friendUid, follower, following)
		return True
Beispiel #10
0
import sys
sys.path.append("..")
from db.dbSession import BaseModel, DBSession
from sqlalchemy import Column, String, Integer

class AutoUser(BaseModel):
    """
    user model
    """
    __tablename__ = 'authors'

    id = Column(Integer, primary_key=True, nullable=False)
    name = Column(String(64), nullable=False)
    hashed_password = Column(String(64), nullable=False)
    email = Column(String(64), nullable=False)



if __name__ == "__main__":
	# 创建session对象:
	session = DBSession()
	# 创建新User对象:
	new_user = AutoUser(id='6', name='Bob', hashed_password='******', email = '*****@*****.**')
	# 添加到session:
	session.add(new_user)
	# 提交即保存到数据库:
	session.commit()
	# 关闭session:
	session.close()