Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to require participants to complete their profile before participating #2416

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/challenges/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ChallengeAdmin(ImportExportTimeStampedAdmin):
"end_date",
"creator",
"published",
"is_profile_required",
"is_registration_open",
"enable_forum",
"anonymous_leaderboard",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-07-30 19:18
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('challenges', '0057_add_task_def_arn_and_workers_field_to_challenge_model'),
]

operations = [
migrations.AddField(
model_name='challenge',
name='is_profile_required',
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions apps/challenges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self, *args, **kwargs):
published = models.BooleanField(
default=False, verbose_name="Publicly Available", db_index=True
)
is_profile_required = models.BooleanField(default=False)
is_registration_open = models.BooleanField(default=True)
enable_forum = models.BooleanField(default=True)
forum_url = models.URLField(max_length=100, blank=True, null=True)
Expand Down
2 changes: 2 additions & 0 deletions apps/challenges/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Meta:
"end_date",
"creator",
"published",
"is_profile_required",
"is_registration_open",
"enable_forum",
"anonymous_leaderboard",
Expand Down Expand Up @@ -180,6 +181,7 @@ class Meta:
"creator",
"evaluation_details",
"published",
"is_profile_required",
"is_registration_open",
"enable_forum",
"anonymous_leaderboard",
Expand Down
22 changes: 19 additions & 3 deletions apps/challenges/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,25 @@ def add_participant_team_to_challenge(
"participant_team_id": int(participant_team_pk),
}
return Response(response_data, status=status.HTTP_200_OK)
else:
challenge.participant_teams.add(participant_team)
return Response(status=status.HTTP_201_CREATED)

if challenge.is_profile_required:
participants = Participant.objects.filter(team=participant_team)
for participant in participants:
if (
participant.user.first_name == "" or participant.user.last_name == ""
or participant.user.profile.affiliation == ""
or participant.user.profile.google_scholar_url == ""
):
response_data = {
"error": "Each participant of a team must complete their profile"
" in order to participate in this challenge.",
"is_profile_complete": False
}
return Response(
response_data, status=status.HTTP_406_NOT_ACCEPTABLE
)
challenge.participant_teams.add(participant_team)
return Response(status=status.HTTP_201_CREATED)


@api_view(["POST"])
Expand Down
2 changes: 2 additions & 0 deletions docs/source/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Following fields are required (and can be customized) in the [`challenge_config.

- **image**: Logo of the challenge (use a relative path for the logo in the zip configuration, e.g. `images/logo/challenge_logo.jpg`). **Note**: The image must be in jpg, jpeg or png format.

- **is_profile_required**: True/False (boolean field that require participants to complete their profile before participating in challenge)

- **submission_guidelines**: Submission guidelines of the challenge (use a relative path for the HTML file, e.g. `challenge_details/submission_guidelines.html`)

- **evaluation_script**: Python script which will decide how to evaluate submissions in different phases (path of the evaluation script file or folder relative to this YAML file. For e.g. `evaluation_script/`)
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/challenges/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def setUp(self):
submission_guidelines="Submission guidelines for test challenge",
creator=self.challenge_host_team,
published=False,
is_profile_required=False,
is_registration_open=True,
enable_forum=True,
anonymous_leaderboard=False,
Expand Down Expand Up @@ -153,6 +154,7 @@ def test_get_challenge(self):
"team_url": self.challenge.creator.team_url,
},
"published": self.challenge.published,
"is_profile_required": self.challenge.is_profile_required,
"is_registration_open": self.challenge.is_registration_open,
"enable_forum": self.challenge.enable_forum,
"leaderboard_description": self.challenge.leaderboard_description,
Expand Down Expand Up @@ -262,6 +264,7 @@ def test_get_particular_challenge(self):
"team_url": self.challenge.creator.team_url,
},
"published": self.challenge.published,
"is_profile_required": self.challenge.is_profile_required,
"is_registration_open": self.challenge.is_registration_open,
"enable_forum": self.challenge.enable_forum,
"leaderboard_description": self.challenge.leaderboard_description,
Expand Down Expand Up @@ -332,6 +335,7 @@ def test_update_challenge_when_user_is_its_creator(self):
"team_url": self.challenge.creator.team_url,
},
"published": self.challenge.published,
"is_profile_required": self.challenge.is_profile_required,
"is_registration_open": self.challenge.is_registration_open,
"enable_forum": self.challenge.enable_forum,
"leaderboard_description": self.challenge.leaderboard_description,
Expand Down Expand Up @@ -423,6 +427,7 @@ def test_particular_challenge_partial_update(self):
"team_url": self.challenge.creator.team_url,
},
"published": self.challenge.published,
"is_profile_required": self.challenge.is_profile_required,
"is_registration_open": self.challenge.is_registration_open,
"enable_forum": self.challenge.enable_forum,
"leaderboard_description": self.challenge.leaderboard_description,
Expand Down Expand Up @@ -470,6 +475,7 @@ def test_particular_challenge_update(self):
"team_url": self.challenge.creator.team_url,
},
"published": self.challenge.published,
"is_profile_required": self.challenge.is_profile_required,
"is_registration_open": self.challenge.is_registration_open,
"enable_forum": self.challenge.enable_forum,
"leaderboard_description": self.challenge.leaderboard_description,
Expand Down Expand Up @@ -894,6 +900,7 @@ def setUp(self):
submission_guidelines="Submission guidelines for test challenge 2",
creator=self.challenge_host_team,
published=True,
is_profile_required=False,
is_registration_open=True,
enable_forum=True,
approved_by_admin=True,
Expand All @@ -911,6 +918,7 @@ def setUp(self):
submission_guidelines="Submission guidelines for test challenge 3",
creator=self.challenge_host_team,
published=True,
is_profile_required=False,
is_registration_open=True,
enable_forum=True,
approved_by_admin=True,
Expand All @@ -929,6 +937,7 @@ def setUp(self):
submission_guidelines="Submission guidelines for test challenge 4",
creator=self.challenge_host_team,
published=True,
is_profile_required=False,
is_registration_open=True,
enable_forum=True,
approved_by_admin=True,
Expand Down Expand Up @@ -980,6 +989,7 @@ def test_get_past_challenges(self):
"team_url": self.challenge3.creator.team_url,
},
"published": self.challenge3.published,
"is_profile_required": self.challenge3.is_profile_required,
"is_registration_open": self.challenge3.is_registration_open,
"enable_forum": self.challenge3.enable_forum,
"leaderboard_description": self.challenge3.leaderboard_description,
Expand Down Expand Up @@ -1029,6 +1039,7 @@ def test_get_present_challenges(self):
"team_url": self.challenge2.creator.team_url,
},
"published": self.challenge2.published,
"is_profile_required": self.challenge2.is_profile_required,
"is_registration_open": self.challenge2.is_registration_open,
"enable_forum": self.challenge2.enable_forum,
"leaderboard_description": self.challenge2.leaderboard_description,
Expand Down Expand Up @@ -1078,6 +1089,7 @@ def test_get_future_challenges(self):
"team_url": self.challenge4.creator.team_url,
},
"published": self.challenge4.published,
"is_profile_required": self.challenge4.is_profile_required,
"is_registration_open": self.challenge4.is_registration_open,
"enable_forum": self.challenge4.enable_forum,
"leaderboard_description": self.challenge4.leaderboard_description,
Expand Down Expand Up @@ -1126,6 +1138,7 @@ def test_get_all_challenges(self):
"team_url": self.challenge4.creator.team_url,
},
"published": self.challenge4.published,
"is_profile_required": self.challenge4.is_profile_required,
"is_registration_open": self.challenge4.is_registration_open,
"enable_forum": self.challenge4.enable_forum,
"leaderboard_description": self.challenge4.leaderboard_description,
Expand Down Expand Up @@ -1163,6 +1176,7 @@ def test_get_all_challenges(self):
"team_url": self.challenge3.creator.team_url,
},
"published": self.challenge3.published,
"is_profile_required": self.challenge3.is_profile_required,
"is_registration_open": self.challenge3.is_registration_open,
"enable_forum": self.challenge3.enable_forum,
"leaderboard_description": self.challenge3.leaderboard_description,
Expand Down Expand Up @@ -1200,6 +1214,7 @@ def test_get_all_challenges(self):
"team_url": self.challenge2.creator.team_url,
},
"published": self.challenge2.published,
"is_profile_required": self.challenge2.is_profile_required,
"is_registration_open": self.challenge2.is_registration_open,
"enable_forum": self.challenge2.enable_forum,
"leaderboard_description": self.challenge2.leaderboard_description,
Expand Down Expand Up @@ -1264,6 +1279,7 @@ def setUp(self):
submission_guidelines="Submission guidelines for test challenge 3",
creator=self.challenge_host_team,
published=True,
is_profile_required=False,
is_registration_open=True,
enable_forum=True,
approved_by_admin=True,
Expand Down Expand Up @@ -1298,6 +1314,7 @@ def test_get_featured_challenges(self):
"team_url": self.challenge3.creator.team_url,
},
"published": self.challenge3.published,
"is_profile_required": self.challenge3.is_profile_required,
"is_registration_open": self.challenge3.is_registration_open,
"enable_forum": self.challenge3.enable_forum,
"leaderboard_description": self.challenge3.leaderboard_description,
Expand Down Expand Up @@ -1344,6 +1361,7 @@ def setUp(self):
submission_guidelines="Submission guidelines for test challenge 3",
creator=self.challenge_host_team,
published=False,
is_profile_required=False,
is_registration_open=True,
enable_forum=True,
anonymous_leaderboard=False,
Expand All @@ -1360,6 +1378,7 @@ def setUp(self):
submission_guidelines="Submission guidelines for test challenge 4",
creator=self.challenge_host_team,
published=True,
is_profile_required=False,
is_registration_open=True,
enable_forum=True,
leaderboard_description="Curabitur nec placerat libero.",
Expand Down Expand Up @@ -1423,6 +1442,7 @@ def test_get_challenge_by_pk_when_user_is_challenge_host(self):
"team_url": self.challenge3.creator.team_url,
},
"published": self.challenge3.published,
"is_profile_required": self.challenge3.is_profile_required,
"is_registration_open": self.challenge3.is_registration_open,
"enable_forum": self.challenge3.enable_forum,
"leaderboard_description": self.challenge3.leaderboard_description,
Expand Down Expand Up @@ -1484,6 +1504,7 @@ def test_get_challenge_by_pk_when_user_is_participant(self):
"team_url": self.challenge4.creator.team_url,
},
"published": self.challenge4.published,
"is_profile_required": self.challenge4.is_profile_required,
"is_registration_open": self.challenge4.is_registration_open,
"enable_forum": self.challenge4.enable_forum,
"leaderboard_description": self.challenge4.leaderboard_description,
Expand Down Expand Up @@ -1538,6 +1559,7 @@ def setUp(self):
submission_guidelines="Submission guidelines for test challenge",
creator=self.challenge_host_team,
published=True,
is_profile_required=False,
is_registration_open=True,
enable_forum=True,
leaderboard_description=None,
Expand All @@ -1555,6 +1577,7 @@ def setUp(self):
submission_guidelines="Submission guidelines for some test challenge",
creator=self.challenge_host_team2,
published=True,
is_profile_required=False,
is_registration_open=True,
enable_forum=True,
anonymous_leaderboard=False,
Expand Down Expand Up @@ -1601,6 +1624,7 @@ def test_get_challenge_when_host_team_is_given(self):
"team_url": self.challenge2.creator.team_url,
},
"published": self.challenge2.published,
"is_profile_required": self.challenge2.is_profile_required,
"is_registration_open": self.challenge2.is_registration_open,
"enable_forum": self.challenge2.enable_forum,
"leaderboard_description": self.challenge2.leaderboard_description,
Expand Down Expand Up @@ -1650,6 +1674,7 @@ def test_get_challenge_when_participant_team_is_given(self):
"team_url": self.challenge2.creator.team_url,
},
"published": self.challenge2.published,
"is_profile_required": self.challenge2.is_profile_required,
"is_registration_open": self.challenge2.is_registration_open,
"enable_forum": self.challenge2.enable_forum,
"leaderboard_description": self.challenge2.leaderboard_description,
Expand Down Expand Up @@ -1699,6 +1724,7 @@ def test_get_challenge_when_mode_is_participant(self):
"team_url": self.challenge2.creator.team_url,
},
"published": self.challenge2.published,
"is_profile_required": self.challenge2.is_profile_required,
"is_registration_open": self.challenge2.is_registration_open,
"enable_forum": self.challenge2.enable_forum,
"leaderboard_description": self.challenge2.leaderboard_description,
Expand Down Expand Up @@ -1746,6 +1772,7 @@ def test_get_challenge_when_mode_is_host(self):
"team_url": self.challenge.creator.team_url,
},
"published": self.challenge.published,
"is_profile_required": self.challenge.is_profile_required,
"is_registration_open": self.challenge.is_registration_open,
"enable_forum": self.challenge.enable_forum,
"leaderboard_description": self.challenge.leaderboard_description,
Expand Down Expand Up @@ -1783,6 +1810,7 @@ def test_get_challenge_when_mode_is_host(self):
"team_url": self.challenge2.creator.team_url,
},
"published": self.challenge2.published,
"is_profile_required": self.challenge2.is_profile_required,
"is_registration_open": self.challenge2.is_registration_open,
"enable_forum": self.challenge2.enable_forum,
"leaderboard_description": self.challenge2.leaderboard_description,
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/participants/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ def setUp(self):
submission_guidelines="Submission guidelines for test challenge 1",
creator=self.challenge_host_team,
published=False,
is_profile_required=False,
is_registration_open=True,
enable_forum=True,
leaderboard_description="Lorem ipsum dolor sit amet, consectetur adipiscing elit",
Expand Down Expand Up @@ -640,6 +641,7 @@ def test_get_teams_and_corresponding_challenges_for_a_participant(self):
"team_url": self.challenge_host_team.team_url,
},
"published": self.challenge1.published,
"is_profile_required": self.challenge1.is_profile_required,
"is_registration_open": self.challenge1.is_registration_open,
"enable_forum": self.challenge1.enable_forum,
"leaderboard_description": self.challenge1.leaderboard_description,
Expand Down Expand Up @@ -704,6 +706,7 @@ def test_get_participant_team_challenge_list(self):
"team_url": self.challenge_host_team.team_url,
},
"published": self.challenge1.published,
"is_profile_required": self.challenge1.is_profile_required,
"is_registration_open": self.challenge1.is_registration_open,
"enable_forum": self.challenge1.enable_forum,
"leaderboard_description": self.challenge1.leaderboard_description,
Expand Down