예제 #1
0
def SerializeItem(model, userid=None, dataprocessing=None, notreturn=[]):
    '''
        序列化单个对象
    '''
    li = []
    dicts = {}
    columns = [c.key for c in class_mapper(model.__class__).columns]

    for c in columns:
        # print(c)

        # 不需要返回的字段直接排除不返回数据
        if str(c) not in notreturn:

            try:
                # 优先处理数组和字段的对象

                cc = eval(getattr(model, c))
                if isinstance(cc, dict):
                    li.append((c, cc))

                if isinstance(cc, list):
                    li.append((c, cc))

            except:

                # 不符合数组字段类型的进入date datetime str 等类型的返回

                if type(getattr(model, c)) == datetime.datetime:
                    li.append((c, DateTimeForStr(getattr(model, c))))

                elif type(getattr(model, c)) == datetime.date:
                    li.append((c, DateForStr(getattr(model, c))))

                else:
                    if getattr(model, c) == '' or getattr(model, c) == None:
                        li.append((c, ''))
                    else:
                        li.append((c, getattr(model, c)))

                # 持续化处理--------------------------------------------
                '''
                    添加返回项的方法
                    li.append(('参数名' , 值))

                    # 获取model原有的字段名的值
                    getattr(model, 'id') 获取model id 的值
                '''

                if dataprocessing == 'getarticlelist':
                    if c == 'cover':
                        li.append(
                            ('cover',
                             SERVER_STATICLOADURL + getattr(model, 'cover')))

        else:
            pass
    for s in li:
        dicts.update(dict([s]))
    return dicts
예제 #2
0
파일: views.py 프로젝트: weivis/My-Website
def login(request):

    hmduserreturncode = 1000
    email = request.get('email', None)
    password = request.get('password', None)

    account = Account.query.filter(Account.email == email).first()

    if not account:
        return ReturnCode.paramete_error, '用户不存在', ''

    if account.status == 2:
        return hmduserreturncode, '黑名单用户 禁止登录', ''

    if check_password_hash(str(account.password), password):
        md5 = hashlib.md5(
            (account.email +
             DateTimeForStr(datetime.now())).encode()).hexdigest()
        account.token = str(md5)
        db.session.commit()
        # return 400, '登录成功', {'Token':md5, 'userID': str(user.id)}
        return ReturnCode.ok, '登录成功', {
            'Token': md5,
            'userID': str(account.id),
            'username': account.username,
            'head': SERVER_GULAOBURL + '/static/head/' + account.profile,
            'group': account.account_group
        }

    return ReturnCode.paramete_error, ' 邮箱或密码不正确', ''
예제 #3
0
def login(request):

    hmduserreturncode = 1000

    email = GetRequestJsonData(request, 'email', None)
    password = GetRequestJsonData(request, 'password', None)

    user = User.query.filter(User.email == email).first()
    if not user:
        return ReturnCode.paramete_error, '用户不存在', ''

    if user.userstatus == 2:
        return hmduserreturncode, '黑名单用户 禁止登录', ''

    if check_password_hash(str(user.password), password):
        md5 = hashlib.md5((user.email + DateTimeForStr(datetime.now())).encode()).hexdigest()
        user.token = str(md5)
        db.session.commit()
        # return 400, '登录成功', {'Token':md5, 'userID': str(user.id)}
        return ReturnCode.ok, '登录成功', {'Token':md5, 'userID': str(user.id), 'username':user.username, 'head':SERVER_GULAOBURL + '/static/head/' + user.head, 'userstatus':user.userstatus}
        

    return ReturnCode.paramete_error, ' 邮箱或密码不正确', ''
예제 #4
0
def SerializeliData(model, userid=None, dataprocessing=None, notreturn=[]):
    '''
        单对象序列化器
    '''
    li = []
    dicts = {}

    from sqlalchemy.orm import class_mapper
    columns = [c.key for c in class_mapper(model.__class__).columns]

    for c in columns:
        print(c)

        if str(c) not in notreturn:

            try:
                cc = eval(getattr(model, c))
                if isinstance(cc, dict):
                    li.append((c, cc))

                if isinstance(cc, list):
                    li.append((c, cc))

            except:

                if type(getattr(model, c)) == datetime.datetime:
                    li.append((c, DateTimeForStr(getattr(model, c))))

                elif type(getattr(model, c)) == datetime.date:
                    li.append((c, DateForStr(getattr(model, c))))

                else:
                    if getattr(model, c) == '' or getattr(model, c) == None:
                        li.append((c, ''))
                    else:
                        li.append((c, getattr(model, c)))

                # 自增条件--------------------------------------------
                if c == 'author_userid' and userid != None:
                    li.append(('follow_status',
                               GetFollowType(userid, getattr(model, c))))

                if c == 'parent_comment_id':
                    if int(getattr(model, 'seedtype')) == 1:
                        li.append(('parent_comment_id', getattr(model, 'id')))

                if dataprocessing == 'queryvideo':

                    videotag = VideoTag.query.filter(
                        VideoTag.videoid == getattr(model, 'id')).all()
                    dataprocessing_taglist = [{
                        'tagid':
                        i.tagid,
                        'tagname':
                        VideoTagName.query.filter_by(
                            id=i.tagid).first().tagname
                    } for i in videotag]

                    li.append(('taglist', dataprocessing_taglist))

        else:
            pass

    for s in li:
        dicts.update(dict([s]))

    return dicts