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


Python Setting.cached_library_content_date方法代码示例

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


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

示例1: library_content_html

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import cached_library_content_date [as 别名]
def library_content_html():
    # No cache found -- regenerate HTML
    smart_history = getSmartHistoryContent()

    all_playlists = []

    dict_videos = {}
    dict_videos_counted = {}
    dict_playlists = {}
    dict_playlists_by_title = {}
    dict_video_playlists = {}

    async_queries = [
        Video.all(),
        Playlist.all(),
        VideoPlaylist.all().filter('live_association = ', True).order('video_position'),
    ]

    results = util.async_queries(async_queries)

    for video in results[0].get_result():
        dict_videos[video.key()] = video

    for playlist in results[1].get_result():
        dict_playlists[playlist.key()] = playlist
        if playlist.title in topics_list:
            dict_playlists_by_title[playlist.title] = playlist

    for video_playlist in results[2].get_result():
        playlist_key = VideoPlaylist.playlist.get_value_for_datastore(video_playlist)
        video_key = VideoPlaylist.video.get_value_for_datastore(video_playlist)

        if dict_videos.has_key(video_key) and dict_playlists.has_key(playlist_key):
            video = dict_videos[video_key]
            playlist = dict_playlists[playlist_key]
            fast_video_playlist_dict = {"video":video, "playlist":playlist}

            if dict_video_playlists.has_key(playlist_key):
                dict_video_playlists[playlist_key].append(fast_video_playlist_dict)
            else:
                dict_video_playlists[playlist_key] = [fast_video_playlist_dict]

            if dict_playlists_by_title.has_key(playlist.title):
                # Only count videos in topics_list
                dict_videos_counted[video.youtube_id] = True

    # Update count of all distinct videos associated w/ a live playlist
    Setting.count_videos(len(dict_videos_counted.keys()))

    for topic in topics_list:
        if topic in dict_playlists_by_title:
            playlist = dict_playlists_by_title[topic]
            playlist_key = playlist.key()
            playlist_videos = dict_video_playlists.get(playlist_key) or []

            if not playlist_videos:
                logging.error('Playlist %s has no videos!', playlist.title)

            playlist_data = {
                     'title': topic,
                     'topic': topic,
                     'playlist': playlist,
                     'videos': playlist_videos,
                     'next': None
                     }

            all_playlists.append(playlist_data)

    playlist_data_prev = None
    for playlist_data in all_playlists:
        if playlist_data_prev:
            playlist_data_prev['next'] = playlist_data
        playlist_data_prev = playlist_data

    # Separating out the columns because the formatting is a little different on each column
    template_values = {
        'App' : App,
        'all_playlists': all_playlists,
        'smart_history': smart_history,
        }

    html = shared_jinja.get().render_template("library_content_template.html", **template_values)

    # Set shared date of last generated content
    Setting.cached_library_content_date(str(datetime.datetime.now()))

    return html
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:89,代码来源:library.py

示例2: getSmartHistoryContent

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import cached_library_content_date [as 别名]
@layer_cache.cache(layer=layer_cache.Layers.Memcache | layer_cache.Layers.Datastore, expiration=86400)
def getSmartHistoryContent():
    request = urllib2.Request("http://smarthistory.org/khan-home.html")
    try:
        response = urllib2.urlopen(request)
        smart_history = response.read()
        smart_history = re.search(re.compile("<body>(.*)</body>", re.S), smart_history).group(1).decode("utf-8")
        smart_history.replace("script", "")
    except Exception, e:
        logging.exception("Failed fetching smarthistory playlist")
        smart_history = None
        pass
    return smart_history

@layer_cache.cache_with_key_fxn(
        lambda *args, **kwargs: "library_content_html_%s" % Setting.cached_library_content_date()
        )
def library_content_html():
    # No cache found -- regenerate HTML
    smart_history = getSmartHistoryContent()

    all_playlists = []

    dict_videos = {}
    dict_videos_counted = {}
    dict_playlists = {}
    dict_playlists_by_title = {}
    dict_video_playlists = {}

    async_queries = [
        Video.all(),
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:33,代码来源:library.py

示例3: get_playlists

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import cached_library_content_date [as 别名]
        user_data = UserData.get_for_current_user()
        logout_url = users.create_logout_url(self.request.uri)
        template_values = qa.add_template_values({'App': App,
                                                  'points': user_data.points,
                                                  'username': user and user.nickname() or "",
                                                  'login_url': util.create_login_url(self.request.uri),
                                                  'student_email' : self.request.get('student_email'),
                                                  'logout_url': logout_url}, 
                                                  self.request)

        path = os.path.join(os.path.dirname(__file__), 'import.html')
        self.response.out.write(template.render(path, template_values)) 
        

        
@layer_cache.cache_with_key("playlists_%s" % Setting.cached_library_content_date())
def get_playlists():
    playlists = []   
    for playlist_title in all_topics_list:            
        query = Playlist.all()
        query.filter('title =', playlist_title)
        playlist = query.get()
        playlist_dict = {'youtube_id':  playlist.youtube_id,
                         'youtube_url': playlist.url,
                         'title': playlist.title, 
                         'description': playlist.description,
                         'api_url': "http://www.khanacademy.org/api/playlistvideos?playlist=%s" % (urllib.quote_plus(playlist_title)),
                        } 
        playlists.append(playlist_dict) 
    return json.dumps(playlists, indent=4)
                
开发者ID:adamwulf,项目名称:old-khan,代码行数:32,代码来源:api.py

示例4: video_library_last_updated

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import cached_library_content_date [as 别名]
def video_library_last_updated():
    return Setting.cached_library_content_date()
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:4,代码来源:v0.py

示例5: get_playlist_videos_json

# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import cached_library_content_date [as 别名]
    return get_playlist_videos_json(playlist_title)

@route("/api/videolibrary", methods=["GET"])
@jsonp
@jsonify
def video_library():
    return zlib.decompress(get_video_library_json_compressed())

@route("/api/videolibrarylastupdated", methods=["GET"])
@jsonp
@jsonify
def video_library_last_updated():
    return Setting.cached_library_content_date()

@layer_cache.cache_with_key_fxn(
        lambda: "json_playlists_%s" % Setting.cached_library_content_date(), 
        layer=layer_cache.Layers.Memcache)
def get_playlists_json():
    return json.dumps(get_playlist_api_dicts(), indent=4)

@layer_cache.cache_with_key_fxn(
        lambda playlist_title: "json_playlistvideos_%s_%s" % (playlist_title, Setting.cached_library_content_date()), 
        layer=layer_cache.Layers.Memcache)
def get_playlist_videos_json(playlist_title):
    query = Playlist.all()
    query.filter('title =', playlist_title)
    playlist = query.get()

    video_query = Video.all()
    video_query.filter('playlists = ', playlist_title)
    video_key_dict = Video.get_dict(video_query, lambda video: video.key())
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:33,代码来源:v0.py


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