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


Python MyTBAHelper.add_subscription方法代码示例

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


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

示例1: post

# 需要导入模块: from helpers.mytba_helper import MyTBAHelper [as 别名]
# 或者: from helpers.mytba_helper.MyTBAHelper import add_subscription [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_subscription [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: update_model_preferences

# 需要导入模块: from helpers.mytba_helper import MyTBAHelper [as 别名]
# 或者: from helpers.mytba_helper.MyTBAHelper import add_subscription [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

示例4: post

# 需要导入模块: from helpers.mytba_helper import MyTBAHelper [as 别名]
# 或者: from helpers.mytba_helper.MyTBAHelper import add_subscription [as 别名]
    def post(self):
        self._require_login('/account/register')
        self._require_registration('/account/register')

        current_user_id = self.user_bundle.account.key.id()
        target_account_id = self.request.get('account_id')
        if current_user_id == target_account_id:
            action = self.request.get('action')
    #         if action == "favorite_add":
    #             model = self.request.get('model_key')
    #             if not ValidationHelper.is_valid_model_key(model):
    #                 self.redirect('/account/mytba?error=invalid_model')
    #                 return
    #             favorite = Favorite(parent = ndb.Key(Account, current_user_id), model_key =  model, user_id = current_user_id)
    #            MyTBAHelper.add_favorite(favorite)
    #            self.redirect('/account/mytba')
    #            return
            if action == "favorite_delete":
                model_key = self.request.get('model_key')
                result = MyTBAHelper.remove_favorite(current_user_id, model_key)
                if result == 404:
                    self.redirect('/account/mytba?error=fav_not_found')
                    return
                self.redirect('/account/mytba')
                return
    #         elif action == "subscription_add":
    #             model = self.request.get('model_key')
    #             if not ValidationHelper.is_valid_model_key(model):
    #                 self.redirect('/account/mytba?error=invalid_model')
    #                 return
    #             subs = self.request.get_all('notification_types')
    #             if not subs:
    #                 # No notification types specified. Don't add
    #                 self.redirect('/account/mytba?error=no_sub_types')
    #                 return
    #             subscription = Subscription(parent = ndb.Key(Account, current_user_id), user_id = current_user_id, model_key = model, notification_types = [int(s) for s in subs])
    #             MyTBAHelper.add_subscription(subscription)
    #             self.redirect('/account/mytba')
    #             return
            elif action == "subscription_year_add":
                now = datetime.datetime.now()
                year = self.request.get('year')
                if not "{}".format(now.year) == year:
                    # Can only subscribe to the current year's firehose
                    self.redirect('/account/mytba?error=invalid_year')
                    return
                key = "{}*".format(year)
                subs = self.request.get_all('notification_types')
                if not subs:
                    # No notification types specified. Don't add
                    self.redirect('/account/mytba?error=no_sub_types')
                    return
                subscription = Subscription(parent = ndb.Key(Account, current_user_id), user_id = current_user_id, model_key = key, model_type = ModelType.EVENT, notification_types = [int(s) for s in subs])

                logging.info("{}".format(self.request.get('webhooks_only')))
                MyTBAHelper.add_subscription(subscription)
                self.redirect('/account/mytba')
                return
            elif action == "subscription_delete":
                model_key = self.request.get('model_key')
                result = MyTBAHelper.remove_subscription(current_user_id, model_key)
                if result == 404:
                    self.redirect('/account/mytba?error=sub_not_found')
                    return
                self.redirect('/account/mytba')
                return
        self.redirect('/account/mytba?error=invalid_account')
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:69,代码来源:account_controller.py


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