def articledetails(self, uid, aid):
     obj = db_session.query(Article).filter(Article.aid == aid).first()
     list = []
     # 获取现在的时间
     now_time = datetime.now()
     timestr = datetime.strftime(now_time, '%Y/%m/%d %H:%M:%S')
     if obj == None:
         dict = {}
         dict['status'] = 0
         list.append(dict)
     else:
         dict = {}
         dict['aid'] = obj.aid
         dict['type'] = obj.type
         dict['title'] = obj.title
         dict['fromid'] = obj.fromid
         dict['time'] = obj.time
         dict['content'] = obj.content
         dict['like'] = obj.like
         list.append(dict)
         # 写入用户足迹
         footstep = Footstep(uid=uid, aid=aid, time=timestr)
         db_session.add(footstep)
         try:
             db_session.commit()
         except Exception as r:
             current_app.logger.info(r)
         current_app.logger.info('{}的用户浏览了{}的文章'.format(uid, aid))
     return list
 def testInserExpert(self, name='未知'):
     u = Userclassifies(name)
     print(u)
     db_session.add(u)
     db_session.commit()
     id = u.id
     return id
    def register(self, username, passward, phone, mail, varifiycode):
        # username需要适当的名字
        username = getRadomStr() if username == None else username
        username = getRadomStr() if len(username) < 3 else username
        mail = '' if mail == None else mail
        if passward != None and varifiycode != None and phone != None and \
                len(passward) > 3 and len(varifiycode) == 4 and len(phone) == 11:

            # 这里验证验证码
            if varifiycode != '1234':
                current_app.logger.info('验证码错误,系统验证码:{}用户输入的验证码:{}'.format(
                    varifiycode, 1234))
                return 0

            # 查询是否已经有注册了
            u = db_session.query(User).filter(User.phone == phone).first()
            if u != None:
                current_app.logger.info('手机号{}已经注册过了'.format(phone))
                return 0

            u = User(username, generate_password_hash(passward), phone, mail,
                     'N', 2, 0)  # 2 设置为注册用户
            db_session.add(u)
            try:
                db_session.commit()
                current_app.logger.info('添加用户:{}'.format(u))
            except Exception as r:
                current_app.logger.error(r)
                return 0
            return 1
        else:
            current_app.logger.info('数据错误')
            return 0
    def applyExpert(self, name, degree, userId, pic1, pic2, pic3):

        expert = Expert(name, degree, pic1, pic2, pic3, userId)
        db_session.add(expert)
        try:
            db_session.commit()
            current_app.logger.info('添加专家:{}'.format(expert))
        except Exception as r:
            current_app.logger.error(r)
            return 0
        return 1
 def addhelpfor(self, title, content, fromid, toid):
     now_time = datetime.now()
     timestr = datetime.strftime(now_time, '%Y/%m/%d %H:%M:%S')
     list = []
     dict = {}
     help = Help(title=title, content=content, time=timestr, fromid=fromid, toid=toid)
     db_session.add(help)
     try:
         db_session.commit()
     except Exception as r:
         current_app.logger.info(r)
     dict['status'] = '成功向{}发起定向求助'.format(toid)
     list.append(dict)
     return list
Example #6
0
 def addcollect(self, uid, sid):
     list = []
     dict = {}
     collect = Collect(uid=uid, sid=sid)
     db_session.add(collect)
     try:
         db_session.commit()
         dict['status'] = 1
         list.append(dict)
     except Exception as r:
         current_app.logger.info(r)
         dict['status'] = 0
         list.append(dict)
     return list
Example #7
0
 def addshoppingcar(self, uid, sid):
     list = []
     dict = {}
     shoppingcar = Shoppingcar(uid=uid, sid=sid)
     db_session.add(shoppingcar)
     try:
         db_session.commit()
         dict['status'] = 1
         list.append(dict)
     except Exception as r:
         current_app.logger.info(r)
         dict['status'] = 0
         list.append(dict)
     return list
 def comment(self, type, id, uid, content):
     # 获取现在的时间
     now_time = datetime.now()
     timestr = datetime.strftime(now_time, '%Y/%m/%d %H:%M:%S')
     list = []
     dict = {}
     if type is '1' or type is '2':
         comment = Comment(replyid=id, uid=uid, content=content, time=timestr, type=type)
         db_session.add(comment)
         try:
             db_session.commit()
             dict['status'] = 'success'
         except Exception as r:
             current_app.logger.info(r)
             dict['status'] = 'fail'
     else:
         dict['status'] = '该类型不存在'
     list.append(dict)
     return list
from utils.dataBase import init_db
import random
init_db()
from utils.dataBase import db_session
from models.UserSubSysModels import Userclassifies
string = '专家{}'.format(random.randint(0, 100))
u = Userclassifies(string)
print('写入专家:', u)
db_session.add(u)
db_session.commit()
print(u.query.all())