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


Python Sitevar.get_or_insert方法代码示例

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


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

示例1: post

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

        trusted_sitevar = Sitevar.get_or_insert('trustedapi')
        sitevar = Sitevar.get_or_insert('apistatus')
        old_value = sitevar.contents

        status = {}
        status['android'] = {}
        status['ios'] = {}
        status['max_season'] = int(self.request.get('max_year'))
        status['current_season'] = int(self.request.get('current_year'))
        status['android']['latest_app_version'] = int(self.request.get('android_latest_version'))
        status['android']['min_app_version'] = int(self.request.get('android_min_version'))
        status['ios']['latest_app_version'] = int(self.request.get('ios_latest_version'))
        status['ios']['min_app_version'] = int(self.request.get('ios_min_version'))
        sitevar.contents = status
        sitevar.put()

        trusted_status = {
            1: True if self.request.get('enable_match_video') else False,
            2: True if self.request.get('enable_event_teams') else False,
            3: True if self.request.get('enable_event_matches') else False,
            4: True if self.request.get('enable_event_rankings') else False,
            5: True if self.request.get('enable_event_alliances') else False,
            6: True if self.request.get('enable_event_awards') else False,
        }
        trusted_sitevar.contents = trusted_status
        trusted_sitevar.put()

        ApiStatusController.clear_cache_if_needed(old_value, status)

        self.redirect('/admin/apistatus')
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:35,代码来源:admin_apistatus_controller.py

示例2: post

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

        google_secrets = Sitevar.get_or_insert('google.secrets')
        firebase_secrets = Sitevar.get_or_insert('firebase.secrets')
        fmsapi_secrets = Sitevar.get_or_insert('fmsapi.secrets')
        mobile_clientIds = Sitevar.get_or_insert('mobile.clientIds')
        gcm_serverKey = Sitevar.get_or_insert('gcm.serverKey')

        google_key = self.request.get("google_secret")
        firebase_key = self.request.get("firebase_secret")
        fmsapi_user = self.request.get("fmsapi_user")
        fmsapi_secret = self.request.get("fmsapi_secret")
        web_client_id = self.request.get("web_client_id")
        android_client_id = self.request.get("android_client_id")
        ios_client_id = self.request.get("ios_client_id")
        gcm_key = self.request.get("gcm_key")

        google_secrets.contents = {'api_key': google_key}
        firebase_secrets.contents = {'FIREBASE_SECRET': firebase_key}
        fmsapi_secrets.contents = {'username': fmsapi_user, 'authkey': fmsapi_secret}
        mobile_clientIds.contents = {'web': web_client_id, 'android': android_client_id,
                                     'ios': ios_client_id}
        gcm_serverKey.contents = {'gcm_key': gcm_key}

        google_secrets.put()
        firebase_secrets.put()
        fmsapi_secrets.put()
        mobile_clientIds.put()
        gcm_serverKey.put()

        self.redirect('/admin/authkeys')
开发者ID:brycematsuda,项目名称:the-blue-alliance,代码行数:34,代码来源:admin_authkeys_controller.py

示例3: post

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
    def post(self):
        self._require_registration()

        event_key = self.request.get("event_key")

        status, suggestion = SuggestionCreator.createEventMediaSuggestion(
            author_account_key=self.user_bundle.account.key,
            media_url=self.request.get("media_url"),
            event_key=event_key)

        if status == 'success':
            # Send an update to the FUN slack
            slack_sitevar = Sitevar.get_or_insert('slack.hookurls')
            if slack_sitevar:
                slack_url = slack_sitevar.contents.get('fun', '')
                if slack_url:
                    message_body = u"{0} ({1}) has suggested a video for <https://www.thebluealliance.com/event/{2}|{2}>: https://youtu.be/{3}.\nSee all suggestions at https://www.thebluealliance.com/suggest/event/media/review".format(
                        self.user_bundle.account.display_name,
                        self.user_bundle.account.email,
                        event_key,
                        suggestion.contents['foreign_key']).encode('utf-8')

                    OutgoingNotificationHelper.send_slack_alert(slack_url, message_body, [])

        self.redirect('/suggest/event/media?event_key=%s&status=%s' % (event_key, status))
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:27,代码来源:suggest_event_media_controller.py

