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/codelist/models.py b/codelist/models.py index 10c197a0..7537c8f7 100644 --- a/codelist/models.py +++ b/codelist/models.py @@ -76,7 +76,6 @@ class KonovaCodeList(models.Model): ) codes = models.ManyToManyField( KonovaCode, - null=True, blank=True, help_text="Codes for this list", related_name="code_lists" diff --git a/compensation/models.py b/compensation/models.py index a3384ba2..850ff7e5 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -141,7 +141,6 @@ class AbstractCompensation(BaseObject): fundings = models.ManyToManyField( KonovaCode, - null=True, blank=True, limit_choices_to={ "code_lists__in": [CODELIST_COMPENSATION_FUNDING_ID], diff --git a/intervention/models.py b/intervention/models.py index 1f5fdf8c..6b1fda72 100644 --- a/intervention/models.py +++ b/intervention/models.py @@ -161,7 +161,6 @@ class LegalData(UuidModel): ) laws = models.ManyToManyField( KonovaCode, - null=True, blank=True, limit_choices_to={ "code_lists__in": [CODELIST_LAW_ID], diff --git a/konova/autocompletes.py b/konova/autocompletes.py index 7acdca99..3930b6b4 100644 --- a/konova/autocompletes.py +++ b/konova/autocompletes.py @@ -14,35 +14,6 @@ from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES CODELIST_COMPENSATION_FUNDING_ID from compensation.models import EcoAccount from intervention.models import Intervention -from organisation.models import Organisation - - -class OrganisationAutocomplete(Select2QuerySetView): - def get_queryset(self): - if self.request.user.is_anonymous: - return Organisation.objects.none() - qs = Organisation.objects.all() - if self.q: - qs = qs.filter(name__icontains=self.q) - qs = qs.order_by( - "name" - ) - return qs - - -class NonOfficialOrganisationAutocomplete(Select2QuerySetView): - def get_queryset(self): - if self.request.user.is_anonymous: - return Organisation.objects.none() - qs = Organisation.objects.all() - if self.q: - qs = qs.filter( - name__icontains=self.q, - ) - qs = qs.order_by( - "name" - ) - return qs class EcoAccountAutocomplete(Select2QuerySetView): diff --git a/konova/management/commands/setup.py b/konova/management/commands/setup.py index 831998bd..f02a8e36 100644 --- a/konova/management/commands/setup.py +++ b/konova/management/commands/setup.py @@ -8,27 +8,64 @@ 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 TEST_ORGANISATION_DATA, GROUPS_DATA, USER_NOTIFICATIONS_NAMES -from organisation.models import Organisation +from konova.management.commands.setup_data import GROUPS_DATA, USER_NOTIFICATIONS_NAMES from user.enums import UserNotificationEnum 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): try: with transaction.atomic(): self._init_superuser() - self._init_test_organisation() self._init_default_groups() self._init_user_notifications() + self._init_codelists() except KeyboardInterrupt: self._break_line() exit(-1) @@ -62,20 +99,6 @@ class Command(BaseCommand): self._write_success("Superuser {} created".format(username)) self._break_line() - def _init_test_organisation(self): - """ Creates test organisations from predefined data - - Returns: - - """ - self._write_warning("--- Organisations ---") - for org in TEST_ORGANISATION_DATA: - db_org = Organisation.objects.get_or_create( - **org - )[0] - self._write_success(CREATED_TEMPLATE.format(db_org.name)) - self._break_line() - def _init_default_groups(self): """ Creates the default groups for konova: * Group default @@ -112,31 +135,12 @@ class Command(BaseCommand): self._break_line() - def _break_line(self): - """ Simply prints a line break + def _init_codelists(self): + """ 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, diff --git a/konova/sub_settings/django_settings.py b/konova/sub_settings/django_settings.py index d579d87d..568492f5 100644 --- a/konova/sub_settings/django_settings.py +++ b/konova/sub_settings/django_settings.py @@ -65,7 +65,6 @@ INSTALLED_APPS = [ 'konova', 'compensation', 'intervention', - 'organisation', 'news', 'user', 'ema', diff --git a/konova/urls.py b/konova/urls.py index 0c2bef21..8448cb4e 100644 --- a/konova/urls.py +++ b/konova/urls.py @@ -17,7 +17,7 @@ import debug_toolbar from django.contrib import admin from django.urls import path, include -from konova.autocompletes import OrganisationAutocomplete, NonOfficialOrganisationAutocomplete, EcoAccountAutocomplete, \ +from konova.autocompletes import EcoAccountAutocomplete, \ InterventionAutocomplete, CompensationActionCodeAutocomplete, BiotopeCodeAutocomplete, LawCodeAutocomplete, \ RegistrationOfficeCodeAutocomplete, ConservationOfficeCodeAutocomplete, ProcessTypeCodeAutocomplete, \ CompensationFundingCodeAutocomplete @@ -34,7 +34,6 @@ urlpatterns = [ path('intervention/', include("intervention.urls")), path('compensation/', include("compensation.urls")), path('ema/', include("ema.urls")), - path('organisation/', include("organisation.urls")), path('user/', include("user.urls")), path('news/', include("news.urls")), path('news/', include("codelist.urls")), @@ -43,8 +42,6 @@ urlpatterns = [ path('deadline//remove', remove_deadline_view, name="deadline-remove"), # Autocomplete paths for all apps - path("atcmplt/orgs", OrganisationAutocomplete.as_view(), name="orgs-autocomplete"), - path("atcmplt/orgs/other", NonOfficialOrganisationAutocomplete.as_view(), name="other-orgs-autocomplete"), path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="accounts-autocomplete"), path("atcmplt/interventions", InterventionAutocomplete.as_view(), name="interventions-autocomplete"), path("atcmplt/codes/comp/action", CompensationActionCodeAutocomplete.as_view(), name="codes-compensation-action-autocomplete"), diff --git a/organisation/__init__.py b/organisation/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/organisation/admin.py b/organisation/admin.py deleted file mode 100644 index 52d6cfe2..00000000 --- a/organisation/admin.py +++ /dev/null @@ -1,13 +0,0 @@ -from django.contrib import admin - -from organisation.models import Organisation - - -class OrganisationAdmin(admin.ModelAdmin): - list_display = [ - "name", - "created", - ] - - -admin.site.register(Organisation, OrganisationAdmin) diff --git a/organisation/apps.py b/organisation/apps.py deleted file mode 100644 index ef395214..00000000 --- a/organisation/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class OrganisationConfig(AppConfig): - name = 'organisation' diff --git a/organisation/enums.py b/organisation/enums.py deleted file mode 100644 index 4ba53e66..00000000 --- a/organisation/enums.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -Author: Michel Peltriaux -Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany -Contact: michel.peltriaux@sgdnord.rlp.de -Created on: 07.12.20 - -""" -from konova.enums import BaseEnum diff --git a/organisation/models.py b/organisation/models.py deleted file mode 100644 index 890422a4..00000000 --- a/organisation/models.py +++ /dev/null @@ -1,16 +0,0 @@ -from django.db import models - -from konova.models import BaseResource - - -class Organisation(BaseResource): - name = models.CharField(max_length=500, unique=True) - address = models.CharField(max_length=500, null=True, blank=True) - city = models.CharField(max_length=500, null=True, blank=True) - postal_code = models.CharField(max_length=100, null=True, blank=True) - phone = models.CharField(max_length=500, null=True, blank=True) - email = models.EmailField(max_length=500, null=True, blank=True) - facsimile = models.CharField(max_length=500, null=True, blank=True) - - def __str__(self): - return self.name diff --git a/organisation/settings.py b/organisation/settings.py deleted file mode 100644 index 5369533c..00000000 --- a/organisation/settings.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -Author: Michel Peltriaux -Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany -Contact: michel.peltriaux@sgdnord.rlp.de -Created on: 07.12.20 - -""" -from django.utils.translation import gettext_lazy as _ diff --git a/organisation/tests.py b/organisation/tests.py deleted file mode 100644 index 7ce503c2..00000000 --- a/organisation/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/organisation/urls.py b/organisation/urls.py deleted file mode 100644 index 168b7da7..00000000 --- a/organisation/urls.py +++ /dev/null @@ -1,12 +0,0 @@ -""" -Author: Michel Peltriaux -Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany -Contact: michel.peltriaux@sgdnord.rlp.de -Created on: 07.12.20 - -""" -from django.urls import path - -app_name = "organisation" -urlpatterns = [ -] \ No newline at end of file diff --git a/organisation/views.py b/organisation/views.py deleted file mode 100644 index 91ea44a2..00000000 --- a/organisation/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here.