We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Update seed script to add broker url in challenge
## Current Behaviour:

Currently, when the challenge is created using the seed script, the `queue` field is not populated.

## Expected Behaviour:
When the seed script is run, the `queue` field must be populated with the random string of 75 characters in length.

--- END ISSUE ---

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

{"golden_diff": "diff --git a/scripts/seed.py b/scripts/seed.py\n--- a/scripts/seed.py\n+++ b/scripts/seed.py\n@@ -1,5 +1,7 @@\n # Command to run : python manage.py shell  < scripts/seed.py\n import os\n+import random\n+import string\n \n from datetime import timedelta\n \n@@ -134,6 +136,7 @@\n     \"\"\"\n     evaluation_script = open(\n         os.path.join(settings.BASE_DIR, 'examples', 'example1', 'sample_evaluation_script.zip'), 'rb')\n+    queue = ''.join(random.choice(string.ascii_letters) for _ in range(75))\n     Challenge.objects.create(\n         title=title,\n         short_description=fake.paragraph(),\n@@ -149,6 +152,7 @@\n         anonymous_leaderboard=False,\n         start_date=start_date,\n         end_date=end_date,\n+        queue=queue,\n     )\n     print(\"Challenge created with title: {} creator: {} start_date: {} end_date: {}\".format(title,\n                                                                                             host_team.team_name,\n", "issue": "Update seed script to add broker url in challenge\n## Current Behaviour:\r\n\r\nCurrently, when the challenge is created using the seed script, the `queue` field is not populated.\r\n\r\n## Expected Behaviour:\r\nWhen the seed script is run, the `queue` field must be populated with the random string of 75 characters in length.\n", "before_files": [{"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 input().lower() == \"y\":\n            destroy_database()\n            return True\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(\n        os.path.join(settings.BASE_DIR, 'examples', 'example1', 'sample_evaluation_script.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"}], "after_files": [{"content": "# Command to run : python manage.py shell  < scripts/seed.py\nimport os\nimport random\nimport string\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 input().lower() == \"y\":\n            destroy_database()\n            return True\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(\n        os.path.join(settings.BASE_DIR, 'examples', 'example1', 'sample_evaluation_script.zip'), 'rb')\n    queue = ''.join(random.choice(string.ascii_letters) for _ in range(75))\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        queue=queue,\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"}]}