Skip to content

Commit

Permalink
Add some warnings message when you forgot to populate search configur…
Browse files Browse the repository at this point in the history
…ation & header-filters for our models.
  • Loading branch information
genglert committed Apr 18, 2023
1 parent 580b7a5 commit ac7378a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions creme/creme_core/management/commands/creme_populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
from django.db.models.signals import pre_save

from creme.creme_core.apps import creme_app_configs
from creme.creme_core.models import HeaderFilter, SearchConfigItem
from creme.creme_core.utils.collections import OrderedSet
from creme.creme_core.utils.content_type import entity_ctypes
from creme.creme_core.utils.dependence_sort import dependence_sort


Expand Down Expand Up @@ -80,13 +82,50 @@ def get_dependencies(self) -> list[str]:
return self.dependencies


def check_hfilters():
ctypes = {ctype.id: ctype for ctype in entity_ctypes()}
missing_ct_ids = {*ctypes.keys()} - {
*HeaderFilter.objects.filter(
user=None, is_custom=False,
).values_list('entity_type', flat=True),
}

if missing_ct_ids:
yield (
'BEWARE, these types of entity do not have default configuration '
'for views of list (i.e. HeaderFilter): '
+ ', '.join(str(ctypes[ct_id]) for ct_id in missing_ct_ids)
)


def check_search():
ctypes = {ctype.id: ctype for ctype in entity_ctypes()}
missing_ct_ids = {*ctypes.keys()} - {
*SearchConfigItem.objects.filter(
role=None, superuser=False,
).values_list('content_type', flat=True),
}

if missing_ct_ids:
yield (
'BEWARE, these types of entity do not have default configuration '
'for global search (i.e. SearchConfigItem): '
+ ', '.join(str(ctypes[ct_id]) for ct_id in missing_ct_ids)
)


class Command(BaseCommand):
help = ('Populates the database for the specified applications, or the '
'entire site if no apps are specified.')
# args = '[appname ...]'
leave_locale_alone = True
requires_migrations_checks = True

end_checks = [
check_hfilters,
check_search,
]

def _signal_handler(self, sender, instance, **kwargs):
if instance.pk and not isinstance(instance.pk, str):
# Models with string pk should manage pk manually, so we can optimise
Expand Down Expand Up @@ -208,6 +247,13 @@ def handle(self, *app_labels, **options):
elif verbosity >= 1:
self.stdout.write('No sequence to update.')

# ----------------------------------------------------------------------
if verbosity:
for end_check in self.end_checks:
for message in end_check():
self.stdout.write(message)

# ----------------------------------------------------------------------
if verbosity >= 1:
self.stdout.write(self.style.SUCCESS('Populate is OK.'))

Expand Down

0 comments on commit ac7378a

Please sign in to comment.