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


Python Suggestion.render_key_name方法代码示例

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


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

示例1: createTeamMediaSuggestion

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_key_name [as 别名]
    def createTeamMediaSuggestion(cls, author_account_key, media_url, team_key, year_str):
        """Create a Team Media Suggestion. Returns status (success, exists, bad_url)"""

        media_dict = MediaParser.partial_media_dict_from_url(media_url)
        if media_dict is not None:
            existing_media = Media.get_by_id(Media.render_key_name(media_dict['media_type_enum'], media_dict['foreign_key']))
            if existing_media is None or team_key not in [reference.id() for reference in existing_media.references]:
                foreign_type = Media.SLUG_NAMES[media_dict['media_type_enum']]
                suggestion_id = Suggestion.render_key_name(year_str, 'team', team_key, foreign_type, media_dict['foreign_key'])
                suggestion = Suggestion.get_by_id(suggestion_id)
                if not suggestion or suggestion.review_state != Suggestion.REVIEW_PENDING:
                    media_dict['year'] = int(year_str)
                    media_dict['reference_type'] = 'team'
                    media_dict['reference_key'] = team_key

                    suggestion = Suggestion(
                        id=suggestion_id,
                        author=author_account_key,
                        target_model="media",
                        )
                    suggestion.contents = media_dict
                    suggestion.put()
                    return 'success'
                else:
                    return 'suggestion_exists'
            else:
                return 'media_exists'
        else:
            return 'bad_url'
开发者ID:csteward24,项目名称:the-blue-alliance,代码行数:31,代码来源:suggestion_creator.py

示例2: post

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

        match_key = self.request.get("match_key")
        match_future = Match.get_by_id_async(self.request.get("match_key"))
        youtube_url = self.request.get("youtube_url")

        youtube_id = None
        regex1 = re.match(r".*youtu\.be\/(.*)", youtube_url)
        if regex1 is not None:
            youtube_id = regex1.group(1)
        else:
            regex2 = re.match(r".*v=([a-zA-Z0-9_-]*)", youtube_url)
            if regex2 is not None:
                youtube_id = regex2.group(1)

        if youtube_id is not None:
            if youtube_id not in match_future.get_result().youtube_videos:
                year = match_key[:4]
                suggestion_id = Suggestion.render_key_name(year, 'match', match_key, 'youtube', youtube_id)
                suggestion = Suggestion.get_by_id(suggestion_id)
                if not suggestion or suggestion.review_state != Suggestion.REVIEW_PENDING:
                    suggestion = Suggestion(
                        id=suggestion_id,
                        author=self.user_bundle.account.key,
                        target_key=match_key,
                        target_model="match",
                        )
                    suggestion.contents = {"youtube_videos": [youtube_id]}
                    suggestion.put()
                    status = 'success'
                else:
                    status = 'suggestion_exists'
            else:
                status = 'video_exists'
        else:
            status = 'bad_url'

        self.redirect('/suggest/match/video?match_key={}&status={}'.format(match_key, status))
开发者ID:Nascar,项目名称:the-blue-alliance,代码行数:41,代码来源:suggest_match_video_controller.py


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