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


Python Media.query方法代码示例

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


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

示例1: get

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def get(self):
        team_key = self.request.get("team_key")
        year_str = self.request.get("year")

        self._require_registration()

        if not team_key or not year_str:
            self.redirect("/", abort=True)

        year = int(year_str)
        team_future = Team.get_by_id_async(self.request.get("team_key"))
        team = team_future.get_result()
        if not team:
            self.redirect("/", abort=True)

        media_key_futures = Media.query(Media.references == team.key, Media.year == year).fetch_async(500, keys_only=True)
        social_media_future = media_query.TeamSocialMediaQuery(team.key.id()).fetch_async()

        media_futures = ndb.get_multi_async(media_key_futures.get_result())
        medias = [media_future.get_result() for media_future in media_futures]
        medias_by_slugname = MediaHelper.group_by_slugname(medias)

        social_medias = sorted(social_media_future.get_result(), key=MediaHelper.social_media_sorter)
        social_medias = filter(lambda m: m.media_type_enum == MediaType.INSTAGRAM_PROFILE, social_medias)  # we only allow IG media, so only show IG profile

        self.template_values.update({
            "medias_by_slugname": medias_by_slugname,
            "social_medias": social_medias,
            "status": self.request.get("status"),
            "team": team,
            "year": year,
        })

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

示例2: get

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def get(self):
        team_keys_future = Team.query().order(Team.team_number).fetch_async(keys_only=True)
        social_media_keys_future = Media.query(Media.year == None).fetch_async(keys_only=True)

        team_futures = ndb.get_multi_async(team_keys_future.get_result())
        social_futures = ndb.get_multi_async(social_media_keys_future.get_result())

        socials_by_team = defaultdict(dict)
        for social_future in social_futures:
            social = social_future.get_result()
            for reference in social.references:
                socials_by_team[reference.id()][social.media_type_enum] = social

        if team_futures:
            with cloudstorage.open(self.TEAMS_FILENAME_PATTERN, 'w') as teams_file:
                writer = csv.writer(teams_file, delimiter=',')
                for team_future in team_futures:
                    team = team_future.get_result()
                    team_row = [team.key.id(), team.nickname, team.name, team.city, team.state_prov, team.country, team.website, team.rookie_year]
                    for social_type in MediaType.social_types:
                        social = socials_by_team[team.key.id()].get(social_type, None)
                        team_row.append(social.social_profile_url if social is not None else None)
                    self._writerow_unicode(writer, team_row)

        self.response.out.write("Done backing up teams!")
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:27,代码来源:backup_controller.py

示例3: _query_async

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
 def _query_async(self):
     team_key = ndb.Key(Team, self._query_args[0])
     media_tag_enum = self._query_args[1]
     medias = yield Media.query(
         Media.references == team_key,
         Media.media_tag_enum == media_tag_enum).fetch_async()
     raise ndb.Return(medias)
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:9,代码来源:media_query.py

