mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 00:13:18 +00:00
flake8
This commit is contained in:
parent
5c5cf7ff98
commit
32c1b89080
7
.flake8
Normal file
7
.flake8
Normal file
@ -0,0 +1,7 @@
|
||||
[flake8]
|
||||
exclude =
|
||||
xss_filter.py,
|
||||
migrations/,
|
||||
*settings.py
|
||||
max-line-length = 180
|
||||
inline-quotes = "
|
@ -9,4 +9,5 @@ install:
|
||||
- python manage.py migrate
|
||||
- python manage.py initadmin
|
||||
script:
|
||||
- flake8 .
|
||||
- python manage.py test
|
||||
|
@ -1,7 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
import functools
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from utils.api import JSONResponse
|
||||
|
@ -3,5 +3,5 @@ from django.conf.urls import url
|
||||
from ..views.admin import UserAdminAPI
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^user$', UserAdminAPI.as_view(), name="user_admin_api"),
|
||||
url(r"^user$", UserAdminAPI.as_view(), name="user_admin_api"),
|
||||
]
|
||||
|
@ -3,7 +3,7 @@ from django.conf.urls import url
|
||||
from ..views.oj import UserLoginAPI, UserRegisterAPI, UserChangePasswordAPI
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^login$', UserLoginAPI.as_view(), name="user_login_api"),
|
||||
url(r'^register$', UserRegisterAPI.as_view(), name="user_register_api"),
|
||||
url(r'^change_password$', UserChangePasswordAPI.as_view(), name="user_change_password_api")
|
||||
url(r"^login$", UserLoginAPI.as_view(), name="user_login_api"),
|
||||
url(r"^register$", UserRegisterAPI.as_view(), name="user_register_api"),
|
||||
url(r"^change_password$", UserChangePasswordAPI.as_view(), name="user_change_password_api")
|
||||
]
|
||||
|
@ -32,6 +32,6 @@ class AnnouncementAdminTest(APITestCase):
|
||||
|
||||
def test_delete_announcemen(self):
|
||||
id = self.test_create_announcement().data["data"]["id"]
|
||||
resp = self.client.delete(self.url, data={'id': id})
|
||||
resp = self.client.delete(self.url, data={"id": id})
|
||||
self.assertSuccess(resp)
|
||||
self.assertFalse(Announcement.objects.filter(id=id).exists())
|
||||
|
@ -3,5 +3,5 @@ from django.conf.urls import url
|
||||
from ..views import AnnouncementAdminAPI
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^announcement$', AnnouncementAdminAPI.as_view(), name="announcement_admin_api"),
|
||||
url(r"^announcement$", AnnouncementAdminAPI.as_view(), name="announcement_admin_api"),
|
||||
]
|
||||
|
@ -56,4 +56,3 @@ class JudgeServerHeartbeatSerializer(serializers.Serializer):
|
||||
cpu = serializers.FloatField(min_value=0, max_value=100)
|
||||
action = serializers.ChoiceField(choices=("heartbeat", ))
|
||||
service_url = serializers.CharField(max_length=128, required=False)
|
||||
|
||||
|
@ -51,7 +51,7 @@ class SMTPConfigTest(APITestCase):
|
||||
|
||||
class WebsiteConfigAPITest(APITestCase):
|
||||
def test_create_website_config(self):
|
||||
user = self.create_super_admin()
|
||||
self.create_super_admin()
|
||||
url = self.reverse("website_config_api")
|
||||
data = {"base_url": "http://test.com", "name": "test name",
|
||||
"name_shortcut": "test oj", "footer": "<a>test</a>",
|
||||
@ -60,7 +60,7 @@ class WebsiteConfigAPITest(APITestCase):
|
||||
self.assertSuccess(resp)
|
||||
|
||||
def test_edit_website_config(self):
|
||||
user = self.create_super_admin()
|
||||
self.create_super_admin()
|
||||
url = self.reverse("website_config_api")
|
||||
data = {"base_url": "http://test.com", "name": "test name",
|
||||
"name_shortcut": "test oj", "footer": "<a>test</a>",
|
||||
@ -103,7 +103,7 @@ class JudgeServerHeartbeatest(APITestCase):
|
||||
self.assertSuccess(resp)
|
||||
server = JudgeServer.objects.first()
|
||||
self.assertEqual(server.ip, "127.0.0.1")
|
||||
self.assertEqual(server.service_url ,None)
|
||||
self.assertEqual(server.service_url, None)
|
||||
|
||||
def test_new_heartbeat_service_url(self):
|
||||
service_url = "http://1.2.3.4:8000/api/judge"
|
||||
|
@ -3,7 +3,7 @@ from django.conf.urls import url
|
||||
from ..views import WebsiteConfigAPI, SMTPAPI, JudgeServerAPI
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^smtp$', SMTPAPI.as_view(), name="smtp_admin_api"),
|
||||
url(r'^website$', WebsiteConfigAPI.as_view(), name="website_config_api"),
|
||||
url(r'^judge_server', JudgeServerAPI.as_view(), name="judge_server_api")
|
||||
url(r"^smtp$", SMTPAPI.as_view(), name="smtp_admin_api"),
|
||||
url(r"^website$", WebsiteConfigAPI.as_view(), name="website_config_api"),
|
||||
url(r"^judge_server", JudgeServerAPI.as_view(), name="judge_server_api")
|
||||
]
|
||||
|
@ -4,6 +4,6 @@ from ..views import WebsiteConfigAPI, JudgeServerHeartbeatAPI
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^website$', WebsiteConfigAPI.as_view(), name="website_info_api"),
|
||||
url(r'^judge_server_heartbeat$', JudgeServerHeartbeatAPI.as_view(), name="judge_server_heartbeat_api")
|
||||
url(r"^website$", WebsiteConfigAPI.as_view(), name="website_info_api"),
|
||||
url(r"^judge_server_heartbeat$", JudgeServerHeartbeatAPI.as_view(), name="judge_server_heartbeat_api")
|
||||
]
|
||||
|
@ -49,8 +49,6 @@ class SMTPTestAPI(APIView):
|
||||
@super_admin_required
|
||||
@validate_serializer(TestSMTPConfigSerializer)
|
||||
def post(self, request):
|
||||
email = request.data["email"]
|
||||
# todo: test send email
|
||||
return self.success({"result": True})
|
||||
|
||||
|
||||
@ -111,7 +109,7 @@ class JudgeServerHeartbeatAPI(CSRFExemptAPIView):
|
||||
server.cpu_core = data["cpu_core"]
|
||||
server.memory_usage = data["memory"]
|
||||
server.cpu_usage = data["cpu"]
|
||||
server.service_url= service_url
|
||||
server.service_url = service_url
|
||||
server.ip = ip
|
||||
server.last_heartbeat = timezone.now()
|
||||
server.save()
|
||||
@ -126,7 +124,3 @@ class JudgeServerHeartbeatAPI(CSRFExemptAPIView):
|
||||
last_heartbeat=timezone.now(),
|
||||
)
|
||||
return self.success()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -1,3 +0,0 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
@ -3,3 +3,4 @@ djangorestframework==3.3.3
|
||||
pillow
|
||||
jsonfield
|
||||
otpauth
|
||||
flake8-quotes
|
||||
|
@ -1,3 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -1,7 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class GroupConfig(AppConfig):
|
||||
name = 'group'
|
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -1,3 +0,0 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
@ -1,9 +0,0 @@
|
||||
"""
|
||||
___ _ _ __ _ _ _
|
||||
/___\ _ __ | |(_) _ __ ___ \ \ _ _ __| | __ _ ___ | |__ _ _ __ _ __| | _ _
|
||||
// //| '_ \ | || || '_ \ / _ \ \ \| | | | / _` | / _` | / _ \ | '_ \ | | | | / _` | / _` || | | |
|
||||
/ \_// | | | || || || | | || __/ /\_/ /| |_| || (_| || (_| || __/ | |_) || |_| | | (_| || (_| || |_| |
|
||||
\___/ |_| |_||_||_||_| |_| \___| \___/ \__,_| \__,_| \__, | \___| |_.__/ \__, | \__, | \__,_| \__,_|
|
||||
|___/ |___/ |_|
|
||||
https://github.com/QingdaoU/OnlineJudge
|
||||
"""
|
@ -2,5 +2,3 @@
|
||||
|
||||
# please set your own SECRET_KEY to a long random string
|
||||
# SECRET_KEY = ""
|
||||
|
||||
|
||||
|
@ -3,13 +3,13 @@
|
||||
|
||||
class DBRouter(object):
|
||||
def db_for_read(self, model, **hints):
|
||||
if model._meta.app_label == 'submission':
|
||||
return 'submission'
|
||||
if model._meta.app_label == "submission":
|
||||
return "submission"
|
||||
return "default"
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
if model._meta.app_label == 'submission':
|
||||
return 'submission'
|
||||
if model._meta.app_label == "submission":
|
||||
return "submission"
|
||||
return "default"
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
|
10
oj/urls.py
10
oj/urls.py
@ -2,9 +2,9 @@
|
||||
from django.conf.urls import include, url
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^api/', include("account.urls.oj")),
|
||||
url(r'^api/admin/', include("account.urls.admin")),
|
||||
url(r'^api/admin/', include("announcement.urls.admin")),
|
||||
url(r'^api/', include("conf.urls.oj")),
|
||||
url(r'^api/admin/', include("conf.urls.admin"))
|
||||
url(r"^api/", include("account.urls.oj")),
|
||||
url(r"^api/admin/", include("account.urls.admin")),
|
||||
url(r"^api/admin/", include("announcement.urls.admin")),
|
||||
url(r"^api/", include("conf.urls.oj")),
|
||||
url(r"^api/admin/", include("conf.urls.admin"))
|
||||
]
|
||||
|
@ -1,3 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -1,4 +1,3 @@
|
||||
# coding=utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from jsonfield import JSONField
|
||||
|
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -1,3 +0,0 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
@ -1,2 +1,2 @@
|
||||
from .api import *
|
||||
from ._serializers import *
|
||||
from .api import * # NOQA
|
||||
from ._serializers import * # NOQA
|
||||
|
@ -1,5 +1,3 @@
|
||||
# coding:utf-8
|
||||
|
||||
"""
|
||||
Copyright 2013 TY<tianyu0915@gmail.com>
|
||||
|
||||
@ -20,6 +18,7 @@ import os
|
||||
import time
|
||||
import random
|
||||
|
||||
from io import StringIO
|
||||
from django.http import HttpResponse
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
@ -31,8 +30,8 @@ class Captcha(object):
|
||||
初始化,设置各种属性
|
||||
"""
|
||||
self.django_request = request
|
||||
self.session_key = '_django_captcha_key'
|
||||
self.captcha_expires_time = '_django_captcha_expires_time'
|
||||
self.session_key = "_django_captcha_key"
|
||||
self.captcha_expires_time = "_django_captcha_expires_time"
|
||||
|
||||
# 验证码图片尺寸
|
||||
self.img_width = 90
|
||||
@ -57,7 +56,7 @@ class Captcha(object):
|
||||
"""
|
||||
生成随机数或随机字符串
|
||||
"""
|
||||
string = random.sample('abcdefghkmnpqrstuvwxyzABCDEFGHGKMNOPQRSTUVWXYZ23456789', 4)
|
||||
string = random.sample("abcdefghkmnpqrstuvwxyzABCDEFGHGKMNOPQRSTUVWXYZ23456789", 4)
|
||||
self._set_answer("".join(string))
|
||||
return string
|
||||
|
||||
@ -68,9 +67,9 @@ class Captcha(object):
|
||||
background = (random.randrange(200, 255), random.randrange(200, 255), random.randrange(200, 255))
|
||||
code_color = (random.randrange(0, 50), random.randrange(0, 50), random.randrange(0, 50), 255)
|
||||
|
||||
font_path = os.path.join(os.path.normpath(os.path.dirname(__file__)), 'timesbi.ttf')
|
||||
font_path = os.path.join(os.path.normpath(os.path.dirname(__file__)), "timesbi.ttf")
|
||||
|
||||
image = Image.new('RGB', (self.img_width, self.img_height), background)
|
||||
image = Image.new("RGB", (self.img_width, self.img_height), background)
|
||||
code = self._make_code()
|
||||
font_size = self._get_font_size(code)
|
||||
draw = ImageDraw.Draw(image)
|
||||
@ -82,22 +81,22 @@ class Captcha(object):
|
||||
# 字符y坐标
|
||||
y = random.randrange(1, 7)
|
||||
# 随机字符大小
|
||||
font = ImageFont.truetype(font_path.replace('\\', '/'), font_size + random.randrange(-3, 7))
|
||||
font = ImageFont.truetype(font_path.replace("\\", "/"), font_size + random.randrange(-3, 7))
|
||||
draw.text((x, y), i, font=font, fill=code_color)
|
||||
# 随机化字符之间的距离 字符粘连可以降低识别率
|
||||
x += font_size * random.randrange(6, 8) / 10
|
||||
|
||||
buf = StringIO.StringIO()
|
||||
image.save(buf, 'gif')
|
||||
buf = StringIO()
|
||||
image.save(buf, "gif")
|
||||
|
||||
self.django_request.session[self.session_key] = "".join(code)
|
||||
return HttpResponse(buf.getvalue(), 'image/gif')
|
||||
return HttpResponse(buf.getvalue(), "image/gif")
|
||||
|
||||
def check(self, code):
|
||||
"""
|
||||
检查用户输入的验证码是否正确
|
||||
"""
|
||||
_code = self.django_request.session.get(self.session_key) or ''
|
||||
_code = self.django_request.session.get(self.session_key) or ""
|
||||
if not _code:
|
||||
return False
|
||||
expires_time = self.django_request.session.get(self.captcha_expires_time) or 0
|
||||
|
@ -1,5 +1,3 @@
|
||||
# coding=utf-8
|
||||
import json
|
||||
from django.db import models
|
||||
|
||||
from utils.xss_filter import XssHtml
|
||||
@ -15,7 +13,3 @@ class RichTextField(models.TextField):
|
||||
parser.feed(value)
|
||||
parser.close()
|
||||
return parser.getHtml()
|
||||
|
||||
|
||||
class JsonField(models.TextField):
|
||||
pass
|
Loading…
Reference in New Issue
Block a user