From ea02c6d6dbc816592df8d85fa627ed22797baab0 Mon Sep 17 00:00:00 2001
From: Geert Kapteijns <ghkapteijns@gmail.com>
Date: Tue, 13 Dec 2016 23:29:45 +0100
Subject: [PATCH] Make management command `populate_db.py`

Right now, this only creates a contributor based on a username.
But I hope that, in the future, we can populate an entire development
database with this command.
---
 scipost/management/commands/populate_db.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 scipost/management/commands/populate_db.py

diff --git a/scipost/management/commands/populate_db.py b/scipost/management/commands/populate_db.py
new file mode 100644
index 000000000..26e2d1a3a
--- /dev/null
+++ b/scipost/management/commands/populate_db.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