Merge pull request '17_Update_setup_command' (#29) from 17_Update_setup_command into master
Reviewed-on: SGD-Nord/konova#29
This commit is contained in:
commit
83378f27c1
@ -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_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_ACTION_ID, CODELIST_COMPENSATION_ACTION_CLASS_ID, CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID, \
|
||||||
CODELIST_COMPENSATION_FUNDING_ID, CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID
|
CODELIST_COMPENSATION_FUNDING_ID, CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID
|
||||||
|
from konova.management.commands.setup import BaseKonovaCommand
|
||||||
|
|
||||||
bool_map = {
|
bool_map = {
|
||||||
"true": True,
|
"true": True,
|
||||||
"false": False,
|
"false": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
|
class Command(BaseKonovaCommand):
|
||||||
help = "Performs test on collisions using the identifier generation"
|
help = "Performs test on collisions using the identifier generation"
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
@ -102,32 +104,3 @@ class Command(BaseCommand):
|
|||||||
code_list=code_list,
|
code_list=code_list,
|
||||||
parent=code
|
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
|
|
||||||
)
|
|
||||||
)
|
|
@ -76,7 +76,6 @@ class KonovaCodeList(models.Model):
|
|||||||
)
|
)
|
||||||
codes = models.ManyToManyField(
|
codes = models.ManyToManyField(
|
||||||
KonovaCode,
|
KonovaCode,
|
||||||
null=True,
|
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text="Codes for this list",
|
help_text="Codes for this list",
|
||||||
related_name="code_lists"
|
related_name="code_lists"
|
||||||
|
@ -141,7 +141,6 @@ class AbstractCompensation(BaseObject):
|
|||||||
|
|
||||||
fundings = models.ManyToManyField(
|
fundings = models.ManyToManyField(
|
||||||
KonovaCode,
|
KonovaCode,
|
||||||
null=True,
|
|
||||||
blank=True,
|
blank=True,
|
||||||
limit_choices_to={
|
limit_choices_to={
|
||||||
"code_lists__in": [CODELIST_COMPENSATION_FUNDING_ID],
|
"code_lists__in": [CODELIST_COMPENSATION_FUNDING_ID],
|
||||||
|
@ -161,7 +161,6 @@ class LegalData(UuidModel):
|
|||||||
)
|
)
|
||||||
laws = models.ManyToManyField(
|
laws = models.ManyToManyField(
|
||||||
KonovaCode,
|
KonovaCode,
|
||||||
null=True,
|
|
||||||
blank=True,
|
blank=True,
|
||||||
limit_choices_to={
|
limit_choices_to={
|
||||||
"code_lists__in": [CODELIST_LAW_ID],
|
"code_lists__in": [CODELIST_LAW_ID],
|
||||||
|
@ -14,35 +14,6 @@ from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES
|
|||||||
CODELIST_COMPENSATION_FUNDING_ID
|
CODELIST_COMPENSATION_FUNDING_ID
|
||||||
from compensation.models import EcoAccount
|
from compensation.models import EcoAccount
|
||||||
from intervention.models import Intervention
|
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):
|
class EcoAccountAutocomplete(Select2QuerySetView):
|
||||||
|
@ -8,27 +8,64 @@ Created on: 15.12.20
|
|||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
|
|
||||||
from django.contrib.auth.models import User, Group
|
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 django.db import transaction
|
||||||
|
|
||||||
from konova.management.commands.setup_data import TEST_ORGANISATION_DATA, GROUPS_DATA, USER_NOTIFICATIONS_NAMES
|
from konova.management.commands.setup_data import GROUPS_DATA, USER_NOTIFICATIONS_NAMES
|
||||||
from organisation.models import Organisation
|
|
||||||
from user.enums import UserNotificationEnum
|
from user.enums import UserNotificationEnum
|
||||||
from user.models import UserNotification
|
from user.models import UserNotification
|
||||||
|
|
||||||
CREATED_TEMPLATE = "{} created"
|
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"
|
help = "Initializes database with basic data"
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
self._init_superuser()
|
self._init_superuser()
|
||||||
self._init_test_organisation()
|
|
||||||
self._init_default_groups()
|
self._init_default_groups()
|
||||||
self._init_user_notifications()
|
self._init_user_notifications()
|
||||||
|
self._init_codelists()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self._break_line()
|
self._break_line()
|
||||||
exit(-1)
|
exit(-1)
|
||||||
@ -62,20 +99,6 @@ class Command(BaseCommand):
|
|||||||
self._write_success("Superuser {} created".format(username))
|
self._write_success("Superuser {} created".format(username))
|
||||||
self._break_line()
|
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):
|
def _init_default_groups(self):
|
||||||
""" Creates the default groups for konova:
|
""" Creates the default groups for konova:
|
||||||
* Group default
|
* Group default
|
||||||
@ -112,31 +135,12 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
self._break_line()
|
self._break_line()
|
||||||
|
|
||||||
def _break_line(self):
|
def _init_codelists(self):
|
||||||
""" Simply prints a line break
|
""" Calls the 'update_codelist' command found in codelist app
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.stdout.write("\n")
|
return call_command(
|
||||||
|
'update_codelist'
|
||||||
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
|
|
||||||
)
|
|
||||||
)
|
)
|
@ -9,21 +9,6 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
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 = [
|
GROUPS_DATA = [
|
||||||
{
|
{
|
||||||
"name": DEFAULT_GROUP,
|
"name": DEFAULT_GROUP,
|
||||||
|
@ -65,7 +65,6 @@ INSTALLED_APPS = [
|
|||||||
'konova',
|
'konova',
|
||||||
'compensation',
|
'compensation',
|
||||||
'intervention',
|
'intervention',
|
||||||
'organisation',
|
|
||||||
'news',
|
'news',
|
||||||
'user',
|
'user',
|
||||||
'ema',
|
'ema',
|
||||||
|
@ -17,7 +17,7 @@ import debug_toolbar
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
from konova.autocompletes import OrganisationAutocomplete, NonOfficialOrganisationAutocomplete, EcoAccountAutocomplete, \
|
from konova.autocompletes import EcoAccountAutocomplete, \
|
||||||
InterventionAutocomplete, CompensationActionCodeAutocomplete, BiotopeCodeAutocomplete, LawCodeAutocomplete, \
|
InterventionAutocomplete, CompensationActionCodeAutocomplete, BiotopeCodeAutocomplete, LawCodeAutocomplete, \
|
||||||
RegistrationOfficeCodeAutocomplete, ConservationOfficeCodeAutocomplete, ProcessTypeCodeAutocomplete, \
|
RegistrationOfficeCodeAutocomplete, ConservationOfficeCodeAutocomplete, ProcessTypeCodeAutocomplete, \
|
||||||
CompensationFundingCodeAutocomplete
|
CompensationFundingCodeAutocomplete
|
||||||
@ -34,7 +34,6 @@ urlpatterns = [
|
|||||||
path('intervention/', include("intervention.urls")),
|
path('intervention/', include("intervention.urls")),
|
||||||
path('compensation/', include("compensation.urls")),
|
path('compensation/', include("compensation.urls")),
|
||||||
path('ema/', include("ema.urls")),
|
path('ema/', include("ema.urls")),
|
||||||
path('organisation/', include("organisation.urls")),
|
|
||||||
path('user/', include("user.urls")),
|
path('user/', include("user.urls")),
|
||||||
path('news/', include("news.urls")),
|
path('news/', include("news.urls")),
|
||||||
path('news/', include("codelist.urls")),
|
path('news/', include("codelist.urls")),
|
||||||
@ -43,8 +42,6 @@ urlpatterns = [
|
|||||||
path('deadline/<id>/remove', remove_deadline_view, name="deadline-remove"),
|
path('deadline/<id>/remove', remove_deadline_view, name="deadline-remove"),
|
||||||
|
|
||||||
# Autocomplete paths for all apps
|
# 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/eco-accounts", EcoAccountAutocomplete.as_view(), name="accounts-autocomplete"),
|
||||||
path("atcmplt/interventions", InterventionAutocomplete.as_view(), name="interventions-autocomplete"),
|
path("atcmplt/interventions", InterventionAutocomplete.as_view(), name="interventions-autocomplete"),
|
||||||
path("atcmplt/codes/comp/action", CompensationActionCodeAutocomplete.as_view(), name="codes-compensation-action-autocomplete"),
|
path("atcmplt/codes/comp/action", CompensationActionCodeAutocomplete.as_view(), name="codes-compensation-action-autocomplete"),
|
||||||
|
@ -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)
|
|
@ -1,5 +0,0 @@
|
|||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class OrganisationConfig(AppConfig):
|
|
||||||
name = 'organisation'
|
|
@ -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
|
|
@ -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
|
|
@ -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 _
|
|
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
@ -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 = [
|
|
||||||
]
|
|
@ -1,3 +0,0 @@
|
|||||||
from django.shortcuts import render
|
|
||||||
|
|
||||||
# Create your views here.
|
|
Loading…
Reference in New Issue
Block a user