Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 25 additions & 13 deletions src/apps/api/serializers/leaderboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,15 @@ def get_submissions(self, instance):
primary_col = instance.columns.get(index=instance.primary_index)
# Order first by primary column. Then order by other columns after for tie breakers.
ordering = [f'{"-" if primary_col.sorting == "desc" else ""}primary_col']
submissions = Submission.objects.filter(leaderboard=instance, is_specific_task_re_run=False)\
.select_related('owner').prefetch_related('scores')\
submissions = (
Submission.objects.filter(
leaderboard=instance,
is_specific_task_re_run=False
)
.select_related('owner')
.prefetch_related('scores')
.annotate(primary_col=Sum('scores__score', filter=Q(scores__column=primary_col)))
# TODO: Look at why we have primary_col in the above annotation

)
for column in instance.columns.exclude(id=primary_col.id).order_by('index'):
col_name = f'col{column.index}'
ordering.append(f'{"-" if column.sorting == "desc" else ""}{col_name}')
Expand Down Expand Up @@ -154,16 +158,24 @@ def get_submissions(self, instance):
# asc == colname
primary_col = instance.leaderboard.columns.get(index=instance.leaderboard.primary_index)
ordering = [f'{"-" if primary_col.sorting == "desc" else ""}primary_col']
submissions = Submission.objects.filter(
phase=instance,
is_soft_deleted=False,
has_children=False,
is_specific_task_re_run=False,
leaderboard__isnull=False, ) \
.select_related('owner').prefetch_related('scores') \
submissions = (
Submission.objects.filter(
phase=instance,
is_soft_deleted=False,
has_children=False,
is_specific_task_re_run=False,
leaderboard=instance.leaderboard,
)
.select_related('owner')
.prefetch_related('scores', 'scores__column')
.annotate(primary_col=Sum('scores__score', filter=Q(scores__column=primary_col)))

for column in instance.leaderboard.columns.exclude(id=primary_col.id, hidden=False).order_by('index'):
)
for column in (
instance.leaderboard.columns
.filter(hidden=False)
.exclude(id=primary_col.id)
.order_by('index')
):
col_name = f'col{column.index}'
ordering.append(f'{"-" if column.sorting == "desc" else ""}{col_name}')
kwargs = {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/api/views/competitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def rerun_submissions(self, request, pk):
raise PermissionDenied(error_message)

@swagger_auto_schema(responses={200: PhaseResultsSerializer})
@action(detail=True, methods=['GET'])
@action(detail=True, methods=['GET'], permission_classes=[AllowAny])
def get_leaderboard(self, request, pk):
phase = self.get_object()
if phase.competition.fact_sheet:
Expand Down
23 changes: 22 additions & 1 deletion src/apps/api/views/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,28 @@ def get_queryset(self):
qs = super().get_queryset()
if self.request.method == 'GET':
if not self.request.user.is_authenticated:
return Submission.objects.none()
# Show leaderboard submissions to unauthenticated users
return (
qs.filter(
leaderboard__isnull=False,
is_soft_deleted=False,
status=Submission.FINISHED,
)
.select_related(
'phase',
'phase__competition',
'participant',
'participant__user',
'owner',
'data',
)
.prefetch_related(
'children',
'scores',
'scores__column',
'task',
)
)

# Check if admin is requesting to see soft-deleted submissions
show_is_soft_deleted = self.request.query_params.get('show_is_soft_deleted', 'false').lower() == 'true'
Expand Down
72 changes: 36 additions & 36 deletions src/static/riot/competitions/detail/_registration.tag
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
<registration>
<div if="{!status}" class="ui grid">
<div class="row">
<div class="column">
<p>
You have not yet registered for this competition.
</p>
<p>
To participate in this competition, you must accept its specific
<a href="" onclick="{show_modal}">terms and conditions</a>.
<span if="{registration_auto_approve}">This competition <strong>does not</strong>
require approval, once you register, you will immediately be able to participate.</span>
</p>

<p if="{!registration_auto_approve}">
This competition <strong>requires approval</strong> from the competition organizers. After
submitting your registration request, an email
will be sent to the competition organizers notifying them of your request. Your application will
remain pending until they
approve or deny it.
</p>
</div>
</div>
<virtual if="{CODALAB.state.user.logged_in}">
<div if="{!status}">
<div class="ui yellow message">
<div class="row">
<div class="ui checkbox">
<input type="checkbox" id="accept-terms" onclick="{accept_toggle}">
<label for="accept-terms">I accept the terms and conditions of the competition.</label>
<div class="column">
<h3>You have not yet registered for this competition.</h3>
<p>
To participate in this competition, you must accept its specific
<a href="" onclick="{show_modal}">terms and conditions</a>.
<span if="{registration_auto_approve}">This competition <strong>does not</strong>
require approval, once you register, you will immediately be able to participate.</span>
</p>

<p if="{!registration_auto_approve}">
This competition <strong>requires approval</strong> from the competition organizers. After
submitting your registration request, an email
will be sent to the competition organizers notifying them of your request. Your application will
remain pending until they
approve or deny it.
</p>
</div>
</div>
<div class="row">
<button class="ui primary button {disabled: !accepted}" onclick="{submit_registration}">
Register
</button>
</div>
</virtual>
<div class="row" if="{!CODALAB.state.user.logged_in}">
<div class="column">
<a href="{URLS.LOGIN}?next={location.pathname}">Log In</a> or
<a href="{URLS.SIGNUP}" target="_blank">Sign Up</a> to register for this competition.
<virtual if="{CODALAB.state.user.logged_in}">
<div class="row">
<div class="ui checkbox">
<input type="checkbox" id="accept-terms" onclick="{accept_toggle}">
<label for="accept-terms">I accept the terms and conditions of the competition.</label>
</div>
</div>
<div class="row">
<button class="ui primary button {disabled: !accepted}" onclick="{submit_registration}">
Register
</button>
</div>
</virtual>
<div class="row" if="{!CODALAB.state.user.logged_in}">
<div class="column">
<a href="{URLS.LOGIN}?next={location.pathname}">Log In</a> or
<a href="{URLS.SIGNUP}" target="_blank">Sign Up</a> to register for this competition.
</div>
</div>
</div>
</div>
Expand Down
10 changes: 1 addition & 9 deletions src/static/riot/competitions/detail/_tabs.tag
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,7 @@
<loader></loader>
</div>
<!-- Tab Content !-->
<div class="row" if="{!CODALAB.state.user.logged_in}">
<div class="column">
<div class="ui yellow message">
<a href="{URLS.LOGIN}?next={location.pathname}">Log In</a> or
<a href="{URLS.SIGNUP}" target="_blank">Sign Up</a> to view this competition results.
</div>
</div>
</div>
<div if="{CODALAB.state.user.logged_in}" show="{!loading}">
<div show="{!loading}">
<div class="ui button-container inline">
<div class="ui button {active: selected_phase_index == phase.id}"
each="{ phase in competition.phases }"
Expand Down
29 changes: 2 additions & 27 deletions src/static/riot/competitions/detail/leaderboards.tag
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,10 @@
<th>Date</th>
<th>ID</th>
<th each="{ column in filtered_columns }" colspan="1">{column.title}</th>

</tr>
</thead>
<!-- Show when particpant is not registered -->
<tbody if="{participant_status === null}">
<tr class="center aligned ui yellow message">
<td colspan="100%">
<em>You are not a participant of this competition. Please register in My Submissions tab to view the leaderboard.</em>
</td>
</tr>
</tbody>
<!-- Show when particpant registration is pending -->
<tbody if="{participant_status === 'pending'}">
<tr class="center aligned ui yellow message">
<td colspan="100%">
<em>Your request to participate in this competition is waiting for an approval from the competition organizer.</em>
</td>
</tr>
</tbody>
<!-- Show when particpant registration is denied -->
<tbody if="{participant_status === 'denied'}">
<tr class="center aligned ui red message">
<td colspan="100%">
<em>Your request to participate in this competition is denied. Please contact the competition organizer for more details.</em>
</td>
</tr>
</tbody>
<!-- Show when particpant registration is approved -->
<tbody if="{participant_status === 'approved'}">
<!-- Always show leaderboard -->
<tbody>
<tr if="{_.isEmpty(selected_leaderboard.submissions)}" class="center aligned">
<td colspan="100%">
<em>No submissions have been added to this leaderboard yet!</em>
Expand Down