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


Python Suggestion.render_media_key_name方法代码示例

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


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

示例1: createEventMediaSuggestion

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
    def createEventMediaSuggestion(cls, author_account_key, media_url, event_key, private_details_json=None):
        """Create an Event Media Suggestion. Returns status (success, suggestion_exists, media_exists, bad_url)"""

        media_dict = MediaParser.partial_media_dict_from_url(media_url)
        if media_dict is not None:
            if media_dict['media_type_enum'] != MediaType.YOUTUBE_VIDEO:
                return 'bad_url', 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 event_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_media_key_name(event_key[:4], 'event', event_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'] = event_key[:4]
                    media_dict['reference_type'] = 'event'
                    media_dict['reference_key'] = event_key
                    target_model = 'event_media'
                    if private_details_json is not None:
                        media_dict['private_details_json'] = private_details_json

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

示例2: createMatchVideoYouTubeSuggestion

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
 def createMatchVideoYouTubeSuggestion(cls, author_account_key, youtube_id, match_key):
     """Create a YouTube Match Video. Returns status (success, suggestion_exists, video_exists, bad_url)"""
     if youtube_id:
         match = Match.get_by_id(match_key)
         if not match:
             return 'bad_match'
         if youtube_id not in match.youtube_videos:
             year = match_key[:4]
             suggestion_id = Suggestion.render_media_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=author_account_key,
                     target_key=match_key,
                     target_model="match",
                     )
                 suggestion.contents = {"youtube_videos": [youtube_id]}
                 suggestion.put()
                 return 'success'
             else:
                 return 'suggestion_exists'
         else:
             return 'video_exists'
     else:
         return 'bad_url'
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:28,代码来源:suggestion_creator.py

示例3: createTeamMediaSuggestion

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

        media_dict = MediaParser.partial_media_dict_from_url(media_url.strip())
        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_media_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
                    if private_details_json is not None:
                        media_dict['private_details_json'] = private_details_json

                    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:FRC-Team-5522,项目名称:the-blue-alliance,代码行数:33,代码来源:suggestion_creator.py

示例4: createDesignSuggestion

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
 def createDesignSuggestion(self):
     status = SuggestionCreator.createTeamMediaSuggestion(
         self.account.key,
         'https://grabcad.com/library/2016-148-robowranglers-1', 'frc1124',
         '2016')
     self.assertEqual(status[0], 'success')
     return Suggestion.render_media_key_name(
         '2016', 'team', 'frc1124', 'grabcad', '2016-148-robowranglers-1')
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:10,代码来源:test_suggest_team_admin_review.py

示例5: test_duplicate_suggestion

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
    def test_duplicate_suggestion(self):
        suggestion_id = Suggestion.render_media_key_name('2016', 'event', '2016nyny', 'youtube', 'H-54KMwMKY0')
        Suggestion(
            id=suggestion_id,
            author=self.account.key,
            review_state=Suggestion.REVIEW_PENDING,
            target_key="2016nyny",
            target_model="event_media").put()

        status, _ = SuggestionCreator.createEventMediaSuggestion(
            self.account.key,
            "https://www.youtube.com/watch?v=H-54KMwMKY0",
            "2016nyny")
        self.assertEqual(status, 'suggestion_exists')
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:16,代码来源:test_suggestion_creator.py

示例6: testDuplicateSuggestion

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
    def testDuplicateSuggestion(self):
        suggestion_id = Suggestion.render_media_key_name('2016', 'team', 'frc1124', 'imgur', 'ruRAxDm')
        Suggestion(
            id=suggestion_id,
            author=self.account.key,
            review_state=Suggestion.REVIEW_PENDING,
            target_key="2012cmp",
            target_model="event").put()

        status = SuggestionCreator.createTeamMediaSuggestion(
            self.account.key,
            "http://imgur.com/ruRAxDm",
            "frc1124",
            "2016")
        self.assertEqual(status, 'suggestion_exists')
开发者ID:brycematsuda,项目名称:the-blue-alliance,代码行数:17,代码来源:test_suggestion_creator.py

示例7: testCleanUrl

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
    def testCleanUrl(self):
        status = SuggestionCreator.createTeamMediaSuggestion(
            self.account.key,
            " http://imgur.com/ruRAxDm?foo=bar#meow ",
            "frc1124",
            "2016")
        self.assertEqual(status, 'success')

        # Ensure the Suggestion gets created
        suggestion_id = Suggestion.render_media_key_name('2016', 'team', 'frc1124', 'imgur', 'ruRAxDm')
        suggestion = Suggestion.get_by_id(suggestion_id)
        self.assertIsNotNone(suggestion)
        self.assertEqual(suggestion.review_state, Suggestion.REVIEW_PENDING)
        self.assertEqual(suggestion.author, self.account.key)
        self.assertEqual(suggestion.target_model, 'media')
开发者ID:brycematsuda,项目名称:the-blue-alliance,代码行数:17,代码来源:test_suggestion_creator.py