示例4: update_champ_numbers

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
    def update_champ_numbers(cls, match):
        champ_numbers_sitevar = Sitevar.get_or_insert(
            'champ_numbers',
            values_json=json.dumps({
                'kpa_accumulated': 0,
                'rotors_engaged': 0,
                'ready_for_takeoff': 0,
            }))

        old_contents = champ_numbers_sitevar.contents
        for color in ['red', 'blue']:
            old_contents['kpa_accumulated'] += match.score_breakdown[color]['autoFuelPoints'] + match.score_breakdown[color]['teleopFuelPoints']
            if match.score_breakdown[color]['rotor4Engaged']:
                old_contents['rotors_engaged'] += 4
            elif match.score_breakdown[color]['rotor3Engaged']:
                old_contents['rotors_engaged'] += 3
            elif match.score_breakdown[color]['rotor2Engaged']:
                old_contents['rotors_engaged'] += 2
            elif match.score_breakdown[color]['rotor1Engaged']:
                old_contents['rotors_engaged'] += 1
            old_contents['ready_for_takeoff'] += match.score_breakdown[color]['teleopTakeoffPoints'] / 50

        champ_numbers_sitevar.contents = old_contents
        champ_numbers_sitevar.put()

        deferred.defer(
            cls._patch_data,
            'champ_numbers',
            json.dumps(old_contents),
            _queue="firebase")
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:32,代码来源:firebase_pusher.py

示例5: _update_live_events_helper

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
    def _update_live_events_helper(cls):
        week_events = EventHelper.getWeekEvents()
        events_by_key = {}
        live_events = []
        for event in week_events:
            if event.now:
                event._webcast = event.current_webcasts  # Only show current webcasts
                for webcast in event.webcast:
                    WebcastOnlineHelper.add_online_status_async(webcast)
                events_by_key[event.key.id()] = event
            if event.within_a_day:
                live_events.append(event)

        # To get Champ events to show up before they are actually going on
        forced_live_events = Sitevar.get_or_insert(
            'forced_live_events',
            values_json=json.dumps([]))
        for event in ndb.get_multi([ndb.Key('Event', ekey) for ekey in forced_live_events.contents]):
            if event.webcast:
                for webcast in event.webcast:
                    WebcastOnlineHelper.add_online_status_async(webcast)
            events_by_key[event.key.id()] = event

        # # Add in the Fake TBA BlueZone event (watch for circular imports)
        # from helpers.bluezone_helper import BlueZoneHelper
        # bluezone_event = BlueZoneHelper.update_bluezone(live_events)
        # if bluezone_event:
        #     for webcast in bluezone_event.webcast:
        #         WebcastOnlineHelper.add_online_status_async(webcast)
        #     events_by_key[bluezone_event.key_name] = bluezone_event

        return events_by_key
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:34,代码来源:firebase_pusher.py

示例6: get

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
    def get(self):
        self._require_admin()
        google_secrets = Sitevar.get_or_insert('google.secrets')
        firebase_secrets = Sitevar.get_or_insert('firebase.secrets')
        fmsapi_secrets = Sitevar.get_or_insert('fmsapi.secrets')
        mobile_clientIds = Sitevar.get_or_insert('mobile.clientIds')
        gcm_serverKey = Sitevar.get_or_insert('gcm.serverKey')
        twitch_secrets = Sitevar.get_or_insert('twitch.secrets')
        livestream_secrets = Sitevar.get_or_insert('livestream.secrets')

        fmsapi_keys = fmsapi_secrets.contents if fmsapi_secrets and isinstance(fmsapi_secrets.contents, dict) else {}
        clientIds = mobile_clientIds.contents if mobile_clientIds and isinstance(mobile_clientIds.contents, dict) else {}
        self.template_values.update({
            'google_secret': google_secrets.contents.get('api_key', "") if google_secrets else "",
            'firebase_secret': firebase_secrets.contents.get('FIREBASE_SECRET', "") if firebase_secrets else "",
            'fmsapi_user': fmsapi_keys.get('username', ''),
            'fmsapi_secret': fmsapi_keys.get('authkey', ''),
            'web_client_id': clientIds.get('web', ''),
            'android_client_id': clientIds.get('android', ''),
            'ios_client_id': clientIds.get('ios', ''),
            'gcm_key': gcm_serverKey.contents.get("gcm_key", "") if gcm_serverKey else "",
            'twitch_secret': twitch_secrets.contents.get('client_id', "") if twitch_secrets else "",
            'livestream_secret': livestream_secrets.contents.get('api_key', "") if livestream_secrets else "",
        })

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

