예제 #1
0
def feed():
    feedline = 'feedline:' + str(current_user.id)
    feedlist = []
    for feedid in conn.zrange(feedline,
                              0,
                              sys.maxsize,
                              desc=True,
                              withscores=False,
                              score_cast_func=float):
        dict = {}
        feedid = byte2int(feedid)
        feed = Feed.query.filter_by(id=feedid).first()
        user = User.query.filter_by(id=feed.userId).first()
        dict['name'] = user.nickname
        dict['id'] = user.id
        dict['headurl'] = user.head_url
        if EventType(feed.type) == EventType.DYNAMIC:  # 动态的话
            dict['action'] = '发布了动态'
        elif EventType(feed.type) == EventType.FOLLOW:  # 关注的其他人
            dict['action'] = '关注了别人'
        elif EventType(feed.type) == EventType.COMMENT:  # 评论了
            dict['action'] = '评论了动态'
        elif EventType(feed.type) == EventType.SHARE:  # 分享了图片功能
            dict['action'] = '分享了系统的功能'
        dict['data'] = eval(feed.data)['detail']  # 字典类型
        feedlist.append(dict)
    return render_template('feed.html', feedlist=feedlist)
def deleteinbatch(userid, albumid):
    rediskey = 'album:' + str(userid) + ':' + str(albumid)
    for imgid in conn.zrange(rediskey, 0, sys.maxsize, desc=True, withscores=False, score_cast_func=float):
        img = Image.query.filter_by(id=imgid).first()
        # 删除mysql
        fdfs_client.delete(img.url[len(fdfs_addr):])
        db.session.delete(img)
        db.session.commit()
        # 删除redis
        conn.zrem(rediskey, imgid)
    return True
예제 #3
0
def index(albumid):
    rediskey = 'album:' + str(current_user.id) + ':' + albumid
    imglist = []
    for imgid in conn.zrange(rediskey,
                             0,
                             sys.maxsize,
                             desc=True,
                             withscores=False,
                             score_cast_func=float):
        #imgid = str(imgid, encoding="utf-8")
        #imgid = int(imgid)
        imgid = byte2int(imgid)
        img = Image.query.filter_by(id=imgid).first()
        imglist.append(img)
    return render_template('albumdetail.html',
                           imglist=imglist,
                           albumid=albumid)
예제 #4
0
def followeelist(userid):
    followeekey = 'followee:' + userid + ':1'
    followeelist = []
    for userid in conn.zrange(followeekey,
                              0,
                              sys.maxsize,
                              desc=True,
                              withscores=False,
                              score_cast_func=float):
        dict = {}
        userid = str(userid, encoding="utf-8")
        userid = int(userid)
        user = User.query.filter_by(id=userid).first()
        dict['id'] = userid
        dict['name'] = user.nickname
        dict['url'] = user.head_url
        followeelist.append(dict)
    return followeelist
 def dohandler(self, eventModel):
     # print('取消关注的事件发生了')
     # 得到取消关注人的id,获取它的新鲜事列表,获取当前操作用户的新鲜事流,按照顺序删除
     userid = eventModel.entityId
     db.session.commit()
     feedlist = Feed.query.filter_by(userId=userid).order_by(
         Feed.createtime.desc()).all()
     count = 0
     feedline = 'feedline:' + str(eventModel.actorId)
     for feedid in conn.zrange(feedline,
                               0,
                               sys.maxsize,
                               desc=True,
                               withscores=False,
                               score_cast_func=float):
         feedid = str(feedid, encoding="utf-8")
         feedid = int(feedid)
         if count <= len(feedlist) - 1 and feedid == feedlist[count].id:
             conn.zrem(feedline, feedid)
             count = count + 1
 def dohandler(self, eventModel):
     # 评论评论不算做新鲜事
     if eventModel.entityType == EntityType.COMMENT:
         return
     followerkey = 'follower:1:' + str(eventModel.actorId)
     feed = Feed(eventModel.eventType, eventModel.actorId,
                 json.dumps(eventModel.dict))
     db.session.add(feed)
     db.session.flush()
     db.session.commit()
     for userid in conn.zrange(followerkey,
                               0,
                               sys.maxsize,
                               desc=True,
                               withscores=False,
                               score_cast_func=float):
         userid = str(userid, encoding="utf-8")
         userid = int(userid)
         user = User.query.filter_by(id=userid).first()
         feedline = 'feedline:' + str(user.id)
         conn.zadd(feedline, {feed.id: time.time()})
예제 #7
0
def ajaxdetail():
    data = json.loads(request.get_data(as_text=True))
    albumid = data['albumid']
    rediskey = 'album:' + str(current_user.id) + ':' + albumid
    imglist = []
    for imgid in conn.zrange(rediskey,
                             0,
                             sys.maxsize,
                             desc=True,
                             withscores=False,
                             score_cast_func=float):
        dict = {}
        imgid = byte2int(imgid)
        img = Image.query.filter_by(id=imgid).first()
        if ImageType(img.action) == ImageType.ORIGIN:
            proimg = Image.query.filter_by(orig_id=imgid).first()
            if proimg != None: continue
            dict['url'] = img.url
            dict['id'] = img.id
            imglist.append(dict)
        if len(imglist) == 6: break
    return jsonify(code=200, imglist=imglist, albumid=albumid)