mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-16 01:13:47 +00:00
Merge branch 'chiaki_dev' of github.com:QingdaoU/OnlineJudge into chiaki_dev
This commit is contained in:
commit
25dd57bb49
35
problem/migrations/0004_auto_20170501_0637.py
Normal file
35
problem/migrations/0004_auto_20170501_0637.py
Normal file
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.6 on 2017-05-01 06:37
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('problem', '0003_auto_20170217_0820'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='contestproblem',
|
||||
name='total_accepted_number',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='contestproblem',
|
||||
name='total_submit_number',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='problem',
|
||||
name='total_accepted_number',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='problem',
|
||||
name='total_submit_number',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
]
|
@ -18,6 +18,12 @@ class ProblemRuleType(object):
|
||||
OI = "OI"
|
||||
|
||||
|
||||
class ProblemDifficulty(object):
|
||||
High = "High"
|
||||
Mid = "Mid"
|
||||
Low = "Low"
|
||||
|
||||
|
||||
class AbstractProblem(models.Model):
|
||||
title = models.CharField(max_length=128)
|
||||
# HTML
|
||||
@ -49,19 +55,19 @@ class AbstractProblem(models.Model):
|
||||
difficulty = models.CharField(max_length=32)
|
||||
tags = models.ManyToManyField(ProblemTag)
|
||||
source = models.CharField(max_length=200, blank=True, null=True)
|
||||
total_submit_number = models.IntegerField(default=0)
|
||||
total_accepted_number = models.IntegerField(default=0)
|
||||
total_submit_number = models.BigIntegerField(default=0)
|
||||
total_accepted_number = models.BigIntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
db_table = "problem"
|
||||
abstract = True
|
||||
|
||||
def add_submission_number(self):
|
||||
self.accepted_problem_number = models.F("total_submit_number") + 1
|
||||
self.total_submit_number = models.F("total_submit_number") + 1
|
||||
self.save()
|
||||
|
||||
def add_ac_number(self):
|
||||
self.accepted_problem_number = models.F("total_accepted_number") + 1
|
||||
self.total_accepted_number = models.F("total_accepted_number") + 1
|
||||
self.save()
|
||||
|
||||
|
||||
@ -77,4 +83,4 @@ class ContestProblem(AbstractProblem):
|
||||
|
||||
class Meta:
|
||||
db_table = "contest_problem"
|
||||
unique_together = (("_id", "contest"), )
|
||||
unique_together = (("_id", "contest"),)
|
||||
|
@ -17,7 +17,9 @@ class ProblemTagListAPITest(APITestCase):
|
||||
ProblemTag.objects.create(name="name2")
|
||||
resp = self.client.get(self.reverse("problem_tag_list_api"))
|
||||
self.assertSuccess(resp)
|
||||
self.assertEqual(resp.data["data"], ["name1", "name2"])
|
||||
resp_data = resp.data["data"]
|
||||
self.assertEqual(resp_data[0]["name"], "name1")
|
||||
self.assertEqual(resp_data[1]["name"], "name2")
|
||||
|
||||
|
||||
class TestCaseUploadAPITest(APITestCase):
|
||||
@ -27,7 +29,8 @@ class TestCaseUploadAPITest(APITestCase):
|
||||
self.create_super_admin()
|
||||
|
||||
def test_filter_file_name(self):
|
||||
self.assertEqual(self.api.filter_name_list(["1.in", "1.out", "2.in", ".DS_Store"], spj=False), ["1.in", "1.out"])
|
||||
self.assertEqual(self.api.filter_name_list(["1.in", "1.out", "2.in", ".DS_Store"], spj=False),
|
||||
["1.in", "1.out"])
|
||||
self.assertEqual(self.api.filter_name_list(["2.in", "2.out"], spj=False), [])
|
||||
|
||||
self.assertEqual(self.api.filter_name_list(["1.in", "1.out", "2.in"], spj=True), ["1.in", "2.in"])
|
||||
@ -76,9 +79,9 @@ class TestCaseUploadAPITest(APITestCase):
|
||||
self.assertEqual(f.read(), name + "\n" + name + "\n" + "end")
|
||||
|
||||
|
||||
class ProblemAPITest(APITestCase):
|
||||
class ProblemAdminAPITest(APITestCase):
|
||||
def setUp(self):
|
||||
self.url = self.reverse("problem_api")
|
||||
self.url = self.reverse("problem_admin_api")
|
||||
self.create_super_admin()
|
||||
self.data = {"_id": "A-110", "title": "test", "description": "<p>test</p>", "input_description": "test",
|
||||
"output_description": "test", "time_limit": 1000, "memory_limit": 256, "difficulty": "Low",
|
||||
|
@ -4,6 +4,6 @@ from ..views.admin import ContestProblemAPI, ProblemAPI, TestCaseUploadAPI
|
||||
|
||||
urlpatterns = [
|
||||
url(r"^test_case/upload/?$", TestCaseUploadAPI.as_view(), name="test_case_upload_api"),
|
||||
url(r"^problem/?$", ProblemAPI.as_view(), name="problem_api"),
|
||||
url(r"^problem/?$", ProblemAPI.as_view(), name="problem_admin_api"),
|
||||
url(r"^contest/problem/?$", ContestProblemAPI.as_view(), name="contest_problem_api")
|
||||
]
|
||||
|
@ -1,7 +1,8 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from ..views.oj import ProblemTagAPI
|
||||
from ..views.oj import ProblemTagAPI, ProblemAPI
|
||||
|
||||
urlpatterns = [
|
||||
url(r"^problem/tags/?$", ProblemTagAPI.as_view(), name="problem_tag_list_api")
|
||||
url(r"^problem/tags/?$", ProblemTagAPI.as_view(), name="problem_tag_list_api"),
|
||||
url(r"^problems/?$", ProblemAPI.as_view(), name="problem_list_api"),
|
||||
]
|
||||
|
@ -1,8 +1,44 @@
|
||||
from django.db.models import Q
|
||||
from utils.api import APIView
|
||||
|
||||
from ..models import ProblemTag
|
||||
from ..models import ProblemTag, Problem
|
||||
from ..serializers import ProblemSerializer, TagSerializer
|
||||
|
||||
|
||||
class ProblemTagAPI(APIView):
|
||||
def get(self, request):
|
||||
return self.success([item.name for item in ProblemTag.objects.all().order_by("id")])
|
||||
return self.success(TagSerializer(ProblemTag.objects.all(), many=True).data)
|
||||
|
||||
|
||||
class ProblemAPI(APIView):
|
||||
def get(self, request):
|
||||
# 问题详情页
|
||||
problem_id = request.GET.get("id")
|
||||
if problem_id:
|
||||
try:
|
||||
problem = Problem.objects.get(id=problem_id)
|
||||
return self.success(ProblemSerializer(problem).data)
|
||||
except Problem.DoesNotExist:
|
||||
return self.error("Problem does not exist")
|
||||
|
||||
problems = Problem.objects.filter(visible=True)
|
||||
# 按照标签筛选
|
||||
tag_text = request.GET.get("tag", None)
|
||||
if tag_text:
|
||||
try:
|
||||
tag = ProblemTag.objects.get(name=tag_text)
|
||||
except ProblemTag.DoesNotExist:
|
||||
return self.error("The Tag does not exist.")
|
||||
problems = tag.problem_set.all().filter(visible=True)
|
||||
|
||||
# 搜索的情况
|
||||
keyword = request.GET.get("keyword", "").strip()
|
||||
if keyword:
|
||||
problems = problems.filter(Q(title__contains=keyword) | Q(description__contains=keyword))
|
||||
|
||||
# 难度筛选
|
||||
difficulty_rank = request.GET.get("difficulty", None)
|
||||
if difficulty_rank:
|
||||
problems = problems.filter(difficulty=difficulty_rank)
|
||||
|
||||
return self.success(self.paginate_data(request, problems, ProblemSerializer))
|
||||
|
Loading…
x
Reference in New Issue
Block a user