示例4: get

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def get(self, team_number):
        self._require_admin()

        team = Team.get_by_id("frc" + team_number)
        if not team:
            self.abort(404)
        event_teams = EventTeam.query(EventTeam.team == team.key).fetch(500)
        team_medias = Media.query(Media.references == team.key).fetch(500)
        robots = Robot.query(Robot.team == team.key).fetch()
        district_teams = DistrictTeam.query(DistrictTeam.team == team.key).fetch()
        years_participated = sorted(TeamParticipationQuery(team.key_name).fetch())

        team_medias_by_year = {}
        for media in team_medias:
            if media.year in team_medias_by_year:
                team_medias_by_year[media.year].append(media)
            else:
                team_medias_by_year[media.year] = [media]
        media_years = sorted(team_medias_by_year.keys(), reverse=True)

        self.template_values.update({
            'event_teams': event_teams,
            'team': team,
            'team_media_years': media_years,
            'team_medias_by_year': team_medias_by_year,
            'robots': robots,
            'district_teams': district_teams,
            'years_participated': years_participated,
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/team_details.html')
        self.response.out.write(template.render(path, self.template_values))
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:34,代码来源:admin_team_controller.py

示例5: _render

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
 def _render(self, *args, **kw):
     avatars_future = Media.query(Media.media_type_enum == MediaType.AVATAR).fetch_async()
     avatars = sorted(avatars_future.get_result(), key=lambda a: int(a.references[0].id()[3:]))
     self.template_values.update({
         'avatars': avatars,
     })
     return jinja2_engine.render('avatars2018.html', self.template_values)
开发者ID:legoktm,项目名称:the-blue-alliance,代码行数:9,代码来源:main_controller.py

示例6: _query_async

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
 def _query_async(self):
     team_key = self._query_args[0]
     year = self._query_args[1]
     medias = yield Media.query(
         Media.references == ndb.Key(Team, team_key),
         Media.year == year).fetch_async()
     raise ndb.Return(medias)
开发者ID:cmlicata,项目名称:the-blue-alliance,代码行数:9,代码来源:media_query.py

示例7: _render

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def _render(self, team_key, year=None):
        self._set_team(team_key)

        media_keys = Media.query(Media.references == self.team.key, Media.year == self.year).fetch(500, keys_only=True)
        medias = ndb.get_multi(media_keys)
        media_list = [ModelToDict.mediaConverter(media) for media in medias]
        return json.dumps(media_list, ensure_ascii=True)
开发者ID:Captain-Dude,项目名称:the-blue-alliance,代码行数:9,代码来源:api_team_controller.py

示例8: get

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def get(self):
        team_key = self.request.get("team_key")
        year_str = self.request.get("year")

        self._require_login("/suggest/team/media?team_key=%s&year=%s" % (team_key, year_str))

        if not team_key or not year_str:
            self.redirect("/", abort=True)

        year = int(year_str)
        team_future = Team.get_by_id_async(self.request.get("team_key"))
        team = team_future.get_result()
        media_key_futures = Media.query(Media.references == team.key, Media.year == year).fetch_async(500, keys_only=True)
        media_futures = ndb.get_multi_async(media_key_futures.get_result())
        medias_by_slugname = MediaHelper.group_by_slugname([media_future.get_result() for media_future in media_futures])

        self.template_values.update({
            "success": self.request.get("success"),
            "team": team,
            "year": year,
            "medias_by_slugname": medias_by_slugname
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/suggest_team_media.html')
        self.response.out.write(template.render(path, self.template_values))
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:27,代码来源:suggest_team_media_controller.py

示例9: get

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def get(self, team_number):
        self._require_admin()

        team = Team.get_by_id("frc" + team_number)
        event_teams = EventTeam.query(EventTeam.team == team.key).fetch(500)
        team_medias = Media.query(Media.references == team.key).fetch(500)
        robots = Robot.query(Robot.team == team.key).fetch()
        district_teams = DistrictTeam.query(DistrictTeam.team == team.key).fetch()

        team_medias_by_year = {}
        for media in team_medias:
            if media.year in team_medias_by_year:
                team_medias_by_year[media.year].append(media)
            else:
                team_medias_by_year[media.year] = [media]

        self.template_values.update({
            'event_teams': event_teams,
            'team': team,
            'team_medias_by_year': team_medias_by_year,
            'robots': robots,
            'district_teams': district_teams,
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/team_details.html')
        self.response.out.write(template.render(path, self.template_values))
开发者ID:CarterFendley,项目名称:the-blue-alliance,代码行数:28,代码来源:admin_team_controller.py

示例10: _render

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def _render(self, year):
        year = int(year)
        avatars = []
        shards = memcache.get_multi(['{}avatars_{}'.format(year, i) for i in xrange(10)])
        if len(shards) == 10:  # If missing a shard, must refetch all
            for _, shard in sorted(shards.items(), key=lambda kv: kv[0]):
                avatars += shard

        if not avatars:
            avatars_future = Media.query(Media.media_type_enum == MediaType.AVATAR, Media.year == year).fetch_async()
            avatars = sorted(avatars_future.get_result(), key=lambda a: int(a.references[0].id()[3:]))

            shards = {}
            size = len(avatars) / 10 + 1
            for i in xrange(10):
                start = i * size
                end = start + size
                shards['{}avatars_{}'.format(year, i)] = avatars[start:end]
            memcache.set_multi(shards, 60*60*24)

        self.template_values.update({
            'year': year,
            'avatars': avatars,
        })
        return jinja2_engine.render('avatars.html', self.template_values)
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:27,代码来源:main_controller.py

示例11: get

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def get(self, event_key):
        self._require_admin()

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

        reg_sitevar = Sitevar.get_by_id("cmp_registration_hacks")
        api_keys = ApiAuthAccess.query(ApiAuthAccess.event_list == ndb.Key(Event, event_key)).fetch()
        event_medias = Media.query(Media.references == event.key).fetch(500)

        self.template_values.update({
            "event": event,
            "medias": event_medias,
            "cache_key": event_controller.EventDetail('2016nyny').cache_key.format(event.key_name),
            "flushed": self.request.get("flushed"),
            "playoff_types": PlayoffType.type_names,
            "write_auths": api_keys,
            "event_sync_disable": reg_sitevar and event_key in reg_sitevar.contents.get('divisions_to_skip', []),
            "set_start_day_to_last": reg_sitevar and event_key in reg_sitevar.contents.get('set_start_to_last_day', []),
            "skip_eventteams": reg_sitevar and event_key in reg_sitevar.contents.get('skip_eventteams', []),
            "event_name_override": next(iter(filter(lambda e: e.get("event") == event_key, reg_sitevar.contents.get("event_name_override", []))), {}).get("name", "")
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/event_details.html')
        self.response.out.write(template.render(path, self.template_values))
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:29,代码来源:admin_event_controller.py

示例12: get

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def get(self):
        self._require_admin()
        media_count = Media.query().count()

        self.template_values.update({
            "media_count": media_count
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/media_dashboard.html')
        self.response.out.write(template.render(path, self.template_values))
开发者ID:CarterFendley,项目名称:the-blue-alliance,代码行数:12,代码来源:admin_media_controller.py

示例13: _query_async

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
 def _query_async(self):
     event_key = self._query_args[0]
     year = int(event_key[:4])
     event_team_keys = yield EventTeam.query(EventTeam.event == ndb.Key(Event, event_key)).fetch_async(keys_only=True)
     if not event_team_keys:
         raise ndb.Return([])
     team_keys = map(lambda event_team_key: ndb.Key(Team, event_team_key.id().split('_')[1]), event_team_keys)
     medias = yield Media.query(
         Media.preferred_references.IN(team_keys),
         Media.year == year).fetch_async()
     raise ndb.Return(medias)
开发者ID:CarterFendley,项目名称:the-blue-alliance,代码行数:13,代码来源:media_query.py

示例14: get

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def get(self):
        suggestions = (
            Suggestion.query()
            .filter(Suggestion.review_state == Suggestion.REVIEW_PENDING)
            .filter(Suggestion.target_model == "media")
            .fetch(limit=50)
        )

        # Quick and dirty way to group images together
        suggestions = sorted(
            suggestions, key=lambda x: 0 if x.contents["media_type_enum"] in MediaType.image_types else 1
        )

        reference_keys = []
        existing_preferred_keys_futures = []
        for suggestion in suggestions:
            reference_key = suggestion.contents["reference_key"]
            reference = Media.create_reference(suggestion.contents["reference_type"], reference_key)
            reference_keys.append(reference)

            if "details_json" in suggestion.contents:
                suggestion.details = json.loads(suggestion.contents["details_json"])
                if "image_partial" in suggestion.details:
                    suggestion.details["thumbnail"] = suggestion.details["image_partial"].replace("_l", "_m")

            # Find existing preferred images
            existing_preferred_keys_futures.append(
                Media.query(
                    Media.media_type_enum.IN(MediaType.image_types),
                    Media.references == reference,
                    Media.preferred_references == reference,
                    Media.year == suggestion.contents["year"],
                ).fetch_async(keys_only=True)
            )

        reference_futures = ndb.get_multi_async(reference_keys)
        existing_preferred_futures = map(lambda x: ndb.get_multi_async(x.get_result()), existing_preferred_keys_futures)

        references = map(lambda r: r.get_result(), reference_futures)
        existing_preferred = map(lambda l: map(lambda x: x.get_result(), l), existing_preferred_futures)

        suggestions_and_references_and_preferred = zip(suggestions, references, existing_preferred)

        self.template_values.update(
            {
                "suggestions_and_references_and_preferred": suggestions_and_references_and_preferred,
                "max_preferred": Media.MAX_PREFERRED,
            }
        )

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

示例15: test_reject_suggestion

# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import query [as 别名]
    def test_reject_suggestion(self):
        self.loginUser()
        self.givePermission()
        suggestion_id = self.createSuggestion()
        form = self.getSuggestionForm()
        form['accept_reject-{}'.format(suggestion_id)] = 'reject::{}'.format(suggestion_id)
        response = form.submit().follow()
        self.assertEqual(response.status_int, 200)

        suggestion = Suggestion.get_by_id(suggestion_id)
        self.assertIsNotNone(suggestion)
        self.assertEqual(suggestion.review_state, Suggestion.REVIEW_REJECTED)

        medias = Media.query().fetch()
        self.assertEqual(len(medias), 0)
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:17,代码来源:test_suggest_event_media_review_controller.py


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