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


Python Suggestion.get_by_id_async方法代码示例

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


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

示例1: post

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id_async [as 别名]
    def post(self):
        self._require_admin()

        accept_keys = map(int, self.request.POST.getall("accept_keys[]"))
        reject_keys = map(int, self.request.POST.getall("reject_keys[]"))

        accepted_suggestion_futures = [Suggestion.get_by_id_async(key) for key in accept_keys]
        rejected_suggestion_futures = [Suggestion.get_by_id_async(key) for key in reject_keys]
        accepted_suggestions = map(lambda a: a.get_result(), accepted_suggestion_futures)
        rejected_suggestions = map(lambda a: a.get_result(), rejected_suggestion_futures)

        MatchSuggestionAccepter.accept_suggestions(accepted_suggestions)

        all_suggestions = accepted_suggestions
        all_suggestions.extend(rejected_suggestions)

        for suggestion in all_suggestions:
            if suggestion.key.id() in accept_keys:
                suggestion.review_state = Suggestion.REVIEW_ACCEPTED
            if suggestion.key.id() in reject_keys:
                suggestion.review_state = Suggestion.REVIEW_REJECTED
            suggestion.reviewer = self.user_bundle.account.key
            suggestion.reviewer_at = datetime.datetime.now()

        ndb.put_multi(all_suggestions)

        self.redirect("/admin/suggestions/match/video/review")
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:29,代码来源:admin_match_video_suggestions_review_controller.py

示例2: _process_accepted

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id_async [as 别名]
    def _process_accepted(self, accept_key):
        """
        Performs all actions for an accepted Suggestion in a Transaction.
        Suggestions are processed one at a time (instead of in batch) in a
        Transaction to prevent possible race conditions.

        Actions include:
        - Creating and saving a new Media for the Suggestion
        - Removing a reference from another Media's preferred_references
        - Marking the Suggestion as accepted and saving it
        """
        # Async get
        suggestion_future = Suggestion.get_by_id_async(accept_key)

        # Resolve async Futures
        suggestion = suggestion_future.get_result()

        # Make sure Suggestion hasn't been processed (by another thread)
        if suggestion.review_state != Suggestion.REVIEW_PENDING:
            return

        team_reference = Media.create_reference(
            suggestion.contents['reference_type'],
            suggestion.contents['reference_key'])

        media = MediaCreator.create_media(suggestion, team_reference)

        # Mark Suggestion as accepted
        suggestion.review_state = Suggestion.REVIEW_ACCEPTED
        suggestion.reviewer = self.user_bundle.account.key
        suggestion.reviewed_at = datetime.datetime.now()

        # Do all DB writes
        MediaManipulator.createOrUpdate(media)
        suggestion.put()
开发者ID:CarterFendley,项目名称:the-blue-alliance,代码行数:37,代码来源:suggest_social_media_review_controller.py

示例3: post

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id_async [as 别名]
    def post(self):
        preferred_keys = self.request.POST.getall("preferred_keys[]")

        accept_keys = []
        reject_keys = []
        for value in self.request.POST.values():
            logging.debug(value)
            split_value = value.split('::')
            if len(split_value) == 2:
                key = split_value[1]
            else:
                continue
            if value.startswith('accept'):
                accept_keys.append(key)
            elif value.startswith('reject'):
                reject_keys.append(key)

        # Process accepts
        for accept_key in accept_keys:
            self._process_accepted(accept_key, preferred_keys)

        # Process rejects
        rejected_suggestion_futures = [Suggestion.get_by_id_async(key) for key in reject_keys]
        rejected_suggestions = map(lambda a: a.get_result(), rejected_suggestion_futures)
        for suggestion in rejected_suggestions:
            if suggestion.review_state == Suggestion.REVIEW_PENDING:
                suggestion.review_state = Suggestion.REVIEW_REJECTED
                suggestion.reviewer = self.user_bundle.account.key
                suggestion.reviewed_at = datetime.datetime.now()

        ndb.put_multi(rejected_suggestions)

        self.redirect("/suggest/team/media/review")
