當前位置: 首頁>>代碼示例>>Python>>正文


Python Activity.create方法代碼示例

本文整理匯總了Python中activity.Activity.create方法的典型用法代碼示例。如果您正苦於以下問題:Python Activity.create方法的具體用法?Python Activity.create怎麽用?Python Activity.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在activity.Activity的用法示例。


在下文中一共展示了Activity.create方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_follower

# 需要導入模塊: from activity import Activity [as 別名]
# 或者: from activity.Activity import create [as 別名]
    def add_follower(cls, leader, follower):
        # TODO: expand to handle more than 5000 followers, using extra entities
        follower_id = follower.key().id()  # TickUser.get_by_user_id(follower.user_id(),keys_only=True).id()
        leader_id = leader.key().id()
        check = cls.all(keys_only=True).ancestor(leader).filter("followers_ids =", follower_id).get()
        if not check:
            entity = cls.all().ancestor(leader).filter("leader_id =", leader_id).get()
            if entity:
                entity.follower_ids.append(follower_id)
                index = entity.get_follow_index()
                index.add_followers(follower.all_user_ids)
                index.put()
                entity.put()
            else:
                new_entity = cls(parent=leader, leader_id=leader_id, follower_ids=[follower_id])
                new_entity.put()
                new_index = FollowIndex(parent=new_entity)
                new_index.add_leaders(leader.all_user_ids)
                new_index.add_followers(follower.all_user_ids)
                new_index.put()
            from activity import Activity

            Activity.create(
                "<actor>|began following|<target>", actor=follower, target=leader, extra_recipients=[leader]
            )
            return True
        else:
            return False
開發者ID:cheesun,項目名稱:chees-test,代碼行數:30,代碼來源:follow.py

示例2: remove_follower

# 需要導入模塊: from activity import Activity [as 別名]
# 或者: from activity.Activity import create [as 別名]
    def remove_follower(leader, follower):
        follower_id = follower.key().id()
        existing = (
            Follow.all()
            .ancestor(leader)
            .filter("leader_id =", leader.key().id())
            .filter("follower_ids =", follower_id)
            .get()
        )
        if not existing:
            return False
        existing.follower_ids.remove(follower_id)
        existing.put()
        # do dependent index
        index = existing.get_follow_index()
        for user_id in follower.all_user_ids:
            index.remove_follower(user_id)
        index.put()
        from activity import Activity

        Activity.create("<actor>|stopped following|<target>", actor=follower, target=leader, extra_recipients=[leader])
        return True
開發者ID:cheesun,項目名稱:chees-test,代碼行數:24,代碼來源:follow.py


注:本文中的activity.Activity.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。