We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Modify database seeding method
## Deliverables

- [ ] Modify the seed command to accept an argument `-nc` which denotes the number of challenges that a developer wants to create for testing.
- [ ] Modify the seed script in such a way that it can be run multiple times (right now, if you run it once and then you try to run it again, then it throws an error). 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/base/management/commands/seed.py`
Content:
```
1 from django.core.management import BaseCommand, call_command
2 
3 
4 class Command(BaseCommand):
5 
6     help = "Seeds the database with random but sensible values."
7 
8     def handle(self, *args, **options):
9         self.stdout.write(self.style.SUCCESS('Starting the database seeder. Hang on...'))
10         call_command('runscript', 'seed', '--settings', 'settings.dev')
11
```

Path: `scripts/seed.py`
Content:
```
1 # Command to run : python manage.py shell  < scripts/seed.py
2 import os
3 
4 from datetime import timedelta
5 
6 from django.conf import settings
7 from django.contrib.auth.models import User
8 from django.core.files.uploadedfile import SimpleUploadedFile
9 from django.utils import timezone
10 
11 from allauth.account.models import EmailAddress
12 from faker import Factory
13 
14 from challenges.models import Challenge, ChallengePhase, DatasetSplit, Leaderboard, ChallengePhaseSplit
15 from hosts.models import ChallengeHostTeam, ChallengeHost
16 from participants.models import Participant, ParticipantTeam
17 
18 fake = Factory.create()
19 
20 NUMBER_OF_CHALLENGES = 1
21 NUMBER_OF_PHASES = 2
22 NUMBER_OF_DATASET_SPLITS = 2
23 DATASET_SPLIT_ITERATOR = 0
24 
25 try:
26     xrange          # Python 2
27 except NameError:
28     xrange = range  # Python 3
29 
30 
31 def check_database():
32     if len(EmailAddress.objects.all()) > 0:
33         print("Are you sure you want to wipe the existing development database and reseed it? (Y/N)")
34         if raw_input().lower() == "y":
35             destroy_database()
36         else:
37             return False
38     else:
39         return True
40 
41 
42 def destroy_database():
43     print("Destroying existing database...")
44     print("Destroying Participant objects...")
45     Participant.objects.all().delete()
46     print("Destroying ParticipantTeam objects...")
47     ParticipantTeam.objects.all().delete()
48     print("Destroying ChallengePhaseSplit objects...")
49     ChallengePhaseSplit.objects.all().delete()
50     print("Destroying DatasetSplit objects...")
51     DatasetSplit.objects.all().delete()
52     print("Destroying ChallengePhase objects...")
53     ChallengePhase.objects.all().delete()
54     print("Destroying Leaderboard objects...")
55     Leaderboard.objects.all().delete()
56     print("Destroying Challenge objects...")
57     Challenge.objects.all().delete()
58     print("Destroying ChallengeHostTeam objects...")
59     ChallengeHostTeam.objects.all().delete()
60     print("Destroying ChallengeHost objects...")
61     ChallengeHost.objects.all().delete()
62     print("Destroying User objects...")
63     User.objects.all().delete()
64     print("Destroying EmailAddress objects...")
65     EmailAddress.objects.all().delete()
66     return True
67 
68 
69 def create_user(is_admin, username=""):
70     """
71     Creates superuser, participant user, host user and returns it.
72     """
73     if is_admin:
74         username = "admin"
75         email = "admin@example.com"
76     else:
77         email = "%s@example.com" % (username)
78     user = User.objects.create_user(
79         email=email,
80         username=username,
81         password="password",
82         is_staff=is_admin,
83         is_superuser=is_admin,
84     )
85     EmailAddress.objects.create(user=user, email=email, verified=True, primary=True)
86     print("{} was created with username: {} password: password".format("Super user" if is_admin else "User", username))
87     return user
88 
89 
90 def create_challenge_host_team(user):
91     """
92     Creates challenge host team and returns it.
93     """
94     team_name = "{} Host Team".format(fake.city())
95     team = ChallengeHostTeam.objects.create(
96         team_name=team_name,
97         created_by=user,
98     )
99     print("Challenge Host Team created with team_name: {} created_by: {}".format(team_name, user.username))
100     ChallengeHost.objects.create(user=user, team_name=team, status=ChallengeHost.SELF, permissions=ChallengeHost.ADMIN)
101     print("Challenge Host created with user: {} team_name: {}".format(user.username, team_name))
102     return team
103 
104 
105 def create_challenges(number_of_challenges=3, host_team=None):
106     """
107     Creates past challenge, on-going challenge and upcoming challenge.
108     """
109     for i in xrange(number_of_challenges):
110         if (i % 3 == 0):
111             create_challenge("{} Challenge".format(fake.first_name()),
112                              timezone.now() - timedelta(days=100),
113                              timezone.now() + timedelta(days=500),
114                              host_team
115                              )
116         elif (i % 3 == 1):
117             create_challenge("{} Challenge" % (fake.first_name()),
118                              timezone.now() - timedelta(days=500),
119                              timezone.now() - timedelta(days=100),
120                              host_team
121                              )
122         elif (i % 3 == 2):
123             create_challenge("{} Challenge" % (fake.first_name()),
124                              timezone.now() + timedelta(days=100),
125                              timezone.now() + timedelta(days=500),
126                              host_team
127                              )
128 
129 
130 def create_challenge(title, start_date, end_date, host_team):
131     """
132     Creates a challenge.
133     """
134     evaluation_script = open(os.path.join(settings.BASE_DIR, 'examples', 'example1', 'string_matching.zip'), 'rb')
135     Challenge.objects.create(
136         title=title,
137         short_description=fake.paragraph(),
138         description=fake.paragraph(),
139         terms_and_conditions=fake.paragraph(),
140         submission_guidelines=fake.paragraph(),
141         evaluation_details=fake.paragraph(),
142         evaluation_script=SimpleUploadedFile(evaluation_script.name, evaluation_script.read()),
143         approved_by_admin=True,
144         creator=host_team,
145         published=True,
146         enable_forum=True,
147         anonymous_leaderboard=False,
148         start_date=start_date,
149         end_date=end_date,
150     )
151     print("Challenge created with title: {} creator: {} start_date: {} end_date: {}".format(title,
152                                                                                             host_team.team_name,
153                                                                                             start_date, end_date))
154 
155 
156 def create_challenge_phases(challenge, number_of_phases=1):
157     """
158     Creates challenge phases for the created challenges and returns it.
159     """
160     challenge_phases = []
161     for i in range(number_of_phases):
162         name = "{} Phase".format(fake.first_name())
163         with open(os.path.join(settings.BASE_DIR, 'examples', 'example1', 'test_annotation.txt'), 'rb') as data_file:
164             data = data_file.read()
165         data = data or None
166         challenge_phase = ChallengePhase.objects.create(
167             name=name,
168             description=fake.paragraph(),
169             leaderboard_public=True,
170             is_public=True,
171             start_date=challenge.start_date,
172             end_date=challenge.end_date,
173             challenge=challenge,
174             test_annotation=SimpleUploadedFile(fake.file_name(extension="txt"), data, content_type="text/plain"),
175             codename="{}{}".format("phase", i + 1),
176         )
177         challenge_phases.append(challenge_phase)
178         print("Challenge Phase created with name: {} challenge: {}".format(name, challenge.title))
179     return challenge_phases
180 
181 
182 def create_leaderboard():
183     """
184     Creates Leaderboard schema and returns it.
185     """
186     schema = {
187         'labels': ['score', ],
188         'default_order_by': 'score',
189     }
190     leaderboard = Leaderboard.objects.create(
191         schema=schema
192     )
193     print("Leaderboard created")
194     return leaderboard
195 
196 
197 def create_dataset_splits(number_of_splits):
198     """
199     Creates dataset splits and returns it.
200     """
201     dataset_splits = []
202     for i in range(number_of_splits):
203         global DATASET_SPLIT_ITERATOR
204         name = "Split {}".format(DATASET_SPLIT_ITERATOR + 1)
205         codename = "{}{}".format('split', DATASET_SPLIT_ITERATOR + 1)
206         dataset_split = DatasetSplit.objects.create(
207             name=name,
208             codename=codename,
209         )
210         dataset_splits.append(dataset_split)
211         DATASET_SPLIT_ITERATOR += 1
212         print("Dataset Split created with name: {} codename: {}".format(name, codename))
213     return dataset_splits
214 
215 
216 def create_challenge_phase_splits(challenge_phase, leaderboard, dataset_split):
217     """
218     Creates a challenge phase split.
219     """
220     ChallengePhaseSplit.objects.create(
221         challenge_phase=challenge_phase,
222         leaderboard=leaderboard,
223         dataset_split=dataset_split,
224         visibility=ChallengePhaseSplit.PUBLIC
225     )
226     print("Challenge Phase Split created with challenge_phase: {} dataset_split: {}".format(challenge_phase.name,
227                                                                                             dataset_split.name))
228 
229 
230 def create_participant_team(user):
231     """
232     Creates participant team and returns it.
233     """
234     team_name = "{} Participant Team".format(fake.city())
235     team = ParticipantTeam.objects.create(
236         team_name=team_name,
237         created_by=user,
238     )
239     print("Participant Team created with team_name: {} created_by: {}".format(team_name, user.username))
240     Participant.objects.create(user=user, team=team, status="Self")
241     print("Participant created with user: {} team_name: {}".format(user.username, team_name))
242     return team
243 
244 
245 def run():
246     status = check_database()
247     if status is False:
248         print("Seeding aborted.")
249         return 0
250     print("Seeding...")
251     # Create superuser
252     create_user(is_admin=True)
253     # Create host user
254     host_user = create_user(is_admin=False, username="host")
255     # Create challenge host team with challenge host
256     challenge_host_team = create_challenge_host_team(user=host_user)
257     # Create challenge
258     create_challenges(number_of_challenges=NUMBER_OF_CHALLENGES, host_team=challenge_host_team)
259 
260     # Fetch all the created challenges
261     challenges = Challenge.objects.all()
262     for challenge in challenges:
263         # Create a leaderboard object for each challenge
264         leaderboard = create_leaderboard()
265         # Create Phases for a challenge
266         challenge_phases = create_challenge_phases(challenge, number_of_phases=NUMBER_OF_PHASES)
267         # Create Dataset Split for each Challenge
268         dataset_splits = create_dataset_splits(number_of_splits=NUMBER_OF_DATASET_SPLITS)
269         # Create Challenge Phase Split for each Phase and Dataset Split
270         for challenge_phase in challenge_phases:
271             for dataset_split in dataset_splits:
272                 create_challenge_phase_splits(challenge_phase, leaderboard, dataset_split)
273     participant_user = create_user(is_admin=False, username="participant")
274     create_participant_team(user=participant_user)
275     print('Database successfully seeded.')
276
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/apps/base/management/commands/seed.py b/apps/base/management/commands/seed.py
--- a/apps/base/management/commands/seed.py
+++ b/apps/base/management/commands/seed.py
@@ -5,6 +5,10 @@
 
     help = "Seeds the database with random but sensible values."
 
