devicehub-django/user/management/commands/add_institution.py

89 lines
2.6 KiB
Python
Raw Normal View History

2024-09-17 15:28:14 +00:00
from django.core.management.base import BaseCommand
from user.models import Institution
2025-02-25 12:34:07 +00:00
from lot.models import LotTag, Lot
2024-09-17 15:28:14 +00:00
2025-02-17 12:05:41 +00:00
2024-09-17 15:28:14 +00:00
class Command(BaseCommand):
help = "Create a new Institution"
def add_arguments(self, parser):
parser.add_argument('name', type=str, help='institution')
def handle(self, *args, **kwargs):
2024-09-18 16:01:46 +00:00
self.institution = Institution.objects.create(name=kwargs['name'])
self.create_lot_tags()
2025-02-25 12:34:07 +00:00
self.create_lots()
2024-09-18 16:01:46 +00:00
def create_lot_tags(self):
2025-02-17 12:05:41 +00:00
LotTag.objects.create(
inbox=True,
name="Inbox",
owner=self.institution
)
2024-09-18 16:01:46 +00:00
tags = [
"Entrada",
"Salida",
"Temporal"
]
for tag in tags:
LotTag.objects.create(
name=tag,
owner=self.institution
)
2025-02-25 12:34:07 +00:00
def create_lots(self):
for g in LotTag.objects.all():
if g.name == "Entrada":
Lot.objects.create(
name="donante-orgA",
owner=self.institution,
archived=True,
type=g
)
Lot.objects.create(
name="donante-orgB",
owner=self.institution,
type=g
)
Lot.objects.create(
name="donante-orgC",
owner=self.institution,
type=g
)
if g.name == "Salida":
Lot.objects.create(
name="beneficiario-org1",
owner=self.institution,
type=g
)
Lot.objects.create(
name="beneficiario-org2",
owner=self.institution,
archived=True,
type=g
)
Lot.objects.create(
name="beneficiario-org3",
owner=self.institution,
type=g
)
if g.name == "Temporal":
Lot.objects.create(
name="palet1",
owner=self.institution,
type=g
)
Lot.objects.create(
name="palet2",
owner=self.institution,
type=g
)
Lot.objects.create(
name="palet3",
owner=self.institution,
archived=True,
type=g
)