2
0
Fork 0

feat(fallback): add command for bulk team member creation
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Luca 2024-05-19 23:22:46 +02:00
parent 2d90662e4c
commit 23001a3de3
3 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,42 @@
import sys
from django.core.management.base import BaseCommand, CommandError
from ...models import TeamMember
class Command(BaseCommand):
help = "Import a list of team members, optionally including their affiliations (stored in the comment field)"
def add_arguments(self, parser):
parser.add_argument(
"-d",
"--delimiter",
default=":",
help="character separating name from affiliations",
)
def handle(self, *args, **options):
try:
self._handle(*args, **options)
except KeyboardInterrupt:
self.stderr.write()
except Exception as e:
raise CommandError(e)
def _handle(self, *args, **options):
team_members = []
for line in sys.stdin.readlines():
line = line.strip()
if line == "" or line.startswith("#"):
continue
match line.split(options["delimiter"], maxsplit=1):
case [name, affiliations]:
team_members.append(
TeamMember(name=name, comment=affiliations.strip())
)
case [name]:
team_members.append(TeamMember(name=name))
TeamMember.objects.bulk_create(team_members)