def step_4_pre(): if get_ini('main', 'DO_DB_CHECK') is None: store_ini('main', 'DO_DB_CHECK', 'Y') from core.utils import reboot reboot() report = [] from core.models import db, Template try: db.connect() except: raise db.close() report.append("Database connection successful.") from settings import DB DB.recreate_database() report.append("Database tables created successfully.") username = "******" email = get_ini("user", "email") password = get_ini("user", "password") blog_path = get_ini("install", "blog_path") from core.utils import encrypt_password p_key = get_ini('key', 'PASSWORD_KEY') password = encrypt_password(password, p_key) db.connect() with db.atomic(): from core.models import Site new_site = Site.create( name="Your first site", description="The description for your first site.", url=get_ini('main', 'base_url_root'), path=blog_path) report.append("Initial site created successfully.") from core.models import User new_user = User(name='Administrator', email=email, encrypted_password=password) new_user.save_pwd() from core.auth import role new_user_permissions = new_user.add_permission( permission=role.SYS_ADMIN, site=new_site) new_user_permissions.save() report.append("Initial admin user created successfully.") plugindir = _join((_s.APPLICATION_PATH, 'data', 'plugins')) import shutil # TODO: warn on doing this? # this should only happen with a totally fresh install, not an upgrade install_directory = _join((_s.APPLICATION_PATH, _s.INSTALL_SRC_PATH)) if (os.path.isdir(plugindir)): shutil.rmtree(plugindir) shutil.copytree(_join((install_directory, 'plugins')), plugindir) report.append("Default plugins copied successfully to data directory.") themedir = _join((_s.APPLICATION_PATH, 'data', 'themes')) if (os.path.isdir(themedir)): shutil.rmtree(themedir) shutil.copytree(_join((install_directory, 'themes')), themedir) report.append("Default themes copied successfully to data directory.") from core import plugins for x in os.listdir(plugindir): if (os.path.isdir(_join((plugindir, x))) is True and x != '__pycache__'): new_plugin = plugins.register_plugin(x, enable=True) report.append("New plugin '{}' installed successfully.".format( new_plugin.name)) from settings.defaults import DEFAULT_THEME from core.models import Theme new_theme = Theme.install_to_system(DEFAULT_THEME) report.append( "Default theme created and installed successfully to system.") from core.models import Blog new_blog = Blog(site=new_site, name="Your first blog", description="The description for your first blog.", url=new_site.url, path=new_site.path, local_path=new_site.path, theme=new_theme) # TODO: add blog-level permission for new user as well new_blog.setup(new_user, new_theme) # TODO: Add default post report.append("Initial blog created successfully with default theme.") db.close() output_file_name = _join( (_s.APPLICATION_PATH + _s.DATA_FILE_PATH, _s.INI_FILE_NAME)) config_parser = ConfigParser() sections = ('db', 'path', 'key') for s in sections: for name, value in parser.items(s): try: config_parser.add_section(s) except DuplicateSectionError: pass config_parser.set(s, name, value) # if request.environ['HTTP_HOST'] == _s.DEFAULT_LOCAL_ADDRESS + _s.DEFAULT_LOCAL_PORT: # config_parser.add_section('server') # config_parser.set('server', 'DESKTOP_MODE', 'True') try: with open(output_file_name, "w", encoding='utf-8') as output_file: config_parser.write(output_file) except BaseException as e: raise SetupError(str(e.__class__.__name__) + ": " + str(e)) try: os.remove(config_file_name) except OSError as e: from core.error import not_found if not_found(e) is False: raise e except Exception as e: raise e finished = ''' <p>Installation is complete. <a href="{}">Return to the main page to begin using the application.</a> <script> $.get('/reboot',function(data){{}}); </script> '''.format(_s.BASE_URL) return {'report': report, 'finished': finished}
def blog_create_save(site_id): user = auth.is_logged_in(request) site = Site.load(site_id) permission = auth.is_site_admin(user, site) errors = [] new_blog = Blog( site=site, name=request.forms.getunicode('blog_name'), description=request.forms.getunicode('blog_description'), url=request.forms.getunicode('blog_url'), path=request.forms.getunicode('blog_path'), set_timezone=request.forms.getunicode('blog_timezone'), # theme=get_default_theme(), theme=Theme.default_theme()) try: new_blog.validate() except Exception as e: errors.extend(e.args[0]) if len(errors) == 0: from core.libs.peewee import IntegrityError try: new_blog.setup(user, Theme.default_theme()) # new_blog.theme) except IntegrityError as e: from core.utils import field_error errors.append(field_error(e)) if len(errors) > 0: status = utils.Status( type='danger', no_sure=True, message= 'The blog could not be created due to the following problems:', message_list=errors) from core.libs import pytz tags = template_tags(site=site, user=user) tags.status = status tags.blog = new_blog themes = Theme.select() return template( 'ui/ui_blog_settings', section_title="Create new blog", # search_context=(search_context['sites'], None), menu=generate_menu('site_create_blog', site), nav_default='all', themes=themes, timezones=pytz.all_timezones, **tags.__dict__) else: tags = template_tags(user=user, site=site, blog=new_blog) status = utils.Status(type='success', message=''' Blog <b>{}</b> was successfully created. You can <a href="{}/blog/{}/newpage">start posting</a> immediately. '''.format(new_blog.for_display, BASE_URL, new_blog.id)) tags.status = status return report(tags, 'site_create_blog', site)
def step_4_pre(): if get_ini('main', 'DO_DB_CHECK') is None: store_ini('main', 'DO_DB_CHECK', 'Y') from core.utils import reboot reboot() report = [] from core.models import db, Template try: db.connect() except: raise db.close() report.append("Database connection successful.") from settings import DB DB.recreate_database() report.append("Database tables created successfully.") username = "******" email = get_ini("user", "email") password = get_ini("user", "password") blog_path = get_ini("install", "blog_path") from core.utils import encrypt_password p_key = get_ini('key', 'PASSWORD_KEY') password = encrypt_password(password, p_key) db.connect() with db.atomic(): from core.models import Site new_site = Site.create( name="Your first site", description="The description for your first site.", url=get_ini('main', 'base_url_root'), path=blog_path) report.append("Initial site created successfully.") from core.models import User new_user = User( name='Administrator', email=email, encrypted_password=password) new_user.save_pwd() from core.auth import role new_user_permissions = new_user.add_permission( permission=role.SYS_ADMIN, site=new_site ) new_user_permissions.save() report.append("Initial admin user created successfully.") plugindir = _join((_s.APPLICATION_PATH, 'data', 'plugins')) import shutil # TODO: warn on doing this? # this should only happen with a totally fresh install, not an upgrade install_directory = _join((_s.APPLICATION_PATH, _s.INSTALL_SRC_PATH)) if (os.path.isdir(plugindir)): shutil.rmtree(plugindir) shutil.copytree(_join((install_directory, 'plugins')), plugindir) report.append("Default plugins copied successfully to data directory.") themedir = _join((_s.APPLICATION_PATH, 'data', 'themes')) if (os.path.isdir(themedir)): shutil.rmtree(themedir) shutil.copytree(_join((install_directory, 'themes')), themedir) report.append("Default themes copied successfully to data directory.") from core import plugins for x in os.listdir(plugindir): if (os.path.isdir(_join((plugindir, x))) is True and x != '__pycache__'): new_plugin = plugins.register_plugin(x, enable=True) report.append("New plugin '{}' installed successfully.".format( new_plugin.name)) from settings.defaults import DEFAULT_THEME from core.models import Theme new_theme = Theme.install_to_system(DEFAULT_THEME) report.append("Default theme created and installed successfully to system.") from core.models import Blog new_blog = Blog( site=new_site, name="Your first blog", description="The description for your first blog.", url=new_site.url, path=new_site.path, local_path=new_site.path, theme=new_theme ) # TODO: add blog-level permission for new user as well new_blog.setup(new_user, new_theme) # TODO: Add default post report.append("Initial blog created successfully with default theme.") db.close() output_file_name = _join((_s.APPLICATION_PATH + _s.DATA_FILE_PATH, _s.INI_FILE_NAME)) config_parser = ConfigParser() sections = ('db', 'path', 'key') for s in sections: for name, value in parser.items(s): try: config_parser.add_section(s) except DuplicateSectionError: pass config_parser.set(s, name, value) # if request.environ['HTTP_HOST'] == _s.DEFAULT_LOCAL_ADDRESS + _s.DEFAULT_LOCAL_PORT: # config_parser.add_section('server') # config_parser.set('server', 'DESKTOP_MODE', 'True') try: with open(output_file_name, "w", encoding='utf-8') as output_file: config_parser.write(output_file) except BaseException as e: raise SetupError(str(e.__class__.__name__) + ": " + str(e)) try: os.remove(config_file_name) except OSError as e: from core.error import not_found if not_found(e) is False: raise e except Exception as e: raise e finished = ''' <p>Installation is complete. <a href="{}">Return to the main page to begin using the application.</a> <script> $.get('/reboot',function(data){{}}); </script> '''.format(_s.BASE_URL) return {'report':report, 'finished':finished}
def blog_create_save(site_id): user = auth.is_logged_in(request) site = Site.load(site_id) permission = auth.is_site_admin(user, site) errors = [] new_blog = Blog( site=site, name=request.forms.getunicode('blog_name'), description=request.forms.getunicode('blog_description'), url=request.forms.getunicode('blog_url'), path=request.forms.getunicode('blog_path'), set_timezone=request.forms.getunicode('blog_timezone'), # theme=get_default_theme(), theme=Theme.default_theme() ) try: new_blog.validate() except Exception as e: errors.extend(e.args[0]) if len(errors) == 0: from core.libs.peewee import IntegrityError try: new_blog.setup(user, Theme.default_theme()) # new_blog.theme) except IntegrityError as e: from core.utils import field_error errors.append(field_error(e)) if len(errors) > 0: status = utils.Status( type='danger', no_sure=True, message='The blog could not be created due to the following problems:', message_list=errors) from core.libs import pytz tags = template_tags(site=site, user=user) tags.status = status tags.blog = new_blog themes = Theme.select() return template('ui/ui_blog_settings', section_title="Create new blog", # search_context=(search_context['sites'], None), menu=generate_menu('site_create_blog', site), nav_default='all', themes=themes, timezones=pytz.all_timezones, ** tags.__dict__ ) else: tags = template_tags(user=user, site=site, blog=new_blog) status = utils.Status( type='success', message=''' Blog <b>{}</b> was successfully created. You can <a href="{}/blog/{}/newpage">start posting</a> immediately. '''.format( new_blog.for_display, BASE_URL, new_blog.id) ) tags.status = status return report(tags, 'site_create_blog', site)