Revised the accounting_accounts and accounting_sample commands to call the createsuperuser command when there is no user yet, instead of throwing an error in the accounting application.
This commit is contained in:
parent
4e411bdc43
commit
bc5f940e0a
@ -23,7 +23,8 @@ from typing import Optional, Dict
|
|||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.core.management import BaseCommand, CommandParser, CommandError
|
from django.core.management import BaseCommand, CommandParser, CommandError, \
|
||||||
|
call_command
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
|
||||||
from accounting.models import Account
|
from accounting.models import Account
|
||||||
@ -875,8 +876,8 @@ class Command(BaseCommand):
|
|||||||
error = F"User \"{username_option}\" does not exist."
|
error = F"User \"{username_option}\" does not exist."
|
||||||
raise CommandError(error, returncode=1)
|
raise CommandError(error, returncode=1)
|
||||||
if user_model.objects.count() == 0:
|
if user_model.objects.count() == 0:
|
||||||
error = "Please run the \"createsuperuser\" command first."
|
call_command("createsuperuser")
|
||||||
raise CommandError(error, returncode=1)
|
return user_model.objects.first()
|
||||||
if user_model.objects.count() == 1:
|
if user_model.objects.count() == 1:
|
||||||
return user_model.objects.first()
|
return user_model.objects.first()
|
||||||
try:
|
try:
|
||||||
|
@ -133,8 +133,8 @@ class Command(BaseCommand):
|
|||||||
error = F"User \"{username_option}\" does not exist."
|
error = F"User \"{username_option}\" does not exist."
|
||||||
raise CommandError(error, returncode=1)
|
raise CommandError(error, returncode=1)
|
||||||
if user_model.objects.count() == 0:
|
if user_model.objects.count() == 0:
|
||||||
error = "Please run the \"createsuperuser\" command first."
|
call_command("createsuperuser")
|
||||||
raise CommandError(error, returncode=1)
|
return user_model.objects.first()
|
||||||
if user_model.objects.count() == 1:
|
if user_model.objects.count() == 1:
|
||||||
return user_model.objects.first()
|
return user_model.objects.first()
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user