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


Python subscription.Subscription类代码示例

本文整理汇总了Python中models.subscription.Subscription的典型用法代码示例。如果您正苦于以下问题:Python Subscription类的具体用法?Python Subscription怎么用?Python Subscription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_subscription_search

def test_subscription_search():
    subscription = Subscription.search('google').first()
    assert subscription is not None
    assert subscription.name == 'Google Developers Blog'

    subscription = Subscription.search('youtube').first()
    assert subscription is not None
    assert subscription.name == 'YouTube'
开发者ID:johnliu,项目名称:journal-server,代码行数:8,代码来源:model_tests.py

示例2: test_user_subscriptions

def test_user_subscriptions():
    seed_user = User.get()
    subscription = Subscription.get()

    # Query checking if the subscription is in the user.
    count_query = (UserSubscription.select()
                   .where(UserSubscription.user == seed_user,
                          UserSubscription.subscription == subscription))

    # Unsubscribe first (regardless of subscription).
    seed_user.unsubscribe(subscription)
    assert count_query.count() == 0
    assert subscription.num_subscribers() == 0

    # Resubscribe.
    seed_user.subscribe(subscription)
    assert count_query.count() == 1
    assert subscription.num_subscribers() == 1

    # Resubscribe again.
    seed_user.subscribe(subscription)
    assert count_query.count() == 1
    assert subscription.num_subscribers() == 1

    # Unsubscribe again.
    seed_user.unsubscribe(subscription)
    assert count_query.count() == 0
    assert subscription.num_subscribers() == 0
开发者ID:johnliu,项目名称:journal-server,代码行数:28,代码来源:model_tests.py

示例3: get

    def get(self, event_key=None):
        self._require_login()
        self._require_registration()

        if event_key is None:
            events = EventHelper.getEventsWithinADay()
            EventHelper.sort_events(events)
            self.template_values['events'] = events
            self.response.out.write(jinja2_engine.render('mytba_add_hot_matches_base.html', self.template_values))
            return

        event = Event.get_by_id(event_key)
        if not event:
            self.abort(404)

        subscriptions_future = Subscription.query(
            Subscription.model_type==ModelType.MATCH,
            Subscription.notification_types==NotificationType.UPCOMING_MATCH,
            ancestor=self.user_bundle.account.key).fetch_async(projection=[Subscription.model_key])

        matches = []
        if event.matchstats and 'match_predictions' in event.matchstats:
            match_predictions = event.matchstats['match_predictions']
            max_hotness = 0
            min_hotness = float('inf')
            for match in event.matches:
                if not match.has_been_played and match.key.id() in match_predictions:
                    prediction = match_predictions[match.key.id()]
                    red_score = prediction['red']['score']
                    blue_score = prediction['blue']['score']
                    if red_score > blue_score:
                        winner_score = red_score
                        loser_score = blue_score
                    else:
                        winner_score = blue_score
                        loser_score = red_score

                    hotness = winner_score + 2.0*loser_score  # Favor close high scoring matches

                    max_hotness = max(max_hotness, hotness)
                    min_hotness = min(min_hotness, hotness)
                    match.hotness = hotness
                    matches.append(match)

        existing_subscriptions = set()
        for sub in subscriptions_future.get_result():
            existing_subscriptions.add(sub.model_key)

        hot_matches = []
        for match in matches:
            match.hotness = 100 * (match.hotness - min_hotness) / (max_hotness - min_hotness)
            match.already_subscribed = match.key.id() in existing_subscriptions
            hot_matches.append(match)
        hot_matches = sorted(hot_matches, key=lambda match: -match.hotness)
        matches_dict = {'qm': hot_matches[:25]}

        self.template_values['event'] = event
        self.template_values['matches'] = matches_dict

        self.response.out.write(jinja2_engine.render('mytba_add_hot_matches.html', self.template_values))
开发者ID:ehamwey,项目名称:the-blue-alliance,代码行数:60,代码来源:account_controller.py

示例4: add_subscription

    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,代码行数:27,代码来源:mobile_main.py

示例5: get_users_subscribed_to_event

 def get_users_subscribed_to_event(cls, event, notification):
     keys = []
     keys.append(event.key_name)
     keys.append("{}*".format(event.year))
     users = Subscription.query(Subscription.model_key.IN(keys), Subscription.notification_types == notification).fetch()
     output = []
     for user in users:
         output.append(user.user_id)
     return output
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:9,代码来源:push_helper.py

示例6: remove_subscription

 def remove_subscription(cls, userId, modelKey, device_key=""):
     to_delete = Subscription.query(Subscription.model_key == modelKey, ancestor=ndb.Key(Account, userId)).fetch(keys_only=True)
     if len(to_delete) > 0:
         ndb.delete_multi(to_delete)
         # Send updates to user's other devices
         NotificationHelper.send_subscription_update(userId, device_key)
         return 200
     else:
         # Subscription doesn't exist. Can't delete it
         return 404
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:10,代码来源:mytba_helper.py

