From 001fa4304139a9fd22d21d73cc2beea3e342a772 Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Sun, 19 Mar 2017 10:17:28 +0100 Subject: [PATCH] Add management command to populate db with initial data --- scipost/management/commands/populate_db.py | 23 ++++++++----------- .../management/commands/setup_contributor.py | 20 ++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 scipost/management/commands/setup_contributor.py diff --git a/scipost/management/commands/populate_db.py b/scipost/management/commands/populate_db.py index 26e2d1a3a..ae0f171dc 100644 --- a/scipost/management/commands/populate_db.py +++ b/scipost/management/commands/populate_db.py @@ -1,20 +1,17 @@ from django.core.management.base import BaseCommand -from django.contrib.auth.models import User -from ...models import Contributor +from ...factories import EditorialCollegeFactory, EditorialCollegeMemberFactory class Command(BaseCommand): - def add_arguments(self, parser): - parser.add_argument( - '--username', type=str, required=True, - help='Username of user to use for contributor model') + def create_editorial_college(self): + EditorialCollegeFactory.create_batch(5) + self.stdout.write(self.style.SUCCESS('Successfully created Editorial College\'s.')) - def create_contributor(self, username): - user = User.objects.get(username=username) - contributor = Contributor(user=user, status=1, title="MR") - contributor.vetted_by = contributor - contributor.save() + def create_editorial_college_members(self): + EditorialCollegeMemberFactory.create_batch(20) + self.stdout.write(self.style.SUCCESS('Successfully created Editorial College Members.')) - def handle(self, *args, **options): - self.create_contributor(options['username']) + def handle(self, *args, **kwargs): + self.create_editorial_college() + self.create_editorial_college_members() diff --git a/scipost/management/commands/setup_contributor.py b/scipost/management/commands/setup_contributor.py new file mode 100644 index 000000000..26e2d1a3a --- /dev/null +++ b/scipost/management/commands/setup_contributor.py @@ -0,0 +1,20 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth.models import User + +from ...models import Contributor + + +class Command(BaseCommand): + def add_arguments(self, parser): + parser.add_argument( + '--username', type=str, required=True, + help='Username of user to use for contributor model') + + def create_contributor(self, username): + user = User.objects.get(username=username) + contributor = Contributor(user=user, status=1, title="MR") + contributor.vetted_by = contributor + contributor.save() + + def handle(self, *args, **options): + self.create_contributor(options['username']) -- GitLab