gold eggs backend
Some checks failed
Build and Push to Docker Hub / build-test-push (push) Failing after 1m55s
Some checks failed
Build and Push to Docker Hub / build-test-push (push) Failing after 1m55s
This commit is contained in:
6
core/console/__init__.py
Executable file
6
core/console/__init__.py
Executable file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ConsoleConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "core.console"
|
||||
0
core/console/management/__init__.py
Executable file
0
core/console/management/__init__.py
Executable file
0
core/console/management/commands/__init__.py
Executable file
0
core/console/management/commands/__init__.py
Executable file
59
core/console/management/commands/factory.py
Executable file
59
core/console/management/commands/factory.py
Executable file
@@ -0,0 +1,59 @@
|
||||
import importlib
|
||||
import typing
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import management
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
class Command(management.BaseCommand):
|
||||
help = "factory database with"
|
||||
|
||||
def print(self, message, is_type="success"):
|
||||
if is_type == "success":
|
||||
self.stdout.write(self.style.SUCCESS(message))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(message))
|
||||
|
||||
def handle(self, *args, **options):
|
||||
FACTORYS: list[typing.Any] | typing.Any = (
|
||||
settings.FACTORYS if hasattr(settings, "FACTORYS") else []
|
||||
)
|
||||
|
||||
if len(FACTORYS) == 0:
|
||||
self.print(
|
||||
"FACTORYS not defined:\n\nsettings file add FACTORYS variable",
|
||||
"error",
|
||||
)
|
||||
return
|
||||
|
||||
for factory in FACTORYS:
|
||||
count = factory[1]
|
||||
factory = factory[0]
|
||||
|
||||
class_name = str(factory).split(".")[-1]
|
||||
module_path = ".".join(str(factory).split(".")[:-1])
|
||||
module = importlib.import_module(module_path)
|
||||
my_class = getattr(module, class_name)()
|
||||
|
||||
if not hasattr(my_class, "handle"):
|
||||
self.print("Handle function not found", "error")
|
||||
return
|
||||
if not hasattr(my_class, "model") or my_class.model is None:
|
||||
self.print("Model not found", "error")
|
||||
return
|
||||
try:
|
||||
self.print(f"Start factory: {factory}")
|
||||
progress_bar = tqdm(total=count)
|
||||
for i in range(count):
|
||||
progress_bar.update(1)
|
||||
try:
|
||||
data = my_class.handle()
|
||||
model = my_class.model
|
||||
model.objects.create(**data)
|
||||
except Exception as e:
|
||||
self.print(e, "error")
|
||||
except Exception as e:
|
||||
self.print(f"ERROR: {class_name} {e}", "error")
|
||||
return
|
||||
self.print(f"SUCCESS: {class_name}")
|
||||
31
core/console/management/commands/makeapp.py
Executable file
31
core/console/management/commands/makeapp.py
Executable file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
Create a new app in django project command
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management import base
|
||||
|
||||
|
||||
class Command(base.BaseCommand):
|
||||
help = "Generate new app"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("name")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
name = options.get("name")
|
||||
|
||||
if os.path.exists(
|
||||
os.path.join(settings.BASE_DIR, f"core/apps/{name}")
|
||||
):
|
||||
self.stdout.write(self.style.ERROR(f"App {name} already"))
|
||||
return
|
||||
try:
|
||||
os.system(
|
||||
f"cd ./core/apps && python3 ./../../manage.py startapp {name}"
|
||||
)
|
||||
self.stdout.write(self.style.SUCCESS(f"Make app {name} created"))
|
||||
except Exception as e:
|
||||
self.stdout.write(self.style.ERROR(f"Error: {e}"))
|
||||
7
core/console/management/commands/makefactory.py
Executable file
7
core/console/management/commands/makefactory.py
Executable file
@@ -0,0 +1,7 @@
|
||||
from core.utils import console
|
||||
|
||||
|
||||
class Command(console.BaseMake):
|
||||
help = "Factory seeder"
|
||||
path = "database/factory"
|
||||
name = "Factory"
|
||||
7
core/console/management/commands/makeseeder.py
Executable file
7
core/console/management/commands/makeseeder.py
Executable file
@@ -0,0 +1,7 @@
|
||||
from core.utils import console
|
||||
|
||||
|
||||
class Command(console.BaseMake):
|
||||
help = "Create seeder"
|
||||
path = "database/seeder"
|
||||
name = "Seeder"
|
||||
40
core/console/management/commands/seed.py
Executable file
40
core/console/management/commands/seed.py
Executable file
@@ -0,0 +1,40 @@
|
||||
import importlib
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import management
|
||||
|
||||
|
||||
class Command(management.BaseCommand):
|
||||
help = "seeder database with"
|
||||
|
||||
def print(self, message, is_type="success"):
|
||||
if is_type == "success":
|
||||
self.stdout.write(self.style.SUCCESS(message))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(message))
|
||||
|
||||
def handle(self, *args, **options):
|
||||
SEEDERS = settings.SEEDERS if hasattr(settings, "SEEDERS") else []
|
||||
|
||||
if len(SEEDERS) == 0:
|
||||
self.print(
|
||||
"SEEDERS not defined:\n\nsettings file add SEEDERS variable",
|
||||
"error",
|
||||
)
|
||||
return
|
||||
|
||||
for seeder in SEEDERS:
|
||||
class_name = str(seeder).split(".")[-1]
|
||||
module_path = ".".join(str(seeder).split(".")[:-1])
|
||||
module = importlib.import_module(module_path)
|
||||
my_class = getattr(module, class_name)()
|
||||
|
||||
if not hasattr(my_class, "run"):
|
||||
self.print("run function not found", "error")
|
||||
return
|
||||
try:
|
||||
my_class.run()
|
||||
except Exception as e:
|
||||
self.print(f"ERROR: {class_name} {e}", "error")
|
||||
return
|
||||
self.print(f"SUCCESS: {class_name}")
|
||||
Reference in New Issue
Block a user