def create_challenge_phases(challenge, number_of_phases=1):
"""
Creates challenge phases for the created challenges and returns it.
"""
challenge_phases = []
for i in range(number_of_phases):
name = "{} Phase".format(fake.first_name())
with open(os.path.join(settings.BASE_DIR, 'examples', 'example1', 'test_annotation.txt'), 'rb') as data_file:
data = data_file.read()
data = data or None
challenge_phase = ChallengePhase.objects.create(
name=name,
description=fake.paragraph(),
leaderboard_public=True,
is_public=True,
start_date=challenge.start_date,
end_date=challenge.end_date,
challenge=challenge,
test_annotation=SimpleUploadedFile(fake.file_name(extension="txt"), data, content_type="text/plain"),
codename="{}{}".format("phase", i + 1),
)
challenge_phases.append(challenge_phase)
print("Challenge Phase created with name: {} challenge: {}".format(name, challenge.title))
return challenge_phases
评论列表
文章目录