def get_main_css_dir(): """ Returns the main CSS directory This is where the cache directory/file will be placed """ return dirs.get_main_css_dir()
def handle(self, *args, **options): """ Cache Static Files """ possible_js_cache = os.path.join(generate_cache_dir(get_main_js_dir()), "mediabrute_usefile") if os.path.isfile(possible_js_cache): os.unlink(possible_js_cache) js_urls = handlers.minify_js() js_file = open(possible_js_cache, "w") for url in js_urls: js_file.writelines(js_urls) js_file.close() possible_css_cache = os.path.join(generate_cache_dir(get_main_css_dir()), "mediabrute_usefile") if os.path.isfile(possible_css_cache): os.unlink(possible_css_cache) css_urls = handlers.minify_css() css_file = open(possible_css_cache, "w") for url in css_urls: css_file.writelines(css_urls) css_file.close()
def handle(self, *args, **options): """ Cache Static Files """ possible_js_cache = os.path.join(generate_cache_dir(get_main_js_dir()), "mediabrute_usefile") if os.path.isfile(possible_js_cache): os.unlink(possible_js_cache) js_urls = handlers.minify_js() js_file = open(possible_js_cache, "w") for url in js_urls: js_file.writelines(js_urls) js_file.close() possible_css_cache = os.path.join( generate_cache_dir(get_main_css_dir()), "mediabrute_usefile") if os.path.isfile(possible_css_cache): os.unlink(possible_css_cache) css_urls = handlers.minify_css() css_file = open(possible_css_cache, "w") for url in css_urls: css_file.writelines(css_urls) css_file.close()
def clear_cache(): """ Clears out the cached media files """ js_dir = dirs.get_main_js_dir() css_dir = dirs.get_main_css_dir() heavy_lifting.unlink_cache(dirs.generate_cache_dir(js_dir), "js", unlink_all=True) heavy_lifting.unlink_cache(dirs.generate_cache_dir(css_dir), "css", unlink_all=True)
def test_css_dir(self): """ Main CSS directory default setting test should match either settings.CSS_DIR or just "css" Test that it works as a fullpath AND standalone """ fullpath = dirs.get_main_css_dir() ext_only = dirs.get_main_css_dir(full_path=False) try: ext_compare = settings.CSS_DIR except AttributeError: ext_compare = defaults.CSS_DIR fullpath_compare = os.path.join(dirs.get_root(), ext_compare) self.assertEquals(fullpath_compare, fullpath) self.assertEquals(ext_compare, ext_only)
def minify_css(app_name=None): """ {{ MINI_CSS }} Context processor """ css_dir = dirs.get_main_css_dir() cache_dir = dirs.generate_cache_dir(css_dir) # check for a possible 'lock' file possible_cache = os.path.join(cache_dir, "mediabrute_usefile") if os.path.isfile(possible_cache): txt = open(possible_cache) css_urls = txt.readlines() return [url for url in css_urls if url != ""] # continue to do an on-the-fly cache if no lock file was found css_dirs = [css_dir, dirs.APP_CSS_DIRS] cache_files = [compile_and_cache_css(css_dirs, cache_dir), ] if app_name and app_name in dirs.get_separated_apps("css"): cache_files.append(compile_and_cache_css([dirs.get_separated_css(app_name), ], cache_dir, app_name=app_name)) return ["%s/cache/%s" % (dirs.get_css_url(), cache_name) for cache_name in cache_files]