开发者ID:DNGros,项目名称:the-blue-alliance,代码行数:35,代码来源:suggest_team_media_review_controller.py

示例4: _process_accepted

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id_async [as 别名]
    def _process_accepted(self, accept_key, preferred_keys):
        """
        Performs all actions for an accepted Suggestion in a Transaction.
        Suggestions are processed one at a time (instead of in batch) in a
        Transaction to prevent possible race conditions.

        Actions include:
        - Creating and saving a new Media for the Suggestion
        - Removing a reference from another Media's preferred_references
        - Marking the Suggestion as accepted and saving it
        """
        # Async get
        suggestion_future = Suggestion.get_by_id_async(accept_key)

        # Setup
        to_replace_id = self.request.POST.get('replace-preferred-{}'.format(accept_key), None)

        # Resolve async Futures
        suggestion = suggestion_future.get_result()

        # Make sure Suggestion hasn't been processed (by another thread)
        if suggestion.review_state != Suggestion.REVIEW_PENDING:
            return

        # Remove preferred reference from another Media if specified
        team_reference = Media.create_reference(
            suggestion.contents['reference_type'],
            suggestion.contents['reference_key'])
        if to_replace_id:
            to_replace = Media.get_by_id(to_replace_id)
            if team_reference not in to_replace.preferred_references:
                return  # Preferred reference must have been edited earlier. Skip this Suggestion for now.
            to_replace.preferred_references.remove(team_reference)

        # Add preferred reference to current Media (images only) if explicitly listed in preferred_keys or if to_replace_id exists
        media_type_enum = suggestion.contents['media_type_enum']
        preferred_references = []
        if media_type_enum in MediaType.image_types and ('preferred::{}'.format(suggestion.key.id()) in preferred_keys or to_replace_id):
            preferred_references = [team_reference]

        media = MediaCreator.create_media(suggestion, team_reference, preferred_references)

        # Mark Suggestion as accepted
        suggestion.review_state = Suggestion.REVIEW_ACCEPTED
        suggestion.reviewer = self.user_bundle.account.key
        suggestion.reviewed_at = datetime.datetime.now()

        # Do all DB writes
        if to_replace_id:
            MediaManipulator.createOrUpdate(to_replace, auto_union=False)
        MediaManipulator.createOrUpdate(media)
        suggestion.put()
开发者ID:CarterFendley,项目名称:the-blue-alliance,代码行数:54,代码来源:suggest_team_media_review_controller.py

示例5: _process_rejected

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id_async [as 别名]
    def _process_rejected(self, reject_keys):
        """
        Do everything we need to reject a batch of suggestions
        We can batch these, because we're just rejecting everything
        """
        if not isinstance(reject_keys, list):
            reject_keys = [reject_keys]

        rejected_suggestion_futures = [Suggestion.get_by_id_async(key) for key in reject_keys]
        rejected_suggestions = map(lambda a: a.get_result(), rejected_suggestion_futures)

        for suggestion in rejected_suggestions:
            self._reject_suggestion(suggestion)
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:15,代码来源:suggestions_review_base_controller.py

示例6: post

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id_async [as 别名]
    def post(self):
        self._require_admin()

        accept_keys = map(int, self.request.POST.getall("accept_keys[]"))
        reject_keys = map(int, self.request.POST.getall("reject_keys[]"))

        accepted_suggestion_futures = [Suggestion.get_by_id_async(key) for key in accept_keys]
        rejected_suggestion_futures = [Suggestion.get_by_id_async(key) for key in reject_keys]
        accepted_suggestions = map(lambda a: a.get_result(), accepted_suggestion_futures)
        rejected_suggestions = map(lambda a: a.get_result(), rejected_suggestion_futures)

        for suggestion in accepted_suggestions:
            media = Media(
                id=Media.render_key_name(suggestion.contents['media_type_enum'], suggestion.contents['foreign_key']),
                foreign_key=suggestion.contents['foreign_key'],
                media_type_enum=suggestion.contents['media_type_enum'],
                details_json=suggestion.contents.get('details_json', None),
                year=int(suggestion.contents['year']),
                references=[Media.create_reference(
                    suggestion.contents['reference_type'],
                    suggestion.contents['reference_key'])],
            )
            MediaManipulator.createOrUpdate(media)

        all_suggestions = accepted_suggestions
        all_suggestions.extend(rejected_suggestions)

        for suggestion in all_suggestions:
            if suggestion.key.id() in accept_keys:
                suggestion.review_state = Suggestion.REVIEW_ACCEPTED
            if suggestion.key.id() in reject_keys:
                suggestion.review_state = Suggestion.REVIEW_REJECTED
            suggestion.reviewer = self.user_bundle.account.key
            suggestion.reviewer_at = datetime.datetime.now()

        ndb.put_multi(all_suggestions)

        self.redirect("/admin/suggestions/media/review")
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:40,代码来源:admin_media_suggestions_review_controller.py

