mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
Merge branch 'dev' into sxw-dev
Conflicts: template/admin/admin.html
This commit is contained in:
commit
76e3188360
@ -97,6 +97,7 @@ class UsernameCheckAPIView(APIView):
|
||||
else:
|
||||
return serializer_invalid_response(serializer)
|
||||
|
||||
|
||||
class EmailCheckAPIView(APIView):
|
||||
def post(self, request):
|
||||
"""
|
||||
|
||||
@ -22,3 +22,9 @@ class AnnouncementSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Announcement
|
||||
|
||||
|
||||
class EditAnnouncementSerializer(serializers.Serializer):
|
||||
id = serializers.IntegerField()
|
||||
title = serializers.CharField(max_length=50)
|
||||
content = serializers.CharField(max_length=10000)
|
||||
visible = serializers.BooleanField()
|
||||
|
||||
@ -4,9 +4,10 @@ from django.core.urlresolvers import reverse
|
||||
from rest_framework.test import APITestCase, APIClient
|
||||
|
||||
from account.models import User
|
||||
from announcement.models import Announcement
|
||||
|
||||
|
||||
class AnnouncementAPITest(APITestCase):
|
||||
class AnnouncementAdminAPITest(APITestCase):
|
||||
def setUp(self):
|
||||
self.client = APIClient()
|
||||
self.url = reverse("announcement_admin_api")
|
||||
@ -14,6 +15,7 @@ class AnnouncementAPITest(APITestCase):
|
||||
user.set_password("test")
|
||||
user.save()
|
||||
|
||||
# 以下是发布公告的测试
|
||||
def test_invalid_format(self):
|
||||
self.client.login(username="test", password="test")
|
||||
data = {"title": "test1"}
|
||||
@ -25,3 +27,41 @@ class AnnouncementAPITest(APITestCase):
|
||||
data = {"title": "title0", "content": "content0"}
|
||||
response = self.client.post(self.url, data=data)
|
||||
self.assertEqual(response.data, {"code": 0, "data": u"公告发布成功!"})
|
||||
|
||||
def test_post_invalid_data(self):
|
||||
self.client.login(username="test", password="test")
|
||||
data = {"title": "test"}
|
||||
response = self.client.post(self.url, data=data)
|
||||
self.assertEqual(response.data["code"], 1)
|
||||
|
||||
# 以下是编辑公告的测试
|
||||
def test_put_invalid_data(self):
|
||||
self.client.login(username="test", password="test")
|
||||
data = {"title": "test0", "content": "test0", "visible": "True"}
|
||||
response = self.client.put(self.url, data=data)
|
||||
self.assertEqual(response.data["code"], 1)
|
||||
|
||||
def test_announcement_does_not_exist(self):
|
||||
announcement = Announcement.objects.create(title="aa",
|
||||
content="AA",
|
||||
created_by=User.objects.get(username="test"))
|
||||
data = {"id": announcement.id + 1, "title": "11", "content": "22", "visible": True}
|
||||
response = self.client.put(self.url, data=data)
|
||||
self.assertEqual(response.data, {"code": 1, "data": u"该公告不存在!"})
|
||||
|
||||
def test_success_edit_announcement(self):
|
||||
announcement = Announcement.objects.create(title="bb",
|
||||
content="BB",
|
||||
created_by=User.objects.get(username="test"))
|
||||
data = {"id": announcement.id, "title": "11", "content": "22", "visible": True}
|
||||
response = self.client.put(self.url, data=data)
|
||||
self.assertEqual(response.data["code"], 0)
|
||||
|
||||
|
||||
class AnnouncementAPITest(APITestCase):
|
||||
def setUp(self):
|
||||
self.client = APIClient()
|
||||
self.url = reverse("announcement_list_api")
|
||||
|
||||
def test_success_get_data(self):
|
||||
self.assertEqual(self.client.get(self.url).data["code"], 0)
|
||||
|
||||
@ -6,7 +6,8 @@ from utils.shortcuts import serializer_invalid_response, error_response, success
|
||||
from account.models import User
|
||||
from utils.shortcuts import paginate
|
||||
from .models import Announcement
|
||||
from .serializers import CreateAnnouncementSerializer, AnnouncementSerializer
|
||||
from .serializers import (CreateAnnouncementSerializer, AnnouncementSerializer,
|
||||
EditAnnouncementSerializer)
|
||||
|
||||
|
||||
class AnnouncementAdminAPIView(APIView):
|
||||
@ -26,6 +27,28 @@ class AnnouncementAdminAPIView(APIView):
|
||||
else:
|
||||
return serializer_invalid_response(serializer)
|
||||
|
||||
def put(self, request):
|
||||
"""
|
||||
公告编辑json api接口
|
||||
---
|
||||
request_serializer: EditAnnouncementSerializer
|
||||
response_serializer: AnnouncementSerializer
|
||||
"""
|
||||
serializer = EditAnnouncementSerializer(data=request.DATA)
|
||||
if serializer.is_valid():
|
||||
data = serializer.data
|
||||
try:
|
||||
announcement = Announcement.objects.get(id=data["id"])
|
||||
except Announcement.DoesNotExist:
|
||||
return error_response(u"该公告不存在!")
|
||||
announcement.title = data["title"]
|
||||
announcement.content = data["content"]
|
||||
announcement.visible = data["visible"]
|
||||
announcement.save()
|
||||
return success_response(AnnouncementSerializer(announcement).data)
|
||||
else:
|
||||
return serializer_invalid_response(serializer)
|
||||
|
||||
|
||||
class AnnouncementAPIView(APIView):
|
||||
def get(self, request):
|
||||
|
||||
@ -1,25 +1,15 @@
|
||||
@import url("global.css");
|
||||
@import url("bootstrap/bootstrap.min.css");
|
||||
@import url("bootstrap/todc-bootstrap.min.css");
|
||||
@import url("codeMirror/codemirror.css");
|
||||
@import url("simditor/simditor.css");
|
||||
@import url("webuploader/webuploader.css");
|
||||
@import url("datetime_picker/bootstrap-datetimepicker.css");
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding-top: 30px;
|
||||
padding-bottom: 30px;
|
||||
float: bottom;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 16px;
|
||||
#loading-gif{
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
margin: auto;
|
||||
position: absolute;
|
||||
top: 0; left: 0; bottom: 0; right: 0;
|
||||
}
|
||||
27
static/src/css/global.css
Normal file
27
static/src/css/global.css
Normal file
@ -0,0 +1,27 @@
|
||||
html{
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body{
|
||||
height:100%; /*使内容高度和body一样*/
|
||||
margin-bottom:-80px;/*向上缩减80像素,不至于footer超出屏幕可视范围*/
|
||||
}
|
||||
|
||||
.main{
|
||||
padding-bottom: 120px;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.footer {
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 80px
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 16px;
|
||||
}
|
||||
@ -1,25 +1,8 @@
|
||||
@import url("global.css");
|
||||
@import url("bootstrap/bootstrap.min.css");
|
||||
@import url("bootstrap/todc-bootstrap.min.css");
|
||||
@import url("codeMirror/codemirror.css");
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding-top: 30px;
|
||||
padding-bottom: 30px;
|
||||
float: bottom;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#language-selector {
|
||||
width: 130px;
|
||||
@ -47,7 +30,6 @@ label {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
/* index css */
|
||||
.jumbotron {
|
||||
text-align: center;
|
||||
background-color: transparent;
|
||||
|
||||
@ -7,25 +7,36 @@ define("admin", ["jquery", "avalon"], function($, avalon){
|
||||
$(".list-group-item").attr("class", "list-group-item");
|
||||
}
|
||||
|
||||
function show_template(url){
|
||||
$("#loading-gif").show();
|
||||
vm.template_url = url;
|
||||
}
|
||||
|
||||
var vm = avalon.define({
|
||||
$id: "admin",
|
||||
template_url: "template/index/index.html",
|
||||
hide_loading: function(){
|
||||
$("#loading-gif").hide();
|
||||
}
|
||||
});
|
||||
|
||||
var hash = window.location.hash.substring(1);
|
||||
|
||||
if(hash){
|
||||
li_active("#li-" + hash);
|
||||
li_active("#li-" + hash.replace("/", "-"));
|
||||
show_template("template/" + hash + ".html");
|
||||
}else {
|
||||
li_active("#li-index");
|
||||
li_active("#li-index-index");
|
||||
}
|
||||
|
||||
window.onhashchange = function() {
|
||||
var hash = window.location.hash.substring(1);
|
||||
if(hash){
|
||||
li_inactive(".list-group-item");
|
||||
li_active("#li-" + hash);
|
||||
vm.template_url = "template/index/" + hash + ".html";
|
||||
li_active("#li-" + hash.replace("/", "-"));
|
||||
show_template("template/" + hash + ".html");
|
||||
}
|
||||
};
|
||||
|
||||
var vm = avalon.define({
|
||||
$id: "admin",
|
||||
template_url: "template/index/index.html"
|
||||
});
|
||||
|
||||
});
|
||||
@ -2,6 +2,7 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
|
||||
"validation"
|
||||
],
|
||||
function ($, avalon, editor, uploader) {
|
||||
avalon.vmodels.add_contest = null;
|
||||
$("#add-contest-form")
|
||||
.formValidation({
|
||||
framework: "bootstrap",
|
||||
|
||||
@ -67,23 +67,25 @@
|
||||
<![endif]-->
|
||||
<!-- browser happy end -->
|
||||
|
||||
<div class="container" ms-controller="admin">
|
||||
<div class="container main" ms-controller="admin">
|
||||
<div class="row">
|
||||
<!-- admin left begin-->
|
||||
<div class="col-md-2">
|
||||
<ul class="list-group">
|
||||
<li class="list-group-header">List header</li>
|
||||
<li class="list-group-item" id="li-index"><a href="#index">主页</a></li>
|
||||
<li class="list-group-item" id="li-announcement"><a href="#announcement">公告</a></li>
|
||||
<li class="list-group-item" id="li-index-index"><a href="#index/index">主页</a></li>
|
||||
<li class="list-group-item" id="li-announcement-announcement"><a href="#announcement/announcement">公告</a></li>
|
||||
<li class="list-group-item"><a href="#">Applications</a></li>
|
||||
<li class="list-group-header">Another list header</li>
|
||||
<li class="list-group-item"><a href="#">Help</a></li>
|
||||
<li class="list-group-header">比赛管理</li>
|
||||
<li class="list-group-item" id="li-contest-add_contest"><a href="#contest/add_contest">创建比赛</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- admin left end -->
|
||||
|
||||
<img src="/static/img/loading.gif" id="loading-gif">
|
||||
<!-- custom body begin -->
|
||||
<div class='col-md-8'ms-include-src="template_url"></div>
|
||||
|
||||
<div class='col-md-8' ms-include-src="template_url" data-include-rendered="hide_loading"></div>
|
||||
|
||||
<!-- custom body end -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
{% extends "admin_base.html" %}
|
||||
{% block body %}
|
||||
{% verbatim %}
|
||||
<div ms-controller="add_contest">
|
||||
<div ms-controller="add_contest">
|
||||
|
||||
|
||||
<form id="add-contest-form">
|
||||
@ -177,9 +174,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endverbatim %}
|
||||
{% endblock %}
|
||||
{% block js_block %}
|
||||
<script src="/static/js/app/admin/contest/contest.js"></script>
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
<script src="/static/js/app/admin/contest/contest.js"></script>
|
||||
@ -1,6 +1,6 @@
|
||||
{% extends "oj_base.html" %}
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<div class="container main">
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<h2 class="text-center">修改密码</h2>
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{% extends "oj_base.html" %}
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<div class="container main">
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<h2 class="text-center">用户登录</h2>
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{% extends "oj_base.html" %}
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<div class="container main">
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<h2 class="text-center">用户注册</h2>
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{% extends "oj_base.html" %}
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<div class="container main">
|
||||
<ul class="nav nav-tabs nav-tabs-google">
|
||||
<li role="presentation" class="active">
|
||||
<a href="problem.html">题目</a></li>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{% extends 'oj_base.html' %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container">
|
||||
<div class="container main">
|
||||
<ul class="nav nav-tabs nav-tabs-google">
|
||||
<li role="presentation" class="active">
|
||||
<a href="problem.html">题目</a></li>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{% extends "oj_base.html" %}
|
||||
{% block body %}
|
||||
<div class="container" ms-controller="problem_list">
|
||||
<div class="container main" ms-controller="problem_list">
|
||||
<div class="row">
|
||||
<div class="col-lg-9">
|
||||
<div class="row">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user