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:
|
try:
|
||||||
module = Module.objects.get(slug=slug)
|
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:
|
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)
|
locale, _ = Locale.objects.get_or_create(language_code=language_code)
|
||||||
logger.debug("Starting conversion")
|
logger.debug("Starting conversion")
|
||||||
topic: Topic = module.get_parent()
|
topic: Topic = module.get_parent()
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,9 @@ class Command(BaseCommand):
|
||||||
slug=slug, original_slug=original_slug, language_code=language_code
|
slug=slug, original_slug=original_slug, language_code=language_code
|
||||||
)
|
)
|
||||||
self.stdout.write(result)
|
self.stdout.write(result)
|
||||||
except ModuleDoesNotExistException:
|
except ModuleDoesNotExistException as e:
|
||||||
raise CommandError("Module does not exist")
|
raise CommandError(f"Module does not exist: {e}")
|
||||||
except AlreadyTranslatedException:
|
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