+    def add_arguments(self, parser):
+        parser.add_argument('-nc', nargs='?', default=1, type=int, help='Number of challenges.')
+
     def handle(self, *args, **options):
+        self.nc = options['nc']
         self.stdout.write(self.style.SUCCESS('Starting the database seeder. Hang on...'))
-        call_command('runscript', 'seed', '--settings', 'settings.dev')
+        call_command('runscript', 'seed', '--script-args', self.nc)
diff --git a/scripts/seed.py b/scripts/seed.py
--- a/scripts/seed.py
+++ b/scripts/seed.py
@@ -31,7 +31,7 @@
 def check_database():
     if len(EmailAddress.objects.all()) > 0:
         print("Are you sure you want to wipe the existing development database and reseed it? (Y/N)")
-        if raw_input().lower() == "y":
+        if settings.TEST or raw_input().lower() == "y":
             destroy_database()
         else:
             return False
@@ -102,7 +102,7 @@
     return team
 
 
-def create_challenges(number_of_challenges=3, host_team=None):
+def create_challenges(number_of_challenges, host_team=None):
     """
     Creates past challenge, on-going challenge and upcoming challenge.
     """
@@ -114,13 +114,13 @@
                              host_team
                              )
         elif (i % 3 == 1):
-            create_challenge("{} Challenge" % (fake.first_name()),
+            create_challenge("{} Challenge".format(fake.first_name()),
                              timezone.now() - timedelta(days=500),
                              timezone.now() - timedelta(days=100),
                              host_team
                              )
         elif (i % 3 == 2):
-            create_challenge("{} Challenge" % (fake.first_name()),
+            create_challenge("{} Challenge".format(fake.first_name()),
                              timezone.now() + timedelta(days=100),
                              timezone.now() + timedelta(days=500),
                              host_team
@@ -242,7 +242,8 @@
     return team
 
 
-def run():
+def run(*args):
+    NUMBER_OF_CHALLENGES = int(args[0])
     status = check_database()
     if status is False:
         print("Seeding aborted.")

{"golden_diff": "diff --git a/apps/base/management/commands/seed.py b/apps/base/management/commands/seed.py\n--- a/apps/base/management/commands/seed.py\n+++ b/apps/base/management/commands/seed.py\n@@ -5,6 +5,10 @@\n \n     help = \"Seeds the database with random but sensible values.\"\n \n+    def add_arguments(self, parser):\n+        parser.add_argument('-nc', nargs='?', default=1, type=int, help='Number of challenges.')\n+\n     def handle(self, *args, **options):\n+        self.nc = options['nc']\n         self.stdout.write(self.style.SUCCESS('Starting the database seeder. Hang on...'))\n-        call_command('runscript', 'seed', '--settings', 'settings.dev')\n+        call_command('runscript', 'seed', '--script-args', self.nc)\ndiff --git a/scripts/seed.py b/scripts/seed.py\n--- a/scripts/seed.py\n+++ b/scripts/seed.py\n@@ -31,7 +31,7 @@\n def check_database():\n     if len(EmailAddress.objects.all()) > 0:\n         print(\"Are you sure you want to wipe the existing development database and reseed it? (Y/N)\")\n-        if raw_input().lower() == \"y\":\n+        if settings.TEST or raw_input().lower() == \"y\":\n             destroy_database()\n         else:\n             return False\n@@ -102,7 +102,7 @@\n     return team\n \n \n-def create_challenges(number_of_challenges=3, host_team=None):\n+def create_challenges(number_of_challenges, host_team=None):\n     \"\"\"\n     Creates past challenge, on-going challenge and upcoming challenge.\n     \"\"\"\n@@ -114,13 +114,13 @@\n                              host_team\n                              )\n         elif (i % 3 == 1):\n-            create_challenge(\"{} Challenge\" % (fake.first_name()),\n+            create_challenge(\"{} Challenge\".format(fake.first_name()),\n                              timezone.now() - timedelta(days=500),\n                              timezone.now() - timedelta(days=100),\n                              host_team\n                              )\n         elif (i % 3 == 2):\n-            create_challenge(\"{} Challenge\" % (fake.first_name()),\n+            create_challenge(\"{} Challenge\".format(fake.first_name()),\n                              timezone.now() + timedelta(days=100),\n                              timezone.now() + timedelta(days=500),\n                              host_team\n@@ -242,7 +242,8 @@\n     return team\n \n \n-def run():\n+def run(*args):\n+    NUMBER_OF_CHALLENGES = int(args[0])\n     status = check_database()\n     if status is False:\n         print(\"Seeding aborted.\")\n", "issue": "Modify database seeding method\n## Deliverables\r\n\r\n- [ ] Modify the seed command to accept an argument `-nc` which denotes the number of challenges that a developer wants to create for testing.\r\n- [ ] Modify the seed script in such a way that it can be run multiple times (right now, if you run it once and then you try to run it again, then it throws an error). \n", "before_files": [{"content": "from django.core.management import BaseCommand, call_command\n\n\nclass Command(BaseCommand):\n\n    help = \"Seeds the database with random but sensible values.\"\n\n    def handle(self, *args, **options):\n        self.stdout.write(self.style.SUCCESS('Starting the database seeder. Hang on...'))\n        call_command('runscript', 'seed', '--settings', 'settings.dev')\n", "path": "apps/base/management/commands/seed.py"}, {"content": "# Command to run : python manage.py shell  < scripts/seed.py\nimport os\n\nfrom datetime import timedelta\n\nfrom django.conf import settings\nfrom django.contrib.auth.models import User\nfrom django.core.files.uploadedfile import SimpleUploadedFile\nfrom django.utils import timezone\n\nfrom allauth.account.models import EmailAddress\nfrom faker import Factory\n\nfrom challenges.models import Challenge, ChallengePhase, DatasetSplit, Leaderboard, ChallengePhaseSplit\nfrom hosts.models import ChallengeHostTeam, ChallengeHost\nfrom participants.models import Participant, ParticipantTeam\n\nfake = Factory.create()\n\nNUMBER_OF_CHALLENGES = 1\nNUMBER_OF_PHASES = 2\nNUMBER_OF_DATASET_SPLITS = 2\nDATASET_SPLIT_ITERATOR = 0\n\ntry:\n    xrange          # Python 2\nexcept NameError:\n    xrange = range  # Python 3\n\n\ndef check_database():\n    if len(EmailAddress.objects.all()) > 0:\n        print(\"Are you sure you want to wipe the existing development database and reseed it? (Y/N)\")\n        if raw_input().lower() == \"y\":\n            destroy_database()\n        else:\n            return False\n    else:\n        return True\n\n\ndef destroy_database():\n    print(\"Destroying existing database...\")\n    print(\"Destroying Participant objects...\")\n    Participant.objects.all().delete()\n    print(\"Destroying ParticipantTeam objects...\")\n    ParticipantTeam.objects.all().delete()\n    print(\"Destroying ChallengePhaseSplit objects...\")\n    ChallengePhaseSplit.objects.all().delete()\n    print(\"Destroying DatasetSplit objects...\")\n    DatasetSplit.objects.all().delete()\n    print(\"Destroying ChallengePhase objects...\")\n    ChallengePhase.objects.all().delete()\n    print(\"Destroying Leaderboard objects...\")\n    Leaderboard.objects.all().delete()\n    print(\"Destroying Challenge objects...\")\n    Challenge.objects.all().delete()\n    print(\"Destroying ChallengeHostTeam objects...\")\n    ChallengeHostTeam.objects.all().delete()\n    print(\"Destroying ChallengeHost objects...\")\n    ChallengeHost.objects.all().delete()\n    print(\"Destroying User objects...\")\n    User.objects.all().delete()\n    print(\"Destroying EmailAddress objects...\")\n    EmailAddress.objects.all().delete()\n    return True\n\n\ndef create_user(is_admin, username=\"\"):\n    \"\"\"\n    Creates superuser, participant user, host user and returns it.\n    \"\"\"\n    if is_admin:\n        username = \"admin\"\n        email = \"admin@example.com\"\n    else:\n        email = \"%s@example.com\" % (username)\n    user = User.objects.create_user(\n        email=email,\n        username=username,\n        password=\"password\",\n        is_staff=is_admin,\n        is_superuser=is_admin,\n    )\n    EmailAddress.objects.create(user=user, email=email, verified=True, primary=True)\n    print(\"{} was created with username: {} password: password\".format(\"Super user\" if is_admin else \"User\", username))\n    return user\n\n\ndef create_challenge_host_team(user):\n    \"\"\"\n    Creates challenge host team and returns it.\n    \"\"\"\n    team_name = \"{} Host Team\".format(fake.city())\n    team = ChallengeHostTeam.objects.create(\n        team_name=team_name,\n        created_by=user,\n    )\n    print(\"Challenge Host Team created with team_name: {} created_by: {}\".format(team_name, user.username))\n    ChallengeHost.objects.create(user=user, team_name=team, status=ChallengeHost.SELF, permissions=ChallengeHost.ADMIN)\n    print(\"Challenge Host created with user: {} team_name: {}\".format(user.username, team_name))\n    return team\n\n\ndef create_challenges(number_of_challenges=3, host_team=None):\n    \"\"\"\n    Creates past challenge, on-going challenge and upcoming challenge.\n    \"\"\"\n    for i in xrange(number_of_challenges):\n        if (i % 3 == 0):\n            create_challenge(\"{} Challenge\".format(fake.first_name()),\n                             timezone.now() - timedelta(days=100),\n                             timezone.now() + timedelta(days=500),\n                             host_team\n                             )\n        elif (i % 3 == 1):\n            create_challenge(\"{} Challenge\" % (fake.first_name()),\n                             timezone.now() - timedelta(days=500),\n                             timezone.now() - timedelta(days=100),\n                             host_team\n                             )\n        elif (i % 3 == 2):\n            create_challenge(\"{} Challenge\" % (fake.first_name()),\n                             timezone.now() + timedelta(days=100),\n                             timezone.now() + timedelta(days=500),\n                             host_team\n                             )\n\n\ndef create_challenge(title, start_date, end_date, host_team):\n    \"\"\"\n    Creates a challenge.\n    \"\"\"\n    evaluation_script = open(os.path.join(settings.BASE_DIR, 'examples', 'example1', 'string_matching.zip'), 'rb')\n    Challenge.objects.create(\n        title=title,\n        short_description=fake.paragraph(),\n        description=fake.paragraph(),\n        terms_and_conditions=fake.paragraph(),\n        submission_guidelines=fake.paragraph(),\n        evaluation_details=fake.paragraph(),\n        evaluation_script=SimpleUploadedFile(evaluation_script.name, evaluation_script.read()),\n        approved_by_admin=True,\n        creator=host_team,\n        published=True,\n        enable_forum=True,\n        anonymous_leaderboard=False,\n        start_date=start_date,\n        end_date=end_date,\n    )\n    print(\"Challenge created with title: {} creator: {} start_date: {} end_date: {}\".format(title,\n                                                                                            host_team.team_name,\n                                                                                            start_date, end_date))\n\n\ndef create_challenge_phases(challenge, number_of_phases=1):\n    \"\"\"\n    Creates challenge phases for the created challenges and returns it.\n    \"\"\"\n    challenge_phases = []\n    for i in range(number_of_phases):\n        name = \"{} Phase\".format(fake.first_name())\n        with open(os.path.join(settings.BASE_DIR, 'examples', 'example1', 'test_annotation.txt'), 'rb') as data_file:\n            data = data_file.read()\n        data = data or None\n        challenge_phase = ChallengePhase.objects.create(\n            name=name,\n            description=fake.paragraph(),\n            leaderboard_public=True,\n            is_public=True,\n            start_date=challenge.start_date,\n            end_date=challenge.end_date,\n            challenge=challenge,\n            test_annotation=SimpleUploadedFile(fake.file_name(extension=\"txt\"), data, content_type=\"text/plain\"),\n            codename=\"{}{}\".format(\"phase\", i + 1),\n        )\n        challenge_phases.append(challenge_phase)\n        print(\"Challenge Phase created with name: {} challenge: {}\".format(name, challenge.title))\n    return challenge_phases\n\n\ndef create_leaderboard():\n    \"\"\"\n    Creates Leaderboard schema and returns it.\n    \"\"\"\n    schema = {\n        'labels': ['score', ],\n        'default_order_by': 'score',\n    }\n    leaderboard = Leaderboard.objects.create(\n        schema=schema\n    )\n    print(\"Leaderboard created\")\n    return leaderboard\n\n\ndef create_dataset_splits(number_of_splits):\n    \"\"\"\n    Creates dataset splits and returns it.\n    \"\"\"\n    dataset_splits = []\n    for i in range(number_of_splits):\n        global DATASET_SPLIT_ITERATOR\n        name = \"Split {}\".format(DATASET_SPLIT_ITERATOR + 1)\n        codename = \"{}{}\".format('split', DATASET_SPLIT_ITERATOR + 1)\n        dataset_split = DatasetSplit.objects.create(\n            name=name,\n            codename=codename,\n        )\n        dataset_splits.append(dataset_split)\n        DATASET_SPLIT_ITERATOR += 1\n        print(\"Dataset Split created with name: {} codename: {}\".format(name, codename))\n    return dataset_splits\n\n\ndef create_challenge_phase_splits(challenge_phase, leaderboard, dataset_split):\n    \"\"\"\n    Creates a challenge phase split.\n    \"\"\"\n    ChallengePhaseSplit.objects.create(\n        challenge_phase=challenge_phase,\n        leaderboard=leaderboard,\n        dataset_split=dataset_split,\n        visibility=ChallengePhaseSplit.PUBLIC\n    )\n    print(\"Challenge Phase Split created with challenge_phase: {} dataset_split: {}\".format(challenge_phase.name,\n                                                                                            dataset_split.name))\n\n\ndef create_participant_team(user):\n    \"\"\"\n    Creates participant team and returns it.\n    \"\"\"\n    team_name = \"{} Participant Team\".format(fake.city())\n    team = ParticipantTeam.objects.create(\n        team_name=team_name,\n        created_by=user,\n    )\n    print(\"Participant Team created with team_name: {} created_by: {}\".format(team_name, user.username))\n    Participant.objects.create(user=user, team=team, status=\"Self\")\n    print(\"Participant created with user: {} team_name: {}\".format(user.username, team_name))\n    return team\n\n\ndef run():\n    status = check_database()\n    if status is False:\n        print(\"Seeding aborted.\")\n        return 0\n    print(\"Seeding...\")\n    # Create superuser\n    create_user(is_admin=True)\n    # Create host user\n    host_user = create_user(is_admin=False, username=\"host\")\n    # Create challenge host team with challenge host\n    challenge_host_team = create_challenge_host_team(user=host_user)\n    # Create challenge\n    create_challenges(number_of_challenges=NUMBER_OF_CHALLENGES, host_team=challenge_host_team)\n\n    # Fetch all the created challenges\n    challenges = Challenge.objects.all()\n    for challenge in challenges:\n        # Create a leaderboard object for each challenge\n        leaderboard = create_leaderboard()\n        # Create Phases for a challenge\n        challenge_phases = create_challenge_phases(challenge, number_of_phases=NUMBER_OF_PHASES)\n        # Create Dataset Split for each Challenge\n        dataset_splits = create_dataset_splits(number_of_splits=NUMBER_OF_DATASET_SPLITS)\n        # Create Challenge Phase Split for each Phase and Dataset Split\n        for challenge_phase in challenge_phases:\n            for dataset_split in dataset_splits:\n                create_challenge_phase_splits(challenge_phase, leaderboard, dataset_split)\n    participant_user = create_user(is_admin=False, username=\"participant\")\n    create_participant_team(user=participant_user)\n    print('Database successfully seeded.')\n", "path": "scripts/seed.py"}], "after_files": [{"content": "from django.core.management import BaseCommand, call_command\n\n\nclass Command(BaseCommand):\n\n    help = \"Seeds the database with random but sensible values.\"\n\n    def add_arguments(self, parser):\n        parser.add_argument('-nc', nargs='?', default=1, type=int, help='Number of challenges.')\n\n    def handle(self, *args, **options):\n        self.nc = options['nc']\n        self.stdout.write(self.style.SUCCESS('Starting the database seeder. Hang on...'))\n        call_command('runscript', 'seed', '--script-args', self.nc)\n", "path": "apps/base/management/commands/seed.py"}, {"content": "# Command to run : python manage.py shell  < scripts/seed.py\nimport os\n\nfrom datetime import timedelta\n\nfrom django.conf import settings\nfrom django.contrib.auth.models import User\nfrom django.core.files.uploadedfile import SimpleUploadedFile\nfrom django.utils import timezone\n\nfrom allauth.account.models import EmailAddress\nfrom faker import Factory\n\nfrom challenges.models import Challenge, ChallengePhase, DatasetSplit, Leaderboard, ChallengePhaseSplit\nfrom hosts.models import ChallengeHostTeam, ChallengeHost\nfrom participants.models import Participant, ParticipantTeam\n\nfake = Factory.create()\n\nNUMBER_OF_CHALLENGES = 1\nNUMBER_OF_PHASES = 2\nNUMBER_OF_DATASET_SPLITS = 2\nDATASET_SPLIT_ITERATOR = 0\n\ntry:\n    xrange          # Python 2\nexcept NameError:\n    xrange = range  # Python 3\n\n\ndef check_database():\n    if len(EmailAddress.objects.all()) > 0:\n        print(\"Are you sure you want to wipe the existing development database and reseed it? (Y/N)\")\n        if settings.TEST or raw_input().lower() == \"y\":\n            destroy_database()\n        else:\n            return False\n    else:\n        return True\n\n\ndef destroy_database():\n    print(\"Destroying existing database...\")\n    print(\"Destroying Participant objects...\")\n    Participant.objects.all().delete()\n    print(\"Destroying ParticipantTeam objects...\")\n    ParticipantTeam.objects.all().delete()\n    print(\"Destroying ChallengePhaseSplit objects...\")\n    ChallengePhaseSplit.objects.all().delete()\n    print(\"Destroying DatasetSplit objects...\")\n    DatasetSplit.objects.all().delete()\n    print(\"Destroying ChallengePhase objects...\")\n    ChallengePhase.objects.all().delete()\n    print(\"Destroying Leaderboard objects...\")\n    Leaderboard.objects.all().delete()\n    print(\"Destroying Challenge objects...\")\n    Challenge.objects.all().delete()\n    print(\"Destroying ChallengeHostTeam objects...\")\n    ChallengeHostTeam.objects.all().delete()\n    print(\"Destroying ChallengeHost objects...\")\n    ChallengeHost.objects.all().delete()\n    print(\"Destroying User objects...\")\n    User.objects.all().delete()\n    print(\"Destroying EmailAddress objects...\")\n    EmailAddress.objects.all().delete()\n    return True\n\n\ndef create_user(is_admin, username=\"\"):\n    \"\"\"\n    Creates superuser, participant user, host user and returns it.\n    \"\"\"\n    if is_admin:\n        username = \"admin\"\n        email = \"admin@example.com\"\n    else:\n        email = \"%s@example.com\" % (username)\n    user = User.objects.create_user(\n        email=email,\n        username=username,\n        password=\"password\",\n        is_staff=is_admin,\n        is_superuser=is_admin,\n    )\n    EmailAddress.objects.create(user=user, email=email, verified=True, primary=True)\n    print(\"{} was created with username: {} password: password\".format(\"Super user\" if is_admin else \"User\", username))\n    return user\n\n\ndef create_challenge_host_team(user):\n    \"\"\"\n    Creates challenge host team and returns it.\n    \"\"\"\n    team_name = \"{} Host Team\".format(fake.city())\n    team = ChallengeHostTeam.objects.create(\n        team_name=team_name,\n        created_by=user,\n    )\n    print(\"Challenge Host Team created with team_name: {} created_by: {}\".format(team_name, user.username))\n    ChallengeHost.objects.create(user=user, team_name=team, status=ChallengeHost.SELF, permissions=ChallengeHost.ADMIN)\n    print(\"Challenge Host created with user: {} team_name: {}\".format(user.username, team_name))\n    return team\n\n\ndef create_challenges(number_of_challenges, host_team=None):\n    \"\"\"\n    Creates past challenge, on-going challenge and upcoming challenge.\n    \"\"\"\n    for i in xrange(number_of_challenges):\n        if (i % 3 == 0):\n            create_challenge(\"{} Challenge\".format(fake.first_name()),\n                             timezone.now() - timedelta(days=100),\n                             timezone.now() + timedelta(days=500),\n                             host_team\n                             )\n        elif (i % 3 == 1):\n            create_challenge(\"{} Challenge\".format(fake.first_name()),\n                             timezone.now() - timedelta(days=500),\n                             timezone.now() - timedelta(days=100),\n                             host_team\n                             )\n        elif (i % 3 == 2):\n            create_challenge(\"{} Challenge\".format(fake.first_name()),\n                             timezone.now() + timedelta(days=100),\n                             timezone.now() + timedelta(days=500),\n                             host_team\n                             )\n\n\ndef create_challenge(title, start_date, end_date, host_team):\n    \"\"\"\n    Creates a challenge.\n    \"\"\"\n    evaluation_script = open(os.path.join(settings.BASE_DIR, 'examples', 'example1', 'string_matching.zip'), 'rb')\n    Challenge.objects.create(\n        title=title,\n        short_description=fake.paragraph(),\n        description=fake.paragraph(),\n        terms_and_conditions=fake.paragraph(),\n        submission_guidelines=fake.paragraph(),\n        evaluation_details=fake.paragraph(),\n        evaluation_script=SimpleUploadedFile(evaluation_script.name, evaluation_script.read()),\n        approved_by_admin=True,\n        creator=host_team,\n        published=True,\n        enable_forum=True,\n        anonymous_leaderboard=False,\n        start_date=start_date,\n        end_date=end_date,\n    )\n    print(\"Challenge created with title: {} creator: {} start_date: {} end_date: {}\".format(title,\n                                                                                            host_team.team_name,\n                                                                                            start_date, end_date))\n\n\ndef create_challenge_phases(challenge, number_of_phases=1):\n    \"\"\"\n    Creates challenge phases for the created challenges and returns it.\n    \"\"\"\n    challenge_phases = []\n    for i in range(number_of_phases):\n        name = \"{} Phase\".format(fake.first_name())\n        with open(os.path.join(settings.BASE_DIR, 'examples', 'example1', 'test_annotation.txt'), 'rb') as data_file:\n            data = data_file.read()\n        data = data or None\n        challenge_phase = ChallengePhase.objects.create(\n            name=name,\n            description=fake.paragraph(),\n            leaderboard_public=True,\n            is_public=True,\n            start_date=challenge.start_date,\n            end_date=challenge.end_date,\n            challenge=challenge,\n            test_annotation=SimpleUploadedFile(fake.file_name(extension=\"txt\"), data, content_type=\"text/plain\"),\n            codename=\"{}{}\".format(\"phase\", i + 1),\n        )\n        challenge_phases.append(challenge_phase)\n        print(\"Challenge Phase created with name: {} challenge: {}\".format(name, challenge.title))\n    return challenge_phases\n\n\ndef create_leaderboard():\n    \"\"\"\n    Creates Leaderboard schema and returns it.\n    \"\"\"\n    schema = {\n        'labels': ['score', ],\n        'default_order_by': 'score',\n    }\n    leaderboard = Leaderboard.objects.create(\n        schema=schema\n    )\n    print(\"Leaderboard created\")\n    return leaderboard\n\n\ndef create_dataset_splits(number_of_splits):\n    \"\"\"\n    Creates dataset splits and returns it.\n    \"\"\"\n    dataset_splits = []\n    for i in range(number_of_splits):\n        global DATASET_SPLIT_ITERATOR\n        name = \"Split {}\".format(DATASET_SPLIT_ITERATOR + 1)\n        codename = \"{}{}\".format('split', DATASET_SPLIT_ITERATOR + 1)\n        dataset_split = DatasetSplit.objects.create(\n            name=name,\n            codename=codename,\n        )\n        dataset_splits.append(dataset_split)\n        DATASET_SPLIT_ITERATOR += 1\n        print(\"Dataset Split created with name: {} codename: {}\".format(name, codename))\n    return dataset_splits\n\n\ndef create_challenge_phase_splits(challenge_phase, leaderboard, dataset_split):\n    \"\"\"\n    Creates a challenge phase split.\n    \"\"\"\n    ChallengePhaseSplit.objects.create(\n        challenge_phase=challenge_phase,\n        leaderboard=leaderboard,\n        dataset_split=dataset_split,\n        visibility=ChallengePhaseSplit.PUBLIC\n    )\n    print(\"Challenge Phase Split created with challenge_phase: {} dataset_split: {}\".format(challenge_phase.name,\n                                                                                            dataset_split.name))\n\n\ndef create_participant_team(user):\n    \"\"\"\n    Creates participant team and returns it.\n    \"\"\"\n    team_name = \"{} Participant Team\".format(fake.city())\n    team = ParticipantTeam.objects.create(\n        team_name=team_name,\n        created_by=user,\n    )\n    print(\"Participant Team created with team_name: {} created_by: {}\".format(team_name, user.username))\n    Participant.objects.create(user=user, team=team, status=\"Self\")\n    print(\"Participant created with user: {} team_name: {}\".format(user.username, team_name))\n    return team\n\n\ndef run(*args):\n    NUMBER_OF_CHALLENGES = int(args[0])\n    status = check_database()\n    if status is False:\n        print(\"Seeding aborted.\")\n        return 0\n    print(\"Seeding...\")\n    # Create superuser\n    create_user(is_admin=True)\n    # Create host user\n    host_user = create_user(is_admin=False, username=\"host\")\n    # Create challenge host team with challenge host\n    challenge_host_team = create_challenge_host_team(user=host_user)\n    # Create challenge\n    create_challenges(number_of_challenges=NUMBER_OF_CHALLENGES, host_team=challenge_host_team)\n\n    # Fetch all the created challenges\n    challenges = Challenge.objects.all()\n    for challenge in challenges:\n        # Create a leaderboard object for each challenge\n        leaderboard = create_leaderboard()\n        # Create Phases for a challenge\n        challenge_phases = create_challenge_phases(challenge, number_of_phases=NUMBER_OF_PHASES)\n        # Create Dataset Split for each Challenge\n        dataset_splits = create_dataset_splits(number_of_splits=NUMBER_OF_DATASET_SPLITS)\n        # Create Challenge Phase Split for each Phase and Dataset Split\n        for challenge_phase in challenge_phases:\n            for dataset_split in dataset_splits:\n                create_challenge_phase_splits(challenge_phase, leaderboard, dataset_split)\n    participant_user = create_user(is_admin=False, username=\"participant\")\n    create_participant_team(user=participant_user)\n    print('Database successfully seeded.')\n", "path": "scripts/seed.py"}]}