Exemplo n.º 1
0
 def get(self, args):
     child_photo_id = args.get('child_photo_id')
     child_photo = ChildPhoto.find_by_id(child_photo_id)
     if not child_photo:
         return dict(child_photo_id=0, child_pic_url='')
     return dict(child_photo_id=child_photo.id,
                 child_pic_url=child_photo.child_pic_url)
Exemplo n.º 2
0
    def post(self, args):
        # 给照片点赞
        user = self.user
        child_photo_id = args.get('child_photo_id')
        redis_key = '{}_to_{}'.format(user.uid, child_photo_id)

        q = redis_client.get(redis_key)
        if q is None:
            # 当q是None的时候说明之前没有这个key。添加一个设置过期时间
            redis_client.set(redis_key, 0)
            redis_client.expire(redis_key, 86400)
        q = int(q) if q is not None else 1
        if q >= 5:
            return False

        # 点赞一个
        child_photo = ChildPhoto.find_by_id(child_photo_id)
        if not child_photo:
            return UserVerifyInfo.DATA_EXIST.value
        if child_photo.child_pic_num is None:
            child_photo.update(child_pic_num=1)
        else:
            child_photo.update(child_pic_num=child_photo.child_pic_num + 1)

        Like.add(uid=user.uid, child_photo_id=child_photo_id)

        redis_client.incr(redis_key)
        return True
Exemplo n.º 3
0
 def get(self, args):
     child_photo_id = args.get('child_photo_id')
     if child_photo_id is None:
         # 获取自己上传的照片
         user = self.user
         child_photo = ChildPhoto.find_by_uid(user.uid)
         if not child_photo:
             return dict(child_photo_id=0, child_pic_url='')
         return dict(child_photo_id=child_photo.id,
                     child_pic_url=child_photo.child_pic_url)
     else:
         child_photo = ChildPhoto.find_by_id(child_photo_id)
         if not child_photo:
             return dict(child_photo_id=0, child_pic_url='')
         return dict(child_photo_id=child_photo.id,
                     child_pic_url=child_photo.child_pic_url)
Exemplo n.º 4
0
    def get(self, args):
        child_photo_id = args.get('child_photo_id')
        if not child_photo_id:
            return UserVerifyInfo.CHILD_RANKING_LIST_PHOTO_ID.value

        # redis 存储这个人点赞的照片id
        user = self.user
        f = user.like_photo(child_photo_id)
        if f is False:
            return False

        # 点赞一个
        child_photo = ChildPhoto.find_by_id(child_photo_id)
        if not child_photo:
            return UserVerifyInfo.DATA_EXIST.value
        if child_photo.child_pic_num is None:
            child_photo.update(child_pic_num=1)
        else:
            child_photo.update(child_pic_num=child_photo.child_pic_num + 1)

        Like.add(uid=user.uid, child_photo_id=child_photo_id)

        return True