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
337d7b39e7
@ -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
|
||||
)
|
||||
)
|
||||
)
|
@ -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"
|
||||
|
@ -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],
|
||||
|
@ -161,7 +161,6 @@ class LegalData(UuidModel):
|
||||
)
|
||||
laws = models.ManyToManyField(
|
||||
KonovaCode,
|
||||
null=True,
|
||||
blank=True,
|
||||
limit_choices_to={
|
||||
"code_lists__in": [CODELIST_LAW_ID],
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
)
|
||||
)
|
@ -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,
|
||||
|
@ -65,7 +65,6 @@ INSTALLED_APPS = [
|
||||
'konova',
|
||||
'compensation',
|
||||
'intervention',
|
||||
'organisation',
|
||||
'news',
|
||||
'user',
|
||||
'ema',
|
||||
|
@ -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/<id>/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"),
|
||||
|
@ -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