gold eggs backend
Some checks failed
Build and Push to Docker Hub / build-test-push (push) Failing after 1m55s

This commit is contained in:
2026-04-15 08:59:36 +02:00
commit ab73d05ecc
359 changed files with 14415 additions and 0 deletions

6
core/console/__init__.py Executable file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ConsoleConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "core.console"

View File

View File

View 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}")

View 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}"))

View File

@@ -0,0 +1,7 @@
from core.utils import console
class Command(console.BaseMake):
help = "Factory seeder"
path = "database/factory"
name = "Factory"

View File

@@ -0,0 +1,7 @@
from core.utils import console
class Command(console.BaseMake):
help = "Create seeder"
path = "database/seeder"
name = "Seeder"

View 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}")