feat(fallback): add command for bulk team member creation
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
2d90662e4c
commit
23001a3de3
|
@ -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)
|
Loading…
Reference in New Issue