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 Language and Judge endpoints to API v2 #1471

Merged
merged 1 commit into from
Jun 24, 2020
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
2 changes: 2 additions & 0 deletions dmoj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ def paged_list_view(view, name):
url(r'^submission/(?P<submission>\d+)$', api.api_v2.APISubmissionDetail.as_view()),
url(r'^organizations$', api.api_v2.APIOrganizationList.as_view()),
url(r'^participations$', api.api_v2.APIContestParticipationList.as_view()),
url(r'^languages$', api.api_v2.APILanguageList.as_view()),
url(r'^judges$', api.api_v2.APIJudgeList.as_view()),
])),
])),

Expand Down
37 changes: 36 additions & 1 deletion judge/views/api/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from django.views.generic.list import BaseListView

from judge.models import (
Contest, ContestParticipation, ContestTag, Organization, Problem, ProblemType, Profile, Rating, Submission,
Contest, ContestParticipation, ContestTag, Judge, Language, Organization, Problem, ProblemType, Profile, Rating,
Submission,
)
from judge.utils.raw_sql import join_sql_subquery, use_straight_join
from judge.views.submission import group_test_cases
Expand Down Expand Up @@ -609,3 +610,37 @@ def get_object_data(self, organization):
'is_open': organization.is_open,
'member_count': organization.member_count,
}


class APILanguageList(APIListView):
model = Language
basic_filters = (
('common_name', 'common_name'),
)

def get_object_data(self, language):
return {
'id': language.id,
'key': language.key,
'short_name': language.short_name,
'common_name': language.common_name,
'ace_mode_name': language.ace,
'pygments_name': language.pygments,
'code_template': language.template,
}


class APIJudgeList(APIListView):
model = Judge

def get_unfiltered_queryset(self):
return Judge.objects.filter(online=True).prefetch_related('runtimes').order_by('name')

def get_object_data(self, judge):
return {
'name': judge.name,
'start_time': judge.start_time.isoformat(),
'ping': judge.ping_ms,
'load': judge.load,
'languages': list(judge.runtimes.values_list('key', flat=True)),
}