def _create_v2_iconbar_config(Config): config, config_cache = _get_config(Config, 'top_ico') config.name = '%s.v1.old' % config.name config.save() v2_config = {'left': {'logo': {}, 'blog_name': {}}, 'right': []} v2_config['left']['logo'] = v1_img_to_v2(config_cache['left']['logo']) blog_name = config_cache['left']['blog_name'] if not isinstance(blog_name, dict): blog_name = {} v2_config['left']['blog_name'] = blog_name v2_config['left']['blog_name']['_attrs'] = v1_attrs_to_v2( blog_name.get('attrs', {})) v2_config['right'] = config_cache['right'] try: v2_config['left']['blog_name'].pop('attrs') except: pass for i, img in enumerate(v2_config['right']): v2_config['right'][i]['img'] = v1_img_to_v2( config_cache['right'][i]['img']) Config.objects.create(name=app_config_context['v2_iconbar_config'], v2_schema=V2_Config_Schema['v2_iconbar_config'], v2_config=v2_config, v2_real_config=get_real_config(v2_config))
def _create_v2_navbar_config(Config): config, config_cache = _get_config(Config, 'top_menu') config.name = '%s.v1.old' % config.name config.save() v2_config = {'menu': []} for old in config_cache: v2_config['menu'].append(v1_menu_to_v2(old)) Config.objects.create(name=app_config_context['v2_navbar_config'], v2_schema=V2_Config_Schema['v2_navbar_config'], v2_config=v2_config, v2_script=V2_Config_JS['v2_navbar_config'], v2_real_config=get_real_config(v2_config))
def _create_v2_blog_config(Config): config, config_cache = _get_config(Config, 'global_value') config.name = '%s.v1.old' % config.name config.save() v2_config = config_cache config, config_cache = _get_config(Config, 'common_config', suffix='.v1.old') config.name = '%s.v1.old' % config.name config.save() v2_config.update(config_cache) v2_config['host'] = '' v2_config['email'] = {'is_open': False} Config.objects.create(name=app_config_context['v2_blog_config'], v2_schema=V2_Config_Schema['v2_blog_config'], v2_config=v2_config, v2_real_config=get_real_config(v2_config))
def init_config(Config): Config.objects.bulk_create([ # 通用配置 Config(name=v2_app_config_context['v2_common_config'], v2_schema=V2_Config_Schema['v2_common_config'], v2_config={ "_handler": "v2_kv_handler", "data": [] }), # 顶部图标栏 Config(name=v2_app_config_context['v2_iconbar_config'], v2_schema=V2_Config_Schema['v2_iconbar_config'], v2_config={ "left": { "logo": { "_handler": "v2_img_handler", "type": "name", "value": "logo_white", "_attrs": "" }, "blog_name": { "text": " 文字标题 ", "_attrs": "style=font-size:18px" } }, "right": [{ "img": { "_handler": "v2_img_handler", "type": "fa", "value": "fab fa-github", "_attrs": "style=color:#ffffff;font-size:24px" }, "url": "https://github.com/gojuukaze/DeerU" }] }), # 顶部导航栏 Config(name=v2_app_config_context['v2_navbar_config'], v2_schema=V2_Config_Schema['v2_navbar_config'], v2_script=V2_Config_JS['v2_navbar_config'], v2_config={ "menu": [{ "name": "首页", "url": { "_handler": "v2_url_handler", "type": "url", "value": "/" }, "img": { "_handler": "v2_img_handler", "type": "fa", "value": "fas fa-home ", "_attrs": "" }, "children": [] }, { "name": "折叠菜单", "url": { "_handler": "v2_url_handler", "type": "url", "value": "" }, "img": { "_handler": "v2_img_handler", "type": "fa", "value": "fas fa-list ", "_attrs": "" }, "children": [{ "name": "默认分类", "url": { "_handler": "v2_url_handler", "type": "cat", "value": "默认分类" }, "img": { " ": "" } }, { "line": "line" }, { "name": "DeerU", "url": { "_handler": "v2_url_handler", "type": "tag", "value": "DeerU" }, "img": { " ": "" } }] }] }), # 博客配置 Config(name=v2_app_config_context['v2_blog_config'], v2_schema=V2_Config_Schema['v2_blog_config'], v2_config={ "host": "http://127.0.0.1:8000", "title": "Deeru - 开源博客系统", "blog_name": "Deeru - 开源博客系统", "nickname": "gojuukaze", "theme": "base_theme", "baidu_auto_push_show": "是", "baidu_auto_push": 1, "email": { "is_open": False } }), ]) for config in Config.objects.all(): config.v2_real_config = get_real_config(config.v2_config) config.save()
def config_pre_save(sender, **kwargs): if not kwargs['instance'].name.endswith('.old'): kwargs['instance'].v2_real_config = get_real_config( kwargs['instance'].v2_config)