示例7: _process_accepted

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id_async [as 别名]
    def _process_accepted(self, accept_key):
        """
        Performs all actions for an accepted Suggestion in a Transaction.
        Suggestions are processed one at a time (instead of in batch) in a
        Transaction to prevent possible race conditions.

        Actions include:
        - Creating and saving a new Media for the Suggestion
        - Removing a reference from another Media's preferred_references
        - Marking the Suggestion as accepted and saving it
        """
        # Async get
        suggestion_future = Suggestion.get_by_id_async(accept_key)

        # Setup
        to_replace_id = self.request.POST.get('replace-preferred-{}'.format(accept_key), None)

        # Resolve async Futures
        suggestion = suggestion_future.get_result()

        # Make sure Suggestion hasn't been processed (by another thread)
        if suggestion.review_state != Suggestion.REVIEW_PENDING:
            return

        team_reference = Media.create_reference(
            suggestion.contents['reference_type'],
            suggestion.contents['reference_key'])
        media_type_enum = suggestion.contents['media_type_enum']

        media = Media(
            id=Media.render_key_name(suggestion.contents['media_type_enum'], suggestion.contents['foreign_key']),
            foreign_key=suggestion.contents['foreign_key'],
            media_type_enum=media_type_enum,
            details_json=suggestion.contents.get('details_json', None),
            private_details_json=suggestion.contents.get('private_details_json', None),
            year=int(suggestion.contents['year']) if not suggestion.contents.get('is_social', False) else None,
            references=[team_reference],
        )

        # Mark Suggestion as accepted
        suggestion.review_state = Suggestion.REVIEW_ACCEPTED
        suggestion.reviewer = self.user_bundle.account.key
        suggestion.reviewed_at = datetime.datetime.now()

        # Do all DB writes
        MediaManipulator.createOrUpdate(media)
        suggestion.put()
开发者ID:ehamwey,项目名称:the-blue-alliance,代码行数:49,代码来源:suggest_social_media_review_controller.py

示例8: post

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id_async [as 别名]
    def post(self):
        accept_keys = self.request.POST.getall("accept_keys[]")
        reject_keys = self.request.POST.getall("reject_keys[]")
        preferred_keys = self.request.POST.getall("preferred_keys[]")

        # Process accepts
        for accept_key in accept_keys:
            self._process_accepted(accept_key, preferred_keys)

        # Process rejects
        rejected_suggestion_futures = [Suggestion.get_by_id_async(key) for key in reject_keys]
        rejected_suggestions = map(lambda a: a.get_result(), rejected_suggestion_futures)
        for suggestion in rejected_suggestions:
            if suggestion.review_state == Suggestion.REVIEW_PENDING:
                suggestion.review_state = Suggestion.REVIEW_REJECTED
                suggestion.reviewer = self.user_bundle.account.key
                suggestion.reviewed_at = datetime.datetime.now()

        ndb.put_multi(rejected_suggestions)

        self.redirect("/suggest/team/media/review")
开发者ID:zamadatix,项目名称:the-blue-alliance,代码行数:23,代码来源:suggest_team_media_review_controller.py


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