示例7: get_users_subscribed_for_alliances

 def get_users_subscribed_for_alliances(cls, event, notification):
     keys = []
     for team in event.alliance_teams:
         keys.append(team)
         keys.append("{}_{}".format(event.key_name, team))  # [email protected] key
     keys.append("{}*".format(event.year))  # key for all events in year
     keys.append(event.key_name)
     users = Subscription.query(Subscription.model_key.IN(keys), Subscription.notification_types == notification).fetch()
     output = [user.user_id for user in users]
     return output
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:10,代码来源:push_helper.py

示例8: list_subscriptions

    def list_subscriptions(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return SubscriptionCollection(subscriptions = [])
        userId = PushHelper.user_email_to_id(current_user.email())

        subscriptions = Subscription.query( Subscription.user_id == userId ).fetch()
        output = []
        for subscription in subscriptions:
            output.append(SubscriptionMessage(model_key = subscription.model_key, notifications = PushHelper.notification_string_from_enums(subscription.notification_types)))
        return SubscriptionCollection(subscriptions = output)
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:11,代码来源:mobile_main.py

示例9: get_users_subscribed_to_match

 def get_users_subscribed_to_match(cls, match, notification):
     keys = []
     for team in match.team_key_names:
         keys.append(team)
         keys.append("{}_{}".format(match.event.id(), team))
     keys.append(match.key_name)
     keys.append(match.event.id())
     logging.info("Getting subscriptions for keys: "+str(keys))
     users = Subscription.query(Subscription.model_key.IN(keys), Subscription.notification_types == notification).fetch()
     output = []
     for user in users:
         output.append(user.user_id)
     return output
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:13,代码来源:push_helper.py

示例10: list_subscriptions

    def list_subscriptions(self, request):
        user_id = get_current_user_id(self.headers)
        if user_id is None:
            return SubscriptionCollection(subscriptions=[])

        subscriptions = Subscription.query(ancestor=ndb.Key(Account, user_id)).fetch()
        output = []
        for subscription in subscriptions:
            output.append(SubscriptionMessage(
                    model_key=subscription.model_key,
                    notifications=PushHelper.notification_string_from_enums(subscription.notification_types),
                    model_type=subscription.model_type))
        return SubscriptionCollection(subscriptions=output)
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:13,代码来源:clientapi_service.py

示例11: get_users_subscribed_to_match

    def get_users_subscribed_to_match(cls, match, notification):
        keys = []
        for team in match.team_key_names:
            keys.append(team)
            keys.append("{}_{}".format(match.event_key_name, team))

        keys.append("{}*".format(match.year))  # key for all events in year
        keys.append(match.key_name)
        keys.append(match.event_key_name)
        users = Subscription.query(Subscription.model_key.IN(keys), Subscription.notification_types == notification).fetch()
        output = []
        for user in users:
            output.append(user.user_id)
        return output
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:14,代码来源:push_helper.py

示例12: get

    def get(self):
        self._require_registration()

        push_sitevar = Sitevar.get_by_id('notifications.enable')
        if push_sitevar is None or not push_sitevar.values_json == "true":
            ping_enabled = "disabled"
        else:
            ping_enabled = ""

        # Compute myTBA statistics
        user = self.user_bundle.account.key
        num_favorites = Favorite.query(ancestor=user).count()
        num_subscriptions = Subscription.query(ancestor=user).count()

        # Compute suggestion statistics
        submissions_pending = Suggestion.query(Suggestion.review_state==Suggestion.REVIEW_PENDING, Suggestion.author==user).count()
        submissions_accepted = Suggestion.query(Suggestion.review_state==Suggestion.REVIEW_ACCEPTED, Suggestion.author==user).count()

        # Suggestion review statistics
        review_permissions = False
        num_reviewed = 0
        total_pending = 0
        if self.user_bundle.account.permissions:
            review_permissions = True
            num_reviewed = Suggestion.query(Suggestion.reviewer==user).count()
            total_pending = Suggestion.query(Suggestion.review_state==Suggestion.REVIEW_PENDING).count()

        # Fetch trusted API keys
        api_keys = ApiAuthAccess.query(ApiAuthAccess.owner == user).fetch()
        write_keys = filter(lambda key: key.is_write_key, api_keys)
        read_keys = filter(lambda key: key.is_read_key, api_keys)

        self.template_values['status'] = self.request.get('status')
        self.template_values['webhook_verification_success'] = self.request.get('webhook_verification_success')
        self.template_values['ping_sent'] = self.request.get('ping_sent')
        self.template_values['ping_enabled'] = ping_enabled
        self.template_values['num_favorites'] = num_favorites
        self.template_values['num_subscriptions'] = num_subscriptions
        self.template_values['submissions_pending'] = submissions_pending
        self.template_values['submissions_accepted'] = submissions_accepted
        self.template_values['review_permissions'] = review_permissions
        self.template_values['num_reviewed'] = num_reviewed
        self.template_values['total_pending'] = total_pending
        self.template_values['read_keys'] = read_keys
        self.template_values['write_keys'] = write_keys
        self.template_values['auth_write_type_names'] = AuthType.write_type_names

        self.response.out.write(jinja2_engine.render('account_overview.html', self.template_values))
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:48,代码来源:account_controller.py

示例13: get

    def get(self):
        self._require_registration()

        push_sitevar = Sitevar.get_by_id("notifications.enable")
        if push_sitevar is None or not push_sitevar.values_json == "true":
            ping_enabled = "disabled"
        else:
            ping_enabled = ""

        # Compute myTBA statistics
        user = self.user_bundle.account.key
        num_favorites = Favorite.query(ancestor=user).count()
        num_subscriptions = Subscription.query(ancestor=user).count()

        # Compute suggestion statistics
        submissions_pending = Suggestion.query(
            Suggestion.review_state == Suggestion.REVIEW_PENDING, Suggestion.author == user
        ).count()
        submissions_accepted = Suggestion.query(
            Suggestion.review_state == Suggestion.REVIEW_ACCEPTED, Suggestion.author == user
        ).count()

        # Suggestion review statistics
        review_permissions = False
        num_reviewed = 0
        total_pending = 0
        if self.user_bundle.account.permissions:
            review_permissions = True
            num_reviewed = Suggestion.query(Suggestion.reviewer == user).count()
            total_pending = Suggestion.query(Suggestion.review_state == Suggestion.REVIEW_PENDING).count()

        # Fetch trusted API keys
        trusted_keys = ApiAuthAccess.query(ApiAuthAccess.owner == user).fetch()

        self.template_values["status"] = self.request.get("status")
        self.template_values["webhook_verification_success"] = self.request.get("webhook_verification_success")
        self.template_values["ping_enabled"] = ping_enabled
        self.template_values["num_favorites"] = num_favorites
        self.template_values["num_subscriptions"] = num_subscriptions
        self.template_values["submissions_pending"] = submissions_pending
        self.template_values["submissions_accepted"] = submissions_accepted
        self.template_values["review_permissions"] = review_permissions
        self.template_values["num_reviewed"] = num_reviewed
        self.template_values["total_pending"] = total_pending
        self.template_values["trusted_keys"] = trusted_keys
        self.template_values["auth_type_names"] = AuthType.type_names

        self.response.out.write(jinja2_engine.render("account_overview.html", self.template_values))
开发者ID:the-blue-alliance,项目名称:the-blue-alliance,代码行数:48,代码来源:account_controller.py

示例14: remove_subscription

    def remove_subscription(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to remove subscription")
        userId = PushHelper.user_email_to_id(current_user.email())
        modelKey = request.model_key

        to_delete = Subscription.query( Subscription.user_id == userId, Subscription.model_key == modelKey).fetch(keys_only=True)
        if len(to_delete) > 0:
            ndb.delete_multi(to_delete)
            if request.device_key:
                # Send updates to user's other devices
                GCMMessageHelper.send_subscription_update(userId, request.device_key)
            return BaseResponse(code=200, message="Subscriptions deleted")
        else:
            # Subscription doesn't exist. Can't delete it
            return BaseResponse(code=404, message="Subscription not found")
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:17,代码来源:mobile_main.py

示例15: get

    def get(self):
        redirect = self.request.get('redirect')
        if redirect:
            self._require_login(redirect)
        else:
            self._require_login('/account')
        # Redirects to registration page if account not registered
        self._require_registration('/account/register')

        push_sitevar = Sitevar.get_by_id('notifications.enable')
        if push_sitevar is None or not push_sitevar.values_json == "true":
            ping_enabled = "disabled"
        else:
            ping_enabled = ""

        # Compute myTBA statistics
        user = self.user_bundle.account.key
        num_favorites = Favorite.query(ancestor=user).count()
        num_subscriptions = Subscription.query(ancestor=user).count()

        # Compute suggestion statistics
        submissions_pending = Suggestion.query(Suggestion.review_state==Suggestion.REVIEW_PENDING, Suggestion.author==user).count()
        submissions_accepted = Suggestion.query(Suggestion.review_state==Suggestion.REVIEW_ACCEPTED, Suggestion.author==user).count()

        # Suggestion review statistics
        review_permissions = False
        num_reviewed = 0
        total_pending = 0
        if AccountPermissions.MUTATE_DATA in self.user_bundle.account.permissions:
            review_permissions = True
            num_reviewed = Suggestion.query(Suggestion.reviewer==user).count()
            total_pending = Suggestion.query(Suggestion.review_state==Suggestion.REVIEW_PENDING).count()

        self.template_values['status'] = self.request.get('status')
        self.template_values['webhook_verification_success'] = self.request.get('webhook_verification_success')
        self.template_values['ping_enabled'] = ping_enabled
        self.template_values['num_favorites'] = num_favorites
        self.template_values['num_subscriptions'] = num_subscriptions
        self.template_values['submissions_pending'] = submissions_pending
        self.template_values['submissions_accepted'] = submissions_accepted
        self.template_values['review_permissions'] = review_permissions
        self.template_values['num_reviewed'] = num_reviewed
        self.template_values['total_pending'] = total_pending

        self.response.out.write(jinja2_engine.render('account_overview.html', self.template_values))
开发者ID:DNGros,项目名称:the-blue-alliance,代码行数:45,代码来源:account_controller.py


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