mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-13 10:30:16 +00:00
Turn modules into proper Django applications
This commit is contained in:
parent
cc549fff61
commit
fc2fdc4d27
@ -96,9 +96,6 @@ def setup_server():
|
|||||||
'tools.staticdir.dir': '.'}}
|
'tools.staticdir.dir': '.'}}
|
||||||
cherrypy.tree.mount(None, django.conf.settings.STATIC_URL, config)
|
cherrypy.tree.mount(None, django.conf.settings.STATIC_URL, config)
|
||||||
|
|
||||||
# TODO: our modules are mimicking django apps. It'd be better to convert
|
|
||||||
# our modules to Django apps instead of reinventing the wheel.
|
|
||||||
# (we'll still have to serve the static files with cherrypy though)
|
|
||||||
for module_name in module_loader.loaded_modules:
|
for module_name in module_loader.loaded_modules:
|
||||||
module = importlib.import_module(module_name)
|
module = importlib.import_module(module_name)
|
||||||
module_path = os.path.dirname(module.__file__)
|
module_path = os.path.dirname(module.__file__)
|
||||||
@ -163,7 +160,12 @@ def configure_django():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template_directories = module_loader.get_template_directories()
|
applications = ['bootstrapform',
|
||||||
|
'django.contrib.auth',
|
||||||
|
'django.contrib.contenttypes',
|
||||||
|
'django.contrib.messages',
|
||||||
|
'plinth']
|
||||||
|
applications += module_loader.get_modules_to_load()
|
||||||
sessions_directory = os.path.join(cfg.data_dir, 'sessions')
|
sessions_directory = os.path.join(cfg.data_dir, 'sessions')
|
||||||
django.conf.settings.configure(
|
django.conf.settings.configure(
|
||||||
ALLOWED_HOSTS=['127.0.0.1', 'localhost'],
|
ALLOWED_HOSTS=['127.0.0.1', 'localhost'],
|
||||||
@ -173,11 +175,7 @@ def configure_django():
|
|||||||
{'ENGINE': 'django.db.backends.sqlite3',
|
{'ENGINE': 'django.db.backends.sqlite3',
|
||||||
'NAME': cfg.store_file}},
|
'NAME': cfg.store_file}},
|
||||||
DEBUG=cfg.debug,
|
DEBUG=cfg.debug,
|
||||||
INSTALLED_APPS=['bootstrapform',
|
INSTALLED_APPS=applications,
|
||||||
'django.contrib.auth',
|
|
||||||
'django.contrib.contenttypes',
|
|
||||||
'django.contrib.messages',
|
|
||||||
'plinth'],
|
|
||||||
LOGGING=logging_configuration,
|
LOGGING=logging_configuration,
|
||||||
LOGIN_URL='lib:login',
|
LOGIN_URL='lib:login',
|
||||||
LOGIN_REDIRECT_URL='apps:index',
|
LOGIN_REDIRECT_URL='apps:index',
|
||||||
@ -195,12 +193,10 @@ def configure_django():
|
|||||||
SESSION_ENGINE='django.contrib.sessions.backends.file',
|
SESSION_ENGINE='django.contrib.sessions.backends.file',
|
||||||
SESSION_FILE_PATH=sessions_directory,
|
SESSION_FILE_PATH=sessions_directory,
|
||||||
STATIC_URL='/'.join([cfg.server_dir, 'static/']).replace('//', '/'),
|
STATIC_URL='/'.join([cfg.server_dir, 'static/']).replace('//', '/'),
|
||||||
TEMPLATE_CONTEXT_PROCESSORS=context_processors,
|
TEMPLATE_CONTEXT_PROCESSORS=context_processors)
|
||||||
TEMPLATE_DIRS=template_directories)
|
|
||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
LOGGER.info('Configured Django')
|
LOGGER.info('Configured Django with applications - %s', applications)
|
||||||
LOGGER.info('Template directories - %s', template_directories)
|
|
||||||
|
|
||||||
LOGGER.info('Creating or adding new tables to data file')
|
LOGGER.info('Creating or adding new tables to data file')
|
||||||
django.core.management.call_command('syncdb', interactive=False)
|
django.core.management.call_command('syncdb', interactive=False)
|
||||||
|
|||||||
@ -32,6 +32,7 @@ from plinth.signals import pre_module_loading, post_module_loading
|
|||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
loaded_modules = []
|
loaded_modules = []
|
||||||
|
_modules_to_load = None
|
||||||
|
|
||||||
|
|
||||||
def load_modules():
|
def load_modules():
|
||||||
@ -41,17 +42,7 @@ def load_modules():
|
|||||||
"""
|
"""
|
||||||
pre_module_loading.send_robust(sender="module_loader")
|
pre_module_loading.send_robust(sender="module_loader")
|
||||||
modules = {}
|
modules = {}
|
||||||
module_directory = os.path.join(cfg.config_dir, 'modules-enabled')
|
for module_name in get_modules_to_load():
|
||||||
for file_name in os.listdir(module_directory):
|
|
||||||
full_file_name = os.path.join(module_directory, file_name)
|
|
||||||
with open(full_file_name, 'r') as file:
|
|
||||||
for line in file:
|
|
||||||
line = re.sub('#.*', '', line)
|
|
||||||
line = line.strip()
|
|
||||||
if line:
|
|
||||||
modules[line] = None
|
|
||||||
|
|
||||||
for module_name in modules:
|
|
||||||
LOGGER.info('Importing %s', module_name)
|
LOGGER.info('Importing %s', module_name)
|
||||||
try:
|
try:
|
||||||
modules[module_name] = importlib.import_module(module_name)
|
modules[module_name] = importlib.import_module(module_name)
|
||||||
@ -143,14 +134,22 @@ def _initialize_module(module):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def get_template_directories():
|
def get_modules_to_load():
|
||||||
"""Return the list of template directories"""
|
"""Get the list of modules to be loaded"""
|
||||||
directory = os.path.dirname(os.path.abspath(__file__))
|
global _modules_to_load
|
||||||
core_directory = os.path.join(directory, 'templates')
|
if _modules_to_load is not None:
|
||||||
|
return _modules_to_load
|
||||||
|
|
||||||
directories = set((core_directory,))
|
modules = []
|
||||||
module_directory = os.path.join(cfg.config_dir, 'modules-enabled')
|
module_directory = os.path.join(cfg.config_dir, 'modules-enabled')
|
||||||
for name in os.listdir(module_directory):
|
for file_name in os.listdir(module_directory):
|
||||||
directories.add(os.path.join(directory, 'modules', name, 'templates'))
|
full_file_name = os.path.join(module_directory, file_name)
|
||||||
|
with open(full_file_name, 'r') as file:
|
||||||
|
for line in file:
|
||||||
|
line = re.sub('#.*', '', line)
|
||||||
|
line = line.strip()
|
||||||
|
if line:
|
||||||
|
modules.append(line)
|
||||||
|
|
||||||
return directories
|
_modules_to_load = modules
|
||||||
|
return modules
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user