Add clearer messages to command
This commit is contained in:
parent
8dc080a9fc
commit
5a71a9cec8
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue