Refactor: split code into several django apps (we call them modules).

This commit is contained in:
2018-12-13 14:47:58 +01:00
parent c23dc33d4e
commit 0d5a8c65e3
81 changed files with 739 additions and 332 deletions

View File

View File

View File

@@ -0,0 +1,18 @@
from django.conf import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Disable a modular app from django-dav installation.'
def add_arguments(self, parser):
parser.add_argument('module')
def handle(self, *args, **options):
module_name = options['module']
config = settings.MODULE_CONFIG
del config.modules[module_name]
config.save()
self.stdout.write(self.style.SUCCESS('Module \'{}\' disabled.'.format(module_name)))

View File

@@ -0,0 +1,37 @@
import os
import pkg_resources
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from dav_base.config.modules import DJANGO_MAIN_MODULE, ModuleMeta
class Command(BaseCommand):
help = 'Enable a modular app in django-dav installation.'
def add_arguments(self, parser):
parser.add_argument('module', help='the name of the module')
def handle(self, *args, **options):
django_base_dir = settings.BASE_DIR
django_main_module = DJANGO_MAIN_MODULE
module_name = options['module']
config = settings.MODULE_CONFIG
if module_name in config.modules.keys():
raise CommandError('Module \'{}\' is already enabled'.format(module_name))
settings_file_name = 'settings-{}.py'.format(module_name)
input_file = os.path.join('django_project_config', settings_file_name)
if pkg_resources.resource_exists(module_name, input_file):
output_file = os.path.join(django_base_dir, django_main_module, settings_file_name)
if not os.path.exists(output_file):
with open(output_file, 'w') as f:
f.write(pkg_resources.resource_string(module_name, input_file))
module_meta_obj = ModuleMeta(module_name)
config.modules[module_name] = module_meta_obj
config.save()
self.stdout.write(self.style.SUCCESS('Module \'{}\' enabled.'.format(module_name)))

View File

@@ -0,0 +1,17 @@
from django.conf import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'List enabled modular apps in django-dav installation.'
def add_arguments(self, parser):
pass
def handle(self, *args, **options):
paragraphs = []
config = settings.MODULE_CONFIG
for obj in config.modules.values():
paragraphs.append(str(obj))
output = '\n'.join(paragraphs)
self.stdout.write(output)