Add clearer messages to command

This commit is contained in:
Ramon Wenger 2023-08-30 16:38:15 +02:00
parent 8dc080a9fc
commit 5a71a9cec8
2 changed files with 12 additions and 7 deletions

View File

@ -29,11 +29,14 @@ def convert_page_to_translation(slug: str, original_slug: str, language_code="en
"""
try:
module = Module.objects.get(slug=slug)
original = Module.objects.get(slug=original_slug)
if original.translation_key == module.translation_key:
raise AlreadyTranslatedException
except Module.DoesNotExist:
raise ModuleDoesNotExistException
raise ModuleDoesNotExistException(slug)
try:
original = Module.objects.get(slug=original_slug)
except Module.DoesNotExist:
raise ModuleDoesNotExistException(original_slug)
if original.translation_key == module.translation_key:
raise AlreadyTranslatedException
locale, _ = Locale.objects.get_or_create(language_code=language_code)
logger.debug("Starting conversion")
topic: Topic = module.get_parent()

View File

@ -35,7 +35,9 @@ class Command(BaseCommand):
slug=slug, original_slug=original_slug, language_code=language_code
)
self.stdout.write(result)
except ModuleDoesNotExistException:
raise CommandError("Module does not exist")
except ModuleDoesNotExistException as e:
raise CommandError(f"Module does not exist: {e}")
except AlreadyTranslatedException:
raise CommandError("Pages already are translations of each other")
raise CommandError(
f"Pages {slug} and {original_slug} already are translations of each other"
)