示例8: test_create_suggestion_banned

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
    def test_create_suggestion_banned(self):
        status, _ = SuggestionCreator.createEventMediaSuggestion(
            self.account_banned.key,
            "https://www.youtube.com/watch?v=H-54KMwMKY0",
            "2016nyny")
        self.assertEqual(status, 'success')

        # Ensure the Suggestion gets created
        suggestion_id = Suggestion.render_media_key_name('2016', 'event', '2016nyny', 'youtube', 'H-54KMwMKY0')
        suggestion = Suggestion.get_by_id(suggestion_id)
        expected_dict = MediaParser.partial_media_dict_from_url("https://www.youtube.com/watch?v=H-54KMwMKY0")
        self.assertIsNotNone(suggestion)
        self.assertEqual(suggestion.review_state, Suggestion.REVIEW_AUTOREJECTED)
        self.assertEqual(suggestion.author, self.account_banned.key)
        self.assertEqual(suggestion.target_model, 'event_media')
        self.assertDictContainsSubset(expected_dict, suggestion.contents)
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:18,代码来源:test_suggestion_creator.py

示例9: createTeamMediaSuggestion

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
    def createTeamMediaSuggestion(cls, author_account_key, media_url, team_key, year_str, private_details_json=None, is_social=False, default_preferred=False):
        """Create a Team Media Suggestion. Returns status (success, suggestion_exists, media_exists, bad_url)"""

        media_dict = MediaParser.partial_media_dict_from_url(media_url)
        if media_dict is not None:
            if media_dict.get("is_social", False) != is_social:
                return 'bad_url', 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_media_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) if year_str else None
                    media_dict['reference_type'] = 'team'
                    media_dict['reference_key'] = team_key
                    media_dict['default_preferred'] = default_preferred
                    if private_details_json is not None:
                        media_dict['private_details_json'] = private_details_json

                    target_model = "media"
                    if media_dict.get("is_social", False):
                        target_model = "social-media"

                    if media_dict.get('media_type', '') in MediaType.robot_types:
                        target_model = "robot"

                    if Event.validate_key_name(team_key):
                        target_model = 'event_media'
                        media_dict['reference_type'] = 'event'

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

示例10: testCreateSuggestionWithUrlParams

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
    def testCreateSuggestionWithUrlParams(self):
        status = SuggestionCreator.createTeamMediaSuggestion(
            self.account.key,
            "https://www.youtube.com/watch?v=VP992UKFbko",
            "frc1124",
            "2016")
        self.assertEqual(status, 'success')

        # Ensure the Suggestion gets created
        suggestion_id = Suggestion.render_media_key_name('2016', 'team', 'frc1124', 'youtube', 'VP992UKFbko')
        suggestion = Suggestion.get_by_id(suggestion_id)
        expected_dict = MediaParser.partial_media_dict_from_url("https://www.youtube.com/watch?v=VP992UKFbko")
        self.assertIsNotNone(suggestion)
        self.assertEqual(suggestion.review_state, Suggestion.REVIEW_PENDING)
        self.assertEqual(suggestion.author, self.account.key)
        self.assertEqual(suggestion.target_model, 'media')
        self.assertDictContainsSubset(expected_dict, suggestion.contents)
开发者ID:brycematsuda,项目名称:the-blue-alliance,代码行数:19,代码来源:test_suggestion_creator.py

示例11: testCreateSuggestion

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
    def testCreateSuggestion(self):
        status = SuggestionCreator.createTeamMediaSuggestion(
            self.account.key,
            "http://imgur.com/ruRAxDm",
            "frc1124",
            "2016")
        self.assertEqual(status, 'success')

        # Ensure the Suggestion gets created
        suggestion_id = Suggestion.render_media_key_name('2016', 'team', 'frc1124', 'imgur', 'ruRAxDm')
        suggestion = Suggestion.get_by_id(suggestion_id)
        expected_dict = MediaParser.partial_media_dict_from_url("http://imgur.com/ruRAxDm")
        self.assertIsNotNone(suggestion)
        self.assertEqual(suggestion.review_state, Suggestion.REVIEW_PENDING)
        self.assertEqual(suggestion.author, self.account.key)
        self.assertEqual(suggestion.target_model, 'media')
        self.assertDictContainsSubset(expected_dict, suggestion.contents)
开发者ID:brycematsuda,项目名称:the-blue-alliance,代码行数:19,代码来源:test_suggestion_creator.py

示例12: createTeamMediaSuggestion

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

        # Sanitize input url
        media_url = media_url.strip()
        parsed = urlparse(media_url)
        media_url = "{}://{}{}".format(parsed.scheme, parsed.netloc, parsed.path)

        media_dict = MediaParser.partial_media_dict_from_url(media_url)
        if media_dict is not None:
            if media_dict.get("is_social", False) != is_social:
                return 'bad_url'

            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_media_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) if year_str else None
                    media_dict['reference_type'] = 'team'
                    media_dict['reference_key'] = team_key
                    if private_details_json is not None:
                        media_dict['private_details_json'] = private_details_json

                    target_model = "media"
                    if media_dict.get("is_social", False):
                        target_model = "social-media"

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

示例13: post

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_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_media_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:DNGros,项目名称:the-blue-alliance,代码行数:41,代码来源:suggest_match_video_controller.py

示例14: createSuggestion

# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import render_media_key_name [as 别名]
 def createSuggestion(self):
     status = SuggestionCreator.createMatchVideoYouTubeSuggestion(self.account.key,
                                                                  "H-54KMwMKY0",
                                                                  "2016necmp_f1m1")
     self.assertEqual(status, 'success')
     return Suggestion.render_media_key_name(2016, 'match', '2016necmp_f1m1', 'youtube', 'H-54KMwMKY0')
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:8,代码来源:test_suggest_match_video_review_controller.py


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