Merge branch 'dev' into sxw-dev

This commit is contained in:
esp 2015-08-10 18:07:08 +08:00
commit 837f721512
18 changed files with 74 additions and 4 deletions

View File

@ -0,0 +1 @@
# coding=utf-8

View File

@ -0,0 +1 @@
celery -A judge.controller worker -l DEBUG

View File

@ -0,0 +1 @@
# coding=utf-8

View File

@ -0,0 +1,5 @@
# coding=utf-8
from __future__ import absolute_import
from celery import Celery
app = Celery("judge", broker="redis://localhost:6379/0", include=["judge.controller.tasks"])

View File

@ -0,0 +1,8 @@
# coding=utf-8
from __future__ import absolute_import
from judge.controller.celery import app
@app.task
def judge(source_code, language, test_case_id):
print source_code, language, test_case_id

0
judge/judger/__init__.py Normal file
View File

View File

@ -11,7 +11,7 @@ from group.views import GroupAdminAPIView
from admin.views import AdminTemplateView
from problem.views import ProblemAdminAPIView
from problem.views import TestCaseUploadAPIView
from problem.views import TestCaseUploadAPIView, ProblemTagAdminAPIView
urlpatterns = [
@ -41,4 +41,5 @@ urlpatterns = [
url(r'^api/admin/group/$', GroupAdminAPIView.as_view(), name="group_admin_api"),
url(r'^api/admin/problem/$', ProblemAdminAPIView.as_view(), name="problem_admin_api"),
url(r'^api/admin/test_case_upload/$', TestCaseUploadAPIView.as_view(), name="test_case_upload_api"),
url(r'^api/admin/tag/$', ProblemTagAdminAPIView.as_view(), name="problem_tag_admin_api"),
]

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('problem', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='problemtag',
name='description',
),
]

View File

@ -6,7 +6,7 @@ from account.models import User
class ProblemTag(models.Model):
name = models.CharField(max_length=30)
description = models.CharField(max_length=50)
# description = models.CharField(max_length=50)
class Meta:
db_table = "problem_tag"

View File

@ -4,7 +4,7 @@ import json
from rest_framework import serializers
from account.models import User
from .models import Problem
from .models import Problem, ProblemTag
class ProblemSampleSerializer(serializers.ListField):
@ -60,3 +60,12 @@ class EditProblemSerializer(serializers.Serializer):
hint = serializers.CharField(max_length=10000)
visible = serializers.BooleanField()
class ProblemTagSerializer(serializers.ModelSerializer):
class Meta:
model = ProblemTag
class CreateProblemTagSerializer(serializers.Serializer):
name = serializers.CharField(max_length=10)

View File

@ -11,10 +11,36 @@ from django.db.models import Q
from rest_framework.views import APIView
from utils.shortcuts import serializer_invalid_response, error_response, success_response, paginate, rand_str
from .serizalizers import CreateProblemSerializer, EditProblemSerializer, ProblemSerializer
from .serizalizers import (CreateProblemSerializer, EditProblemSerializer, ProblemSerializer,
ProblemTagSerializer, CreateProblemTagSerializer)
from .models import Problem, ProblemTag
class ProblemTagAdminAPIView(APIView):
def post(self, request):
"""
创建标签的接口
---
request_serializer: CreateProblemTagSerializer
"""
serializer = CreateProblemTagSerializer(data=request.data)
if serializer.is_valid():
try:
tag = ProblemTag.objects.get(name=serializer.data["name"])
except ProblemTag.DoesNotExist:
tag = ProblemTag.objects.create(name=serializer.data["name"])
return success_response(ProblemTagSerializer(tag).data)
else:
return error_response(serializer)
def get(self, request):
keyword = request.GET.get("keyword", None)
if not keyword:
return error_response(u"参数错误")
tags = ProblemTag.objects.filter(name__contains=keyword)
return success_response(ProblemTagSerializer(tags, many=True).data)
def problem_page(request, problem_id):