示例7: _add_twitch_status_async

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
 def _add_twitch_status_async(cls, webcast):
     twitch_secrets = Sitevar.get_or_insert('twitch.secrets')
     client_id = None
     if twitch_secrets and twitch_secrets.contents:
         client_id = twitch_secrets.contents.get('client_id')
     if client_id:
         try:
             url = 'https://api.twitch.tv/kraken/streams/{}?client_id={}'.format(webcast['channel'], client_id)
             rpc = urlfetch.create_rpc()
             result = yield urlfetch.make_fetch_call(rpc, url)
         except Exception, e:
             logging.error("URLFetch failed for: {}".format(url))
             raise ndb.Return(None)
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:15,代码来源:webcast_online_helper.py

示例8: _add_youtube_status_async

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
 def _add_youtube_status_async(cls, webcast):
     google_secrets = Sitevar.get_or_insert('google.secrets')
     api_key = None
     if google_secrets and google_secrets.contents:
         api_key = google_secrets.contents.get('api_key')
     if api_key:
         try:
             url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet&id={}&key={}'.format(webcast['channel'], api_key)
             rpc = urlfetch.create_rpc()
             result = yield urlfetch.make_fetch_call(rpc, url)
         except Exception, e:
             logging.error("URLFetch failed for: {}".format(url))
             raise ndb.Return(None)
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:15,代码来源:webcast_online_helper.py

示例9: get

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
    def get(self):
        self._require_admin()

        status_sitevar = Sitevar.get_or_insert('apistatus', values_json="{}")
        trusted_sitevar = Sitevar.get_or_insert('trustedapi', values_json='{"enabled": true}')

        status = status_sitevar.contents
        android_status = status.get('android', None)
        ios_status = status.get('ios', None)

        self.template_values.update({
            'max_year': status.get('max_season', 2016),
            'current_year': status.get('current_season', 2016),
            'android_latest_version': android_status.get('latest_app_version', -1) if android_status else -1,
            'android_min_version': android_status.get('min_app_version', -1) if android_status else -1,
            'ios_latest_version': ios_status.get('latest_app_version', -1) if ios_status else -1,
            'ios_min_version': ios_status.get('min_app_version', -1) if ios_status else -1,
            'enable_trustedapi': trusted_sitevar.contents,
        })

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

示例10: post

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

        user_id = self.user_bundle.account.key.id()
        action = self.request.get('enable')
        sitevar = Sitevar.get_or_insert('notifications.enable')
        if action == "true":
            sitevar.values_json = "true"
            logging.info("User {} enabled push notificatios".format(user_id))
        else:
            sitevar.values_json = "false"
            logging.info("User {} disabled push notification".format(user_id))
        sitevar.put()

        self.redirect('/admin/mobile')
开发者ID:brycematsuda,项目名称:the-blue-alliance,代码行数:17,代码来源:admin_mobile_controller.py

示例11: post

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
    def post(self):
        """
        Configures scheduling a registration day in advance
        This will enqueue the requested year's event details task every X minutes
        Also updates the "short cache" sitevar to reduce timeouts for that day
        :param date_string: YYYY-mm-dd formatted day on which we poll faster
        :param event_year: The year of events to fetch
        :param interval: How many minutes between fetches
        """
        self._require_admin()
        date_string = self.request.get("date_string")
        event_year = self.request.get("event_year")
        interval = self.request.get("interval")

        start = datetime.strptime(date_string, "%Y-%m-%d")
        event_year = int(event_year)
        interval = int(interval)

        # Enqueue the tasks
        now = datetime.now()
        for i in xrange(0, 24*60, interval):
            # 24*60 is number of minutes per day
            task_eta = start + timedelta(minutes=i)
            if task_eta < now:
                # Don't enqueue tasks in the past
                continue
            taskqueue.add(
                queue_name='datafeed',
                target='backend-tasks',
                url='/backend-tasks/get/event_list/{}'.format(event_year),
                eta=task_eta,
                method='GET'
            )

        # Set the cache timeout sitevar
        end_timestamp = (start + timedelta(days=1) - datetime(1970, 1, 1)).total_seconds()
        cache_key_regex = ".*{}.*".format(event_year)
        turbo_mode_json = {
            'regex':  cache_key_regex,
            'valid_until': int(end_timestamp),
            'cache_length': 61
        }
        turbo_sitevar = Sitevar.get_or_insert('turbo_mode', description="Temporarily shorten cache expiration")
        turbo_sitevar.contents = turbo_mode_json
        turbo_sitevar.put()

        self.response.out.write("Enqueued {} tasks to update {} events starting at {}".format((24*60/interval), event_year, start))
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:49,代码来源:admin_cron_controller.py

