From 8128e076f2169e492f3caed38a9b75d38b6b41a6 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Wed, 19 Apr 2017 01:37:10 +0800 Subject: [PATCH] format code --- account/tasks.py | 4 +--- account/urls/oj.py | 7 ++----- account/urls/user.py | 7 ++----- account/views/oj.py | 16 +++++++--------- account/views/user.py | 12 ++++-------- contest/tests.py | 6 +++--- contest/views/admin.py | 1 + deploy/requirements.txt | 3 ++- fps/parser.py | 2 +- oj/local_settings.py | 6 +----- oj/server_settings.py | 10 +--------- oj/settings.py | 24 +++++++++--------------- problem/tests.py | 1 + problem/urls/admin.py | 2 +- problem/views/admin.py | 7 ++++--- run_test.py | 3 +-- utils/mail.py | 3 --- 17 files changed, 41 insertions(+), 73 deletions(-) diff --git a/account/tasks.py b/account/tasks.py index 6470b704..00248baf 100644 --- a/account/tasks.py +++ b/account/tasks.py @@ -1,7 +1,5 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - from celery import shared_task + from utils.mail import send_email diff --git a/account/urls/oj.py b/account/urls/oj.py index e73311f8..fa47e33d 100644 --- a/account/urls/oj.py +++ b/account/urls/oj.py @@ -1,10 +1,7 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - from django.conf.urls import url -from ..views.oj import (UserChangePasswordAPI, UserLoginAPI, UserRegisterAPI, - ApplyResetPasswordAPI, ResetPasswordAPI) +from ..views.oj import (ApplyResetPasswordAPI, ResetPasswordAPI, + UserChangePasswordAPI, UserLoginAPI, UserRegisterAPI) urlpatterns = [ url(r"^login/?$", UserLoginAPI.as_view(), name="user_login_api"), diff --git a/account/urls/user.py b/account/urls/user.py index 3ec765af..1676ddce 100644 --- a/account/urls/user.py +++ b/account/urls/user.py @@ -1,10 +1,7 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - from django.conf.urls import url -from ..views.user import (UserInfoAPI, UserProfileAPI, AvatarUploadAPI, - SSOAPI, TwoFactorAuthAPI) +from ..views.user import (SSOAPI, AvatarUploadAPI, TwoFactorAuthAPI, + UserInfoAPI, UserProfileAPI) urlpatterns = [ url(r"^user/?$", UserInfoAPI.as_view(), name="user_info_api"), diff --git a/account/views/oj.py b/account/views/oj.py index 125fc69c..48a35c38 100644 --- a/account/views/oj.py +++ b/account/views/oj.py @@ -1,14 +1,11 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - from datetime import timedelta -from otpauth import OtpAuth -from django.contrib import auth from django.conf import settings +from django.contrib import auth from django.core.exceptions import MultipleObjectsReturned -from django.utils.translation import ugettext as _ from django.utils.timezone import now +from django.utils.translation import ugettext as _ +from otpauth import OtpAuth from conf.models import WebsiteConfig from utils.api import APIView, validate_serializer @@ -17,9 +14,10 @@ from utils.shortcuts import rand_str from ..decorators import login_required from ..models import User, UserProfile -from ..serializers import (UserChangePasswordSerializer, UserLoginSerializer, - UserRegisterSerializer, - ApplyResetPasswordSerializer, ResetPasswordSerializer) +from ..serializers import (ApplyResetPasswordSerializer, + ResetPasswordSerializer, + UserChangePasswordSerializer, UserLoginSerializer, + UserRegisterSerializer) from ..tasks import _send_email diff --git a/account/views/user.py b/account/views/user.py index d3bcacfa..94b8ccb1 100644 --- a/account/views/user.py +++ b/account/views/user.py @@ -1,15 +1,11 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - import os -import qrcode - from io import StringIO -from otpauth import OtpAuth +import qrcode from django.conf import settings from django.http import HttpResponse from django.utils.translation import ugettext as _ +from otpauth import OtpAuth from conf.models import WebsiteConfig from utils.api import APIView, validate_serializer @@ -17,8 +13,8 @@ from utils.shortcuts import rand_str from ..decorators import login_required from ..models import User -from ..serializers import (EditUserSerializer, UserSerializer, - SSOSerializer, TwoFactorAuthCodeSerializer) +from ..serializers import (EditUserSerializer, SSOSerializer, + TwoFactorAuthCodeSerializer, UserSerializer) class UserInfoAPI(APIView): diff --git a/contest/tests.py b/contest/tests.py index 11d29b2a..8a8134f4 100644 --- a/contest/tests.py +++ b/contest/tests.py @@ -1,12 +1,12 @@ +import copy from datetime import datetime, timedelta -import copy from django.utils import timezone from utils.api._serializers import DateTimeTZField from utils.api.tests import APITestCase -from .models import ContestAnnouncement -from .models import ContestRuleType + +from .models import ContestAnnouncement, ContestRuleType DEFAULT_CONTEST_DATA = {"title": "test title", "description": "test description", "start_time": timezone.localtime(timezone.now()), diff --git a/contest/views/admin.py b/contest/views/admin.py index 4f479cc5..60bb161e 100644 --- a/contest/views/admin.py +++ b/contest/views/admin.py @@ -1,6 +1,7 @@ import dateutil.parser from utils.api import APIView, validate_serializer + from ..models import Contest, ContestAnnouncement from ..serializers import (ContestAnnouncementSerializer, ContestSerializer, CreateConetestSeriaizer, diff --git a/deploy/requirements.txt b/deploy/requirements.txt index 308698b3..3d8bf5ad 100644 --- a/deploy/requirements.txt +++ b/deploy/requirements.txt @@ -9,4 +9,5 @@ coverage python-dateutil celery Envelopes -qrcode \ No newline at end of file +qrcode +flake8-coding diff --git a/fps/parser.py b/fps/parser.py index 73bca86e..bca71b79 100644 --- a/fps/parser.py +++ b/fps/parser.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import copy import base64 +import copy import random import string import xml.etree.ElementTree as ET diff --git a/oj/local_settings.py b/oj/local_settings.py index 902ca258..79dc44e4 100644 --- a/oj/local_settings.py +++ b/oj/local_settings.py @@ -7,11 +7,6 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - }, - # submission 的 name 和 engine 请勿修改,其他代码会用到 - 'submission': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db1.sqlite3'), } } @@ -33,3 +28,4 @@ ALLOWED_HOSTS = ["*"] TEST_CASE_DIR = "/tmp" +LOG_PATH = "log/" diff --git a/oj/server_settings.py b/oj/server_settings.py index e26eefa6..7434ee70 100644 --- a/oj/server_settings.py +++ b/oj/server_settings.py @@ -12,15 +12,6 @@ DATABASES = { 'PORT': 3306, 'USER': os.environ["MYSQL_ENV_MYSQL_USER"], 'PASSWORD': os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"] - }, - 'submission': { - 'NAME': 'oj_submission', - 'ENGINE': 'django.db.backends.mysql', - 'CONN_MAX_AGE': 0.1, - 'HOST': os.environ["MYSQL_PORT_3306_TCP_ADDR"], - 'PORT': 3306, - 'USER': os.environ["MYSQL_ENV_MYSQL_USER"], - 'PASSWORD': os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"] } } @@ -43,3 +34,4 @@ ALLOWED_HOSTS = ['*'] TEST_CASE_DIR = "/test_case" +LOG_PATH = "log/" diff --git a/oj/settings.py b/oj/settings.py index 9e23a7be..e7199d92 100644 --- a/oj/settings.py +++ b/oj/settings.py @@ -104,8 +104,6 @@ STATIC_URL = '/static/' AUTH_USER_MODEL = 'account.User' -LOG_PATH = "log/" - LOGGING = { 'version': 1, 'disable_existing_loggers': True, @@ -118,13 +116,13 @@ LOGGING = { 'django_error': { 'level': 'DEBUG', 'class': 'logging.handlers.RotatingFileHandler', - 'filename': LOG_PATH + 'django.log', + 'filename': os.path.join(LOG_PATH, 'django.log'), 'formatter': 'standard' }, 'app_info': { 'level': 'DEBUG', 'class': 'logging.handlers.RotatingFileHandler', - 'filename': LOG_PATH + 'app_info.log', + 'filename': os.path.join(LOG_PATH, 'app_info.log'), 'formatter': 'standard' }, 'console': { @@ -152,17 +150,13 @@ LOGGING = { }, } -if DEBUG: - REST_FRAMEWORK = { - 'TEST_REQUEST_DEFAULT_FORMAT': 'json' - } -else: - REST_FRAMEWORK = { - 'TEST_REQUEST_DEFAULT_FORMAT': 'json', - 'DEFAULT_RENDERER_CLASSES': ( - 'rest_framework.renderers.JSONRenderer', - ) - } + +REST_FRAMEWORK = { + 'TEST_REQUEST_DEFAULT_FORMAT': 'json', + 'DEFAULT_RENDERER_CLASSES': ( + 'rest_framework.renderers.JSONRenderer', + ) +} # for celery BROKER_URL = 'redis://%s:%s/%s' % (REDIS_QUEUE["host"], str(REDIS_QUEUE["port"]), str(REDIS_QUEUE["db"])) diff --git a/problem/tests.py b/problem/tests.py index aa70af9a..d80262ae 100644 --- a/problem/tests.py +++ b/problem/tests.py @@ -6,6 +6,7 @@ from zipfile import ZipFile from django.conf import settings from utils.api.tests import APITestCase + from .models import ProblemTag from .views.admin import TestCaseUploadAPI diff --git a/problem/urls/admin.py b/problem/urls/admin.py index 7ea423e8..b4813c5b 100644 --- a/problem/urls/admin.py +++ b/problem/urls/admin.py @@ -1,6 +1,6 @@ from django.conf.urls import url -from ..views.admin import ProblemAPI, TestCaseUploadAPI, ContestProblemAPI +from ..views.admin import ContestProblemAPI, ProblemAPI, TestCaseUploadAPI urlpatterns = [ url(r"^test_case/upload/?$", TestCaseUploadAPI.as_view(), name="test_case_upload_api"), diff --git a/problem/views/admin.py b/problem/views/admin.py index 9e306d67..ad818adb 100644 --- a/problem/views/admin.py +++ b/problem/views/admin.py @@ -10,9 +10,10 @@ from contest.models import Contest from utils.api import APIView, CSRFExemptAPIView, validate_serializer from utils.shortcuts import rand_str -from ..models import Problem, ProblemRuleType, ProblemTag, ContestProblem -from ..serializers import (CreateProblemSerializer, EditProblemSerializer, - ProblemSerializer, TestCaseUploadForm, CreateContestProblemSerializer) +from ..models import ContestProblem, Problem, ProblemRuleType, ProblemTag +from ..serializers import (CreateContestProblemSerializer, + CreateProblemSerializer, EditProblemSerializer, + ProblemSerializer, TestCaseUploadForm) class TestCaseUploadAPI(CSRFExemptAPIView): diff --git a/run_test.py b/run_test.py index 17e23d6b..8358f121 100644 --- a/run_test.py +++ b/run_test.py @@ -1,12 +1,11 @@ -import sys import getopt import os +import sys opts, args = getopt.getopt(sys.argv[1:], "cm:", ["coverage=", "module="]) is_coverage = False test_module = "" -waf_addr = "127.0.0.1:50001" setting = "oj.settings" for opt, arg in opts: diff --git a/utils/mail.py b/utils/mail.py index 6ff7e7d4..6efcc330 100644 --- a/utils/mail.py +++ b/utils/mail.py @@ -1,6 +1,3 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - from envelopes import Envelope from conf.models import SMTPConfig