summaryrefslogtreecommitdiff
path: root/ishtar_common/management
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2026-02-24 15:16:56 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2026-02-25 10:15:33 +0100
commit53b408380649f39880763b35a2a9d24eb7cc014a (patch)
tree4a932ebc46229239d7bcb9e21f36ce84efa969c9 /ishtar_common/management
parent13e838988e0a32e0ef54c15d90c8df2f92dad853 (diff)
downloadIshtar-53b408380649f39880763b35a2a9d24eb7cc014a.tar.bz2
Ishtar-53b408380649f39880763b35a2a9d24eb7cc014a.zip
♻️ imports: simplify, refactor and clean
Diffstat (limited to 'ishtar_common/management')
-rw-r--r--ishtar_common/management/commands/process_initialize_item_keys.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/ishtar_common/management/commands/process_initialize_item_keys.py b/ishtar_common/management/commands/process_initialize_item_keys.py
index 4ccaadc0a..e493066f1 100644
--- a/ishtar_common/management/commands/process_initialize_item_keys.py
+++ b/ishtar_common/management/commands/process_initialize_item_keys.py
@@ -16,12 +16,13 @@ from ishtar_common.utils import get_log_time, get_percent, get_eta, BColors
def write_output(base_lbl, idx, total, ref_time):
lbl = f"\r{BColors.OKBLUE}[{get_percent(idx, total)}] {base_lbl} {idx + 1}/{total}"
- lbl += f" ({get_eta(idx, total, ref_time, datetime.datetime.now())} left){BColors.ENDC}"
+ lbl += f" ({get_eta(idx, total, ref_time, datetime.datetime.now())} left)"
+ lbl += "{BColors.ENDC}"
sys.stdout.write(lbl)
sys.stdout.flush()
-def migrate_item_key(clean_old=False):
+def migrate_item_key(clean_old=False, quiet=False):
"""
clean_old=False: set to True to migrate from non unicode to unicode
"""
@@ -34,13 +35,14 @@ def migrate_item_key(clean_old=False):
if any(1 for attr in ("available", "txt_idx", "comment", "available")
if not hasattr(model, attr)):
continue # not a general type
- content_type = ContentType.objects.get(app_label=app,
- model=model._meta.model_name)
+ content_type, __ = ContentType.objects.get_or_create(
+ app_label=app, model=model._meta.model_name)
ref_time = datetime.datetime.now()
q = model.objects
nb = q.count()
for idx, item in enumerate(q.all()):
- write_output(model._meta.verbose_name, idx, nb, ref_time)
+ if not quiet:
+ write_output(model._meta.verbose_name, idx, nb, ref_time)
if clean_old:
ItemKey.objects.filter(
key=slugify(item.label),
@@ -52,7 +54,8 @@ def migrate_item_key(clean_old=False):
importer_type=None, ishtar_import=None, user=None,
group=None)
lbl = f"\r{BColors.OKGREEN}* {model._meta.verbose_name} - OK{SPACE}{BColors.ENDC}\n"
- sys.stdout.write(lbl)
+ if not quiet:
+ sys.stdout.write(lbl)
class Command(BaseCommand):
@@ -73,5 +76,4 @@ class Command(BaseCommand):
if not quiet:
sys.stdout.write(f"{BColors.OKGREEN}[{get_log_time()}] Processing{BColors.ENDC}")
settings.USE_BACKGROUND_TASK = False
- migrate_item_key(clean_old=options["clean_old"])
- sys.exit(1)
+ migrate_item_key(clean_old=options["clean_old"], quiet=quiet)