当前位置: 首页>>代码示例>>Python>>正文


Python MyTBAHelper.add_favorite方法代码示例

本文整理汇总了Python中helpers.mytba_helper.MyTBAHelper.add_favorite方法的典型用法代码示例。如果您正苦于以下问题:Python MyTBAHelper.add_favorite方法的具体用法?Python MyTBAHelper.add_favorite怎么用?Python MyTBAHelper.add_favorite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在helpers.mytba_helper.MyTBAHelper的用法示例。


在下文中一共展示了MyTBAHelper.add_favorite方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from helpers.mytba_helper import MyTBAHelper [as 别名]
# 或者: from helpers.mytba_helper.MyTBAHelper import add_favorite [as 别名]
    def post(self, team_number):
        self._require_login()
        self._require_registration()

        current_user_id = self.user_bundle.account.key.id()
        team_key = 'frc{}'.format(team_number)

        if self.request.get('favorite'):
            favorite = Favorite(
                parent=ndb.Key(Account, current_user_id),
                user_id=current_user_id,
                model_type=ModelType.TEAM,
                model_key=team_key
            )
            MyTBAHelper.add_favorite(favorite)
        else:
            MyTBAHelper.remove_favorite(current_user_id, team_key, ModelType.TEAM)

        subs = self.request.get_all('notification_types')
        if subs:
            subscription = Subscription(
                parent=ndb.Key(Account, current_user_id),
                user_id=current_user_id,
                model_type=ModelType.TEAM,
                model_key=team_key,
                notification_types=[int(s) for s in subs]
            )
            MyTBAHelper.add_subscription(subscription)
        else:
            MyTBAHelper.remove_subscription(current_user_id, team_key, ModelType.TEAM)

        self.redirect('/account/mytba?status=team_updated#my-teams')
开发者ID:ehamwey,项目名称:the-blue-alliance,代码行数:34,代码来源:account_controller.py

示例2: post

# 需要导入模块: from helpers.mytba_helper import MyTBAHelper [as 别名]
# 或者: from helpers.mytba_helper.MyTBAHelper import add_favorite [as 别名]
    def post(self, event_key):
        self._require_registration()

        current_user_id = self.user_bundle.account.key.id()

        if self.request.get("favorite"):
            favorite = Favorite(
                parent=ndb.Key(Account, current_user_id),
                user_id=current_user_id,
                model_type=ModelType.EVENT,
                model_key=event_key,
            )
            MyTBAHelper.add_favorite(favorite)
        else:
            MyTBAHelper.remove_favorite(current_user_id, event_key, ModelType.EVENT)

        subs = self.request.get_all("notification_types")
        if subs:
            subscription = Subscription(
                parent=ndb.Key(Account, current_user_id),
                user_id=current_user_id,
                model_type=ModelType.EVENT,
                model_key=event_key,
                notification_types=[int(s) for s in subs],
            )
            MyTBAHelper.add_subscription(subscription)
        else:
            MyTBAHelper.remove_subscription(current_user_id, event_key, ModelType.EVENT)

        self.redirect("/account/mytba?status=event_updated#my-events")
开发者ID:the-blue-alliance,项目名称:the-blue-alliance,代码行数:32,代码来源:account_controller.py

示例3: post

# 需要导入模块: from helpers.mytba_helper import MyTBAHelper [as 别名]
# 或者: from helpers.mytba_helper.MyTBAHelper import add_favorite [as 别名]
    def post(self):
        if not self.user_bundle.user:
            self.response.set_status(401)
            return

        model_type = int(self.request.get("model_type"))
        model_key = self.request.get("model_key")
        user_id = self.user_bundle.user.user_id()

        fav = Favorite(parent=ndb.Key(Account, user_id), user_id=user_id, model_key=model_key, model_type=model_type)
        MyTBAHelper.add_favorite(fav)
开发者ID:fangeugene,项目名称:the-blue-alliance,代码行数:13,代码来源:ajax_controller.py

示例4: update_model_preferences

# 需要导入模块: from helpers.mytba_helper import MyTBAHelper [as 别名]
# 或者: from helpers.mytba_helper.MyTBAHelper import add_favorite [as 别名]
    def update_model_preferences(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to update model preferences")
        user_id = PushHelper.user_email_to_id(current_user.email())
        model_key = request.model_key
        output = {}
        code = 0

        if request.favorite:
            fav = Favorite(
                parent=ndb.Key(Account, user_id),
                user_id=user_id,
                model_key=model_key,
                model_type=request.model_type
            )
            result = MyTBAHelper.add_favorite(fav, request.device_key)
            if result == 200:
                output['favorite'] = {"code":    200,
                                      "message": "Favorite added"}
                code += 100
            elif result == 304:
                output['favorite'] = {"code":    304,
                                      "message": "Favorite already exists"}
                code += 304
            else:
                output['favorite'] = {"code":    500,
                                      "message": "Unknown error adding favorite"}
                code += 500
        else:
            result = MyTBAHelper.remove_favorite(user_id, model_key, request.device_key)
            if result == 200:
                output['favorite'] = {"code":    200,
                                      "message": "Favorite deleted"}
                code += 100
            elif result == 404:
                output['favorite'] = {"code":    404,
                                      "message": "Favorite not found"}
                code += 404
            else:
                output['favorite'] = {"code":    500,
                                      "message": "Unknown error removing favorite"}
                code += 500

        if request.notifications:
            sub = Subscription(
                parent=ndb.Key(Account, user_id),
                user_id=user_id,
                model_key=model_key,
                model_type=request.model_type,
                notification_types=PushHelper.notification_enums_from_string(request.notifications)
            )
            result = MyTBAHelper.add_subscription(sub, request.device_key)
            if result == 200:
                output['subscription'] = {"code":    200,
                                          "message": "Subscription updated"}
                code += 100
            elif result == 304:
                output['subscription'] = {"code":    304,
                                          "message": "Subscription already exists"}
                code += 304
            else:
                output['subscription'] = {"code":    500,
                                          "message": "Unknown error adding favorite"}
                code += 500
        else:
            result = MyTBAHelper.remove_subscription(user_id, model_key, request.device_key)
            if result == 200:
                output['subscription'] = {"code":    200,
                                          "message": "Subscription removed"}
                code += 100
            elif result == 404:
                output['subscription'] = {"code":    404,
                                          "message": "Subscription not found"}
                code += 404
            else:
                output['subscription'] = {"code":    500,
                                          "message": "Unknown error removing subscription"}
                code += 500

        return BaseResponse(code=code, message=json.dumps(output))
开发者ID:csteward24,项目名称:the-blue-alliance,代码行数:83,代码来源:mobile_main.py


注:本文中的helpers.mytba_helper.MyTBAHelper.add_favorite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。