def clean(hookloadtime, hookthirds): """清理系统""" if hookloadtime: s = get_storage() del s['hookloadtime'] if hookthirds: s = get_storage() del s['hookthirds']
def set_site_config(mapping): """设置站点信息""" if mapping and isinstance(mapping, dict): ALLOWED_TAGS = ['a', 'abbr', 'b', 'i', 'code', 'p', 'br', 'h3', 'h4'] ALLOWED_ATTRIBUTES = { 'a': ['href', 'title', 'target'], 'abbr': ['title'], '*': ['style'], } ALLOWED_STYLES = ['color'] upload_beforehtml = mapping.get("upload_beforehtml") or "" bulletin = mapping.get("bulletin") or "" if upload_beforehtml: mapping["upload_beforehtml"] = bleach_html(upload_beforehtml, ALLOWED_TAGS, ALLOWED_ATTRIBUTES, ALLOWED_STYLES) if bulletin: ALLOWED_TAGS.append("img") ALLOWED_ATTRIBUTES["img"] = [ 'title', 'alt', 'src', 'width', 'height' ] mapping["bulletin"] = bleach_html(bulletin, ALLOWED_TAGS, ALLOWED_ATTRIBUTES, ALLOWED_STYLES) s = get_storage() cfg = s.get("siteconfig") or {} cfg.update(mapping) s.set("siteconfig", cfg)
def set_site_config(mapping): """设置站点信息""" if mapping and isinstance(mapping, dict): ALLOWED_TAGS = ["a", "abbr", "b", "i", "code", "p", "br", "h3", "h4"] ALLOWED_ATTRIBUTES = { "a": ["href", "title", "target"], "abbr": ["title"], "*": ["style"], } ALLOWED_STYLES = ["color"] upload_beforehtml = mapping.get("upload_beforehtml") or "" bulletin = mapping.get("bulletin") or "" about = mapping.get("about") or "" if upload_beforehtml: mapping["upload_beforehtml"] = bleach_html(upload_beforehtml, ALLOWED_TAGS, ALLOWED_ATTRIBUTES, ALLOWED_STYLES) if bulletin: ALLOWED_TAGS.append("img") ALLOWED_ATTRIBUTES["img"] = [ "title", "alt", "src", "width", "height" ] mapping["bulletin"] = bleach_html(bulletin, ALLOWED_TAGS, ALLOWED_ATTRIBUTES, ALLOWED_STYLES) if about: mapping["about"] = bleach_html(about, ALLOWED_TAGS, ALLOWED_ATTRIBUTES, ALLOWED_STYLES) s = get_storage() cfg = s.get("siteconfig") or {} cfg.update(mapping) s.set("siteconfig", cfg)
def test_basestorage(self): class MyStorage(BaseStorage): pass ms = MyStorage() with self.assertRaises(AttributeError): ms.get('test') self.assertIsInstance(get_storage(), BaseStorage)
def get_site_config(): """获取站点配置""" s = get_storage() cfg = s.get("siteconfig") or {} #: Maybe to fix None if "upload_includes" not in cfg: cfg["upload_includes"] = "" return cfg
def clean(hookloadtime, hookthirds, invalidkey): """清理系统""" if hookloadtime: s = get_storage() del s["hookloadtime"] if hookthirds: s = get_storage() del s["hookthirds"] if invalidkey: rc = create_redis_engine() ius = rc.keys(rsp("index", "user", "*")) pipe = rc.pipeline() for uk in ius: us = rc.smembers(uk) for sha in us: if not rc.exists(rsp("image", sha)): pipe.srem(uk, sha) try: pipe.execute() except RedisError: pass
def get_site_config(): """获取站点配置""" s = get_storage() cfg = s.get("siteconfig") or {} return cfg
def set_site_config(mapping): if mapping and isinstance(mapping, dict): s = get_storage() cfg = s.get("siteconfig") or {} cfg.update(mapping) s.set("siteconfig", cfg)
def get_site_config(): s = get_storage() cfg = s.get("siteconfig") or {} return cfg
def delete_hookloadtime(): from libs.storage import get_storage s = get_storage() del s['hookloadtime']