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


Python PushHelper.notification_enums_from_string方法代码示例

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


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

示例1: add_subscription

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import notification_enums_from_string [as 别名]
    def add_subscription(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to add subscription")
        userId = PushHelper.user_email_to_id(current_user.email())
        modelKey = request.model_key

        sub = Subscription.query( Subscription.user_id == userId, Subscription.model_key == modelKey).get()
        if sub is None:
            # Subscription doesn't exist, add it
            Subscription( user_id = userId, model_key = modelKey, notification_types = PushHelper.notification_enums_from_string(request.notifications)).put()
            if request.device_key:
                # Send updates to user's other devices
                GCMMessageHelper.send_subscription_update(userId, request.device_key)
            return BaseResponse(code=200, message="Subscription added")
        else:
            if sub.notification_types == PushHelper.notification_enums_from_string(request.notifications):
                # Subscription already exists. Don't add it again
                return BaseResponse(code=304, message="Subscription already exists")
            else:
                # We're updating the settings
                sub.notification_types = PushHelper.notification_enums_from_string(request.notifications)
                sub.put()
                if request.device_key:
                    # Send updates to user's other devices
                    GCMMessageHelper.send_subscription_update(userId, request.device_key)
                return BaseResponse(code=200, message="Subscription updated")
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:29,代码来源:mobile_main.py

示例2: update_model_preferences

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import notification_enums_from_string [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.push_helper.PushHelper.notification_enums_from_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。