diff --git a/codelist/management/commands/update_codelist.py b/codelist/management/commands/update_codelist.py index c6205f04..74bfd557 100644 --- a/codelist/management/commands/update_codelist.py +++ b/codelist/management/commands/update_codelist.py @@ -14,13 +14,15 @@ from codelist.settings import CODELIST_INTERVENTION_HANDLER_ID, CODELIST_CONSERV CODELIST_REGISTRATION_OFFICE_ID, CODELIST_BIOTOPES_ID, CODELIST_LAW_ID, CODELIST_COMPENSATION_HANDLER_ID, \ CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_CLASS_ID, CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID, \ CODELIST_COMPENSATION_FUNDING_ID, CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID +from konova.management.commands.setup import BaseKonovaCommand bool_map = { "true": True, "false": False, } -class Command(BaseCommand): + +class Command(BaseKonovaCommand): help = "Performs test on collisions using the identifier generation" def handle(self, *args, **options): @@ -101,33 +103,4 @@ class Command(BaseCommand): items=children, code_list=code_list, parent=code - ) - - def _break_line(self): - """ Simply prints a line break - - Returns: - - """ - self.stdout.write("\n") - - def _write_warning(self, txt: str): - self.stdout.write( - self.style.WARNING( - txt - ) - ) - - def _write_success(self, txt: str): - self.stdout.write( - self.style.SUCCESS( - txt - ) - ) - - def _write_error(self, txt: str): - self.stdout.write( - self.style.ERROR( - txt - ) - ) \ No newline at end of file + ) \ No newline at end of file diff --git a/konova/management/commands/setup.py b/konova/management/commands/setup.py index c7eeb42c..f02a8e36 100644 --- a/konova/management/commands/setup.py +++ b/konova/management/commands/setup.py @@ -8,7 +8,7 @@ Created on: 15.12.20 from getpass import getpass from django.contrib.auth.models import User, Group -from django.core.management import BaseCommand +from django.core.management import BaseCommand, call_command from django.db import transaction from konova.management.commands.setup_data import GROUPS_DATA, USER_NOTIFICATIONS_NAMES @@ -18,7 +18,45 @@ from user.models import UserNotification CREATED_TEMPLATE = "{} created" -class Command(BaseCommand): +class BaseKonovaCommand(BaseCommand): + def handle(self, *args, **options): + # Needs to be implemented in inheriting classes + raise NotImplementedError + + def _break_line(self): + """ Simply prints a line break + + Returns: + + """ + self.stdout.write("\n") + + def _write_warning(self, txt: str): + self.stdout.write( + self.style.WARNING( + txt + ) + ) + + def _write_success(self, txt: str): + self.stdout.write( + self.style.SUCCESS( + txt + ) + ) + + def _write_error(self, txt: str): + self.stdout.write( + self.style.ERROR( + txt + ) + ) + + class Meta: + abstract = True + + +class Command(BaseKonovaCommand): help = "Initializes database with basic data" def handle(self, *args, **options): @@ -27,6 +65,7 @@ class Command(BaseCommand): self._init_superuser() self._init_default_groups() self._init_user_notifications() + self._init_codelists() except KeyboardInterrupt: self._break_line() exit(-1) @@ -97,33 +136,11 @@ class Command(BaseCommand): self._break_line() def _init_codelists(self): - pass - - def _break_line(self): - """ Simply prints a line break + """ Calls the 'update_codelist' command found in codelist app Returns: """ - self.stdout.write("\n") - - def _write_warning(self, txt: str): - self.stdout.write( - self.style.WARNING( - txt - ) + return call_command( + 'update_codelist' ) - - def _write_success(self, txt: str): - self.stdout.write( - self.style.SUCCESS( - txt - ) - ) - - def _write_error(self, txt: str): - self.stdout.write( - self.style.ERROR( - txt - ) - ) \ No newline at end of file diff --git a/konova/management/commands/setup_data.py b/konova/management/commands/setup_data.py index 91082bd0..85e64907 100644 --- a/konova/management/commands/setup_data.py +++ b/konova/management/commands/setup_data.py @@ -9,21 +9,6 @@ from django.utils.translation import gettext_lazy as _ from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP -TEST_ORGANISATION_DATA = [ - { - "name": "Test_Official_1", - }, - { - "name": "Test_Official_2", - }, - { - "name": "Test_NGO_1", - }, - { - "name": "Test_Company_1", - }, - ] - GROUPS_DATA = [ { "name": DEFAULT_GROUP,