示例12: _add_livestream_status_async

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
 def _add_livestream_status_async(cls, webcast):
     livestream_secrets = Sitevar.get_or_insert('livestream.secrets')
     api_key = None
     if livestream_secrets and livestream_secrets.contents:
         api_key = livestream_secrets.contents.get('api_key')
     if api_key:
         try:
             url = 'https://livestreamapis.com/v2/accounts/{}/events/{}'.format(webcast['channel'], webcast['file'])
             base64string = base64.encodestring('{}:'.format(api_key)).replace('\n','')
             headers = {
                 'Authorization': 'Basic {}'.format(base64string)
             }
             rpc = urlfetch.create_rpc()
             result = yield urlfetch.make_fetch_call(rpc, url, headers=headers)
         except Exception, e:
             logging.error("URLFetch failed for: {}".format(url))
             raise ndb.Return(None)
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:19,代码来源:webcast_online_helper.py

示例13: post

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
    def post(self):
        self._require_admin()
        gd_sitevar = Sitevar.get_or_insert("gameday.special_webcasts")

        action = self.request.get("action")
        item = self.request.get("item")

        if action == "add" and item == "webcast":
            self.add_special_webcast(gd_sitevar)
        elif action == "delete" and item == "webcast":
            self.delete_special_webcast(gd_sitevar)
        elif action == "add" and item == "alias":
            self.add_alias(gd_sitevar)
        elif action == "delete" and item == "alias":
            self.delete_alias(gd_sitevar)

        self.redirect("/admin/gameday")
        return
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:20,代码来源:admin_gameday_controller.py

示例14: post

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
    def post(self, event_key):
        self._require_admin()
        event = Event.get_by_id(event_key)
        if not event:
            self.abort(404)

        reg_sitevar = Sitevar.get_or_insert("cmp_registration_hacks", values_json="{}")

        new_divisions_to_skip = reg_sitevar.contents.get("divisions_to_skip", [])
        if self.request.get("event_sync_disable"):
            if event_key not in new_divisions_to_skip:
                new_divisions_to_skip.append(event_key)
        else:
            new_divisions_to_skip = list(filter(lambda e: e != event_key, new_divisions_to_skip))

        new_start_day_to_last = reg_sitevar.contents.get("set_start_to_last_day", [])
        if self.request.get("set_start_day_to_last"):
            if event_key not in new_start_day_to_last:
                new_start_day_to_last.append(event_key)
        else:
            new_start_day_to_last= list(filter(lambda e: e != event_key, new_start_day_to_last))

        new_skip_eventteams = reg_sitevar.contents.get("skip_eventteams", [])
        if self.request.get("skip_eventteams"):
            if event_key not in new_skip_eventteams:
                new_skip_eventteams.append(event_key)
        else:
            new_skip_eventteams = list(filter(lambda e: e != event_key, new_skip_eventteams))

        new_name_overrides = reg_sitevar.contents.get("event_name_override", [])
        if self.request.get("event_name_override"):
            if not any(o["event"] == event_key for o in new_name_overrides):
                new_name_overrides.append({"event": event_key, "name": self.request.get("event_name_override")})
        else:
            new_name_overrides = list(filter(lambda o: o["event"] != event_key, new_name_overrides))

        reg_sitevar.contents = {
            "divisions_to_skip": new_divisions_to_skip,
            "set_start_to_last_day": new_start_day_to_last,
            "skip_eventteams": new_skip_eventteams,
            "event_name_override": new_name_overrides,
        }
        reg_sitevar.put()
        self.redirect("/admin/event/{}".format(event_key))
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:46,代码来源:admin_event_controller.py

示例15: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_or_insert [as 别名]
    def _render(self):
        data = json.loads(self.request.body)
        current_commit_sha = data.get('current_commit', '')
        commit_time = data.get('commit_time', '')
        deploy_time = data.get('deploy_time', '')
        travis_job = data.get('travis_job', '')

        web_info = {
            'current_commit': current_commit_sha,
            'commit_time': commit_time,
            'deploy_time': deploy_time,
            'travis_job': travis_job,
        }

        status_sitevar = Sitevar.get_or_insert('apistatus', values_json='{}')
        contents = status_sitevar.contents
        contents['web'] = web_info
        status_sitevar.contents = contents
        status_sitevar.put()
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:21,代码来源:api_admin_controller.py


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