Initial commit from ZIP
This commit is contained in:
commit
378d4692a9
454 files changed
+40367
No files matched your search
Whitespace-only changes.
+236
@@ -0,0 +1,236 @@
|
||||
from typing import TYPE_CHECKING, Tuple, Iterable
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from faker import Factory
|
||||
|
||||
from tests.factories.authentication import (
|
||||
UserFactory,
|
||||
AgencyUserFactory,
|
||||
ClientUserFactory,
|
||||
SupplierUserFactory,
|
||||
)
|
||||
from tests.factories.organizations import (
|
||||
CategoryFactory,
|
||||
BrandFactory,
|
||||
)
|
||||
|
||||
from tests.factories.products import ProductStageFactory, PackagingTypeFactory
|
||||
from tests.factories.token import TokenFactory
|
||||
|
||||
faker = Factory()
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from outbo.apps.organizations.models import ClientOrganization
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Seed with some existing data"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("--dev", action="store_true", help="Seed with dev data")
|
||||
|
||||
def __make_users_and_organizations(self, *, password=None):
|
||||
self.stdout.write("Seeding organizations and users...")
|
||||
|
||||
if password is None:
|
||||
password = "password"
|
||||
|
||||
UserFactory(
|
||||
username="admin",
|
||||
password=password,
|
||||
email="admin@example.com",
|
||||
is_superuser=True,
|
||||
is_staff=True,
|
||||
)
|
||||
|
||||
agency = AgencyUserFactory(
|
||||
username="agency",
|
||||
password=password,
|
||||
email="agency@example.com",
|
||||
organization__name="Sample agency",
|
||||
)
|
||||
|
||||
client = ClientUserFactory(
|
||||
username="client",
|
||||
password=password,
|
||||
email="client@example.com",
|
||||
organization__name="Sample client",
|
||||
)
|
||||
|
||||
supplier = SupplierUserFactory(
|
||||
username="supplier",
|
||||
password=password,
|
||||
email="supplier@example.com",
|
||||
organization__name="Sample supplier",
|
||||
)
|
||||
|
||||
TokenFactory(user=agency, key="6f9afaa36ee8b224181dc14e2ca9af33e97c0f71")
|
||||
TokenFactory(user=client, key="481372f60325289029679df25c72e6ccd05892ed")
|
||||
TokenFactory(user=supplier, key="d23d8f187614c8a76fe7316470e6f50ff5bc4188")
|
||||
|
||||
def __make_product_stages(self):
|
||||
self.stdout.write("Seeding product stages...")
|
||||
|
||||
ProductStageFactory(
|
||||
id="waiting_for_brief",
|
||||
label="1",
|
||||
group=1,
|
||||
description="Briefing",
|
||||
next_action="Oczekuje na uzupełnienie briefu",
|
||||
order=1,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_brief_accept_by_agency",
|
||||
label="1A",
|
||||
group=1,
|
||||
description="Akceptacja agencji",
|
||||
next_action="Oczekuje na akceptację agencji",
|
||||
order=2,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_brief_accept_by_client",
|
||||
label="1B",
|
||||
group=1,
|
||||
description="Akceptacja klienta",
|
||||
next_action="Oczekuje na akceptację klienta",
|
||||
order=3,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_draft",
|
||||
label="2A",
|
||||
group=2,
|
||||
description="Publikacja draftu",
|
||||
next_action="Oczekuje na publikację draftu",
|
||||
order=4,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_draft_accept_by_supplier",
|
||||
label="2B",
|
||||
group=2,
|
||||
description="Akceptacja dostawcy",
|
||||
next_action="Oczekuje na akceptację dostawcy",
|
||||
order=5,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_draft_accept_by_client",
|
||||
label="2C",
|
||||
group=2,
|
||||
description="Akceptacja klienta",
|
||||
next_action="Oczekuje na akceptację klientget_random_stringa",
|
||||
order=6,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_ff",
|
||||
label="3A",
|
||||
group=3,
|
||||
description="Publikacja FF",
|
||||
next_action="Oczekuje na publikację draftu",
|
||||
order=7,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_ff_accept_by_supplier",
|
||||
label="3B",
|
||||
group=3,
|
||||
description="Akceptacja dostawcy",
|
||||
next_action="Oczekuje na akceptację dostawcy",
|
||||
order=8,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_ff_accept_by_client",
|
||||
label="3C",
|
||||
group=3,
|
||||
description="Akceptacja klienta",
|
||||
next_action="Oczekuje na akceptację klienta",
|
||||
order=9,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_pf",
|
||||
label="4A",
|
||||
group=4,
|
||||
description="Publikacja printing files",
|
||||
next_action="Oczekuje na publikację printing files",
|
||||
order=10,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_pf_accept_by_supplier",
|
||||
label="4B",
|
||||
group=4,
|
||||
description="Akceptacja dostawcy",
|
||||
next_action="Oczekuje na akceptację dostawcy",
|
||||
order=11,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="waiting_for_pf_accept_by_client",
|
||||
label="4C",
|
||||
group=4,
|
||||
description="Akceptacja klienta",
|
||||
next_action="Oczekuje na akceptację klienta",
|
||||
order=12,
|
||||
)
|
||||
ProductStageFactory(
|
||||
id="completed",
|
||||
label="5",
|
||||
group=5,
|
||||
description="Zako\u0144czono",
|
||||
next_action="Oczekuje na archiwizację",
|
||||
order=13,
|
||||
)
|
||||
|
||||
def __make_packaging_types(self, *, items: Iterable[str] = None):
|
||||
self.stdout.write("Seeding packaging types...")
|
||||
if items:
|
||||
for name in items:
|
||||
PackagingTypeFactory(name=name)
|
||||
else:
|
||||
PackagingTypeFactory.create_batch(size=20)
|
||||
|
||||
def __make_brands(
|
||||
self, *, items: Iterable[Tuple[str, "ClientOrganization"]] = None
|
||||
):
|
||||
self.stdout.write("Seeding brands...")
|
||||
if items:
|
||||
for name, client in items:
|
||||
BrandFactory(name=name, client=client)
|
||||
else:
|
||||
BrandFactory.create_batch(size=20)
|
||||
|
||||
def __make_categories(self, *, items: Iterable[str] = None):
|
||||
self.stdout.write("Seeding categories...")
|
||||
if items:
|
||||
for item in items:
|
||||
CategoryFactory(name=item)
|
||||
else:
|
||||
CategoryFactory.create_batch(size=20)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.stdout.write("Seeding the database...")
|
||||
|
||||
if not options["dev"]:
|
||||
packaging_types = (
|
||||
"Carton/gift box",
|
||||
"Header",
|
||||
"Hangtag",
|
||||
"Paper band",
|
||||
"Paper board",
|
||||
"Blister",
|
||||
"Image insert",
|
||||
"Simple band",
|
||||
"Label/sticker",
|
||||
"Simple CDU/Displaybox",
|
||||
)
|
||||
raise NotImplementedError()
|
||||
|
||||
password = "!secret123"
|
||||
|
||||
self.__make_users_and_organizations(password=password)
|
||||
self.__make_product_stages()
|
||||
self.__make_packaging_types()
|
||||
self.__make_brands()
|
||||
self.__make_categories()
|
||||
|
||||
self.stdout.write("Seeding completed.")
|
||||
self.stdout.write("Credentials:")
|
||||
self.stdout.write(f" admin: {password}")
|
||||
self.stdout.write(f" agency: {password}")
|
||||
self.stdout.write(f" client: {password}")
|
||||
self.stdout.write(f" supplier: {password}")
|
||||
Reference in new issue
Block a user