diff --git a/.gitignore b/.gitignore index 8707498f..a3159d42 100644 --- a/.gitignore +++ b/.gitignore @@ -63,4 +63,5 @@ build.txt tmp/ test_case/ release/ -upload/ \ No newline at end of file +upload/ +custom_settings.py \ No newline at end of file diff --git a/account/views.py b/account/views.py index 9c41b349..cf31b158 100644 --- a/account/views.py +++ b/account/views.py @@ -43,7 +43,6 @@ class UserLoginAPIView(APIView): serializer = UserLoginSerializer(data=request.data) if serializer.is_valid(): data = serializer.data - print data user = auth.authenticate(username=data["username"], password=data["password"]) # 用户名或密码错误的话 返回None if user: diff --git a/oj/custom_settings.example.py b/oj/custom_settings.example.py new file mode 100644 index 00000000..a1d10903 --- /dev/null +++ b/oj/custom_settings.example.py @@ -0,0 +1,17 @@ +# coding=utf-8 +import os + +SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + +SSO = {"callback": "https://xxxxxxxxx/login"} + +WEBSITE_INFO = {"website_name": u"xx大学 OnlineJudge", + "website_name_shortcut": u"qduoj", + "website_footer": u"xx大学xx学院京ICP备xxxxx号-1", + "url": u"https://your-domain.com"} + + +SMTP_CONFIG = {"smtp_server": "smtp.xxx.com", + "email": "noreply@xxx.com", + "password": os.environ.get("smtp_password", "111111"), + "tls": False} diff --git a/oj/local_settings.py b/oj/local_settings.py index 31f5b407..77b1bcae 100644 --- a/oj/local_settings.py +++ b/oj/local_settings.py @@ -3,7 +3,6 @@ import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -# 注意这是web 服务器访问的地址,判题端访问的地址不一定一样,因为可能不在一台机器上 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', @@ -45,15 +44,3 @@ STATICFILES_DIRS = [os.path.join(BASE_DIR, "static/src/"), BASE_DIR] # 模板文件夹 OJ_TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'template/src/')] -SSO = {"callback": "http://localhost:8765/login"} - -WEBSITE_INFO = {"website_name": "qduoj", - "website_footer": u"青岛大学信息工程学院 创新实验室 京ICP备15062075号-1", - "url": "https://qduoj.com"} - - -SMTP_CONFIG = {"smtp_server": "smtp.mxhichina.com", - "email": "noreply@qduoj.com", - "password": os.environ.get("smtp_password", "111111"), - "tls": False} - diff --git a/oj/server_settings.py b/oj/server_settings.py index bd0d3041..b09a229b 100644 --- a/oj/server_settings.py +++ b/oj/server_settings.py @@ -3,36 +3,35 @@ import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -# 注意这是web 服务器访问的地址,判题端访问的地址不一定一样,因为可能不在一台机器上 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': "oj", 'CONN_MAX_AGE': 0.1, - 'HOST': os.environ.get("MYSQL_PORT_3306_TCP_ADDR", "127.0.0.1"), + 'HOST': os.environ["MYSQL_PORT_3306_TCP_ADDR"], 'PORT': 3306, - 'USER': os.environ.get("MYSQL_ENV_MYSQL_USER", "root"), - 'PASSWORD': os.environ.get("MYSQL_ENV_MYSQL_ROOT_PASSWORD", "root") + '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.get("MYSQL_PORT_3306_TCP_ADDR", "127.0.0.1"), + 'HOST': os.environ["MYSQL_PORT_3306_TCP_ADDR"], 'PORT': 3306, - 'USER': os.environ.get("MYSQL_ENV_MYSQL_USER", "root"), - 'PASSWORD': os.environ.get("MYSQL_ENV_MYSQL_ROOT_PASSWORD", "root") + 'USER': os.environ["MYSQL_ENV_MYSQL_USER"], + 'PASSWORD': os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"] } } REDIS_CACHE = { - "host": os.environ.get("REDIS_PORT_6379_TCP_ADDR", "127.0.0.1"), + "host": os.environ["REDIS_PORT_6379_TCP_ADDR"], "port": 6379, "db": 1 } REDIS_QUEUE = { - "host": os.environ.get("REDIS_PORT_6379_TCP_ADDR", "127.0.0.1"), + "host": os.environ["REDIS_PORT_6379_TCP_ADDR"], "port": 6379, "db": 2 } @@ -54,16 +53,4 @@ STATICFILES_DIRS = [os.path.join(BASE_DIR, "static/release/"), os.path.join(BASE # 模板文件夹 OJ_TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'template/release/')] -SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') -SSO = {"callback": "https://discuss.acmer.site/login"} - -WEBSITE_INFO = {"website_name": "qduoj", - "website_footer": u"青岛大学信息工程学院 创新实验室 京ICP备15062075号-1", - "url": "https://qduoj.com"} - - -SMTP_CONFIG = {"smtp_server": "smtp.mxhichina.com", - "email": "noreply@qduoj.com", - "password": os.environ.get("smtp_password", "111111"), - "tls": False} diff --git a/oj/settings.py b/oj/settings.py index e6e53a5d..8d069668 100644 --- a/oj/settings.py +++ b/oj/settings.py @@ -22,6 +22,8 @@ if ENV == "local": elif ENV == "server": from .server_settings import * +from .custom_settings import * + import djcelery djcelery.setup_loader() @@ -31,10 +33,6 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'hzfp^8mbgapc&x%$#xv)0=t8s7_ilingw(q3!@h&2fty6v6fxz' - - # Application definition INSTALLED_APPS = ( diff --git a/submission/views.py b/submission/views.py index 8763e1e3..deb749da 100644 --- a/submission/views.py +++ b/submission/views.py @@ -180,7 +180,7 @@ def my_submission(request, submission_id): user = User.objects.get(id=submission.user_id) return render(request, "oj/submission/my_submission.html", {"submission": submission, "problem": problem, "info": info, - "user": user, "can_share": result["can_share"]}) + "user": user, "can_share": result["can_share"], "website_base_url": settings.WEBSITE_INFO["url"]}) class SubmissionAdminAPIView(APIView): diff --git a/template/src/oj/index.html b/template/src/oj/index.html index 86bf07fd..feef7b46 100644 --- a/template/src/oj/index.html +++ b/template/src/oj/index.html @@ -1,9 +1,9 @@ - +{% load website_info %} - 青岛大学在线评测平台 - 首页 + {% show_website_info "website_name" %} - 首页 @@ -125,21 +125,12 @@ loopBottom: true }); }); - - /* - var c = 0; - - setInterval(function(){ - //alert(1); - $("#section0").css("background-image", "url(/static/img/index/bg/bg" + (c++ % 4).toString() + ".jpg)") - }, 1000) - */ {% endblock %} diff --git a/tools/run.py b/tools/run.py deleted file mode 100644 index 5c73383b..00000000 --- a/tools/run.py +++ /dev/null @@ -1,61 +0,0 @@ -# coding=utf-8 -import os -import json - -os.system("docker rm -f redis") -os.system("docker rm -f mysql") -os.system("docker rm -f oj_web_server") - -if os.system("docker run --name mysql -v /root/data:/var/lib/mysql -v /root/data/my.cnf:/etc/my.cnf -e MYSQL_ROOT_PASSWORD=root -d mysql/mysql-server:latest"): - print "Error start mysql" - exit() - -if os.system("docker run --name redis -v /root/redis/:/data -d redis redis-server --appendonly yes"): - print "Error start redis" - exit() - -if os.system("docker run --name oj_web_server -e oj_env=server -v /root/qduoj:/code -v /root/test_case:/code/test_case -v /root/log:/code/log -v /root/upload:/code/upload -v /root/qduoj/dockerfiles/oj_web_server/supervisord.conf:/etc/supervisord.conf -v /root/qduoj/dockerfiles/oj_web_server/gunicorn.conf:/etc/gunicorn.conf -v /root/qduoj/dockerfiles/oj_web_server/mq.conf:/etc/mq.conf -d -p 127.0.0.1:8080:8080 --link mysql --link=redis oj_web_server"): - print "Erro start oj_web_server" - exit() - -inspect_redis = json.loads(os.popen("docker inspect redis").read()) - -if not inspect_redis: - print "Error when inspect redis ip" - exit() - -redis_ip = inspect_redis[0]["NetworkSettings"]["IPAddress"] -print "redis ip ", redis_ip - - -inspect_mysql = json.loads(os.popen("docker inspect mysql").read()) -if not inspect_mysql: - print "Error when inspect mysql ip" - exit() - -mysql_ip = inspect_mysql[0]["NetworkSettings"]["IPAddress"] -print "mysql ip ", mysql_ip - - -f = open("/etc/profile", "r") -content = "" -for line in f.readlines(): - if line.startswith("export REDIS_PORT_6379_TCP_ADDR"): - content += ("\nexport REDIS_PORT_6379_TCP_ADDR=" + redis_ip + "\n") - elif line.startswith("export submission_db_host"): - content += ("\nexport submission_db_host=" + mysql_ip + "\n") - else: - content += line - -f.close() - - -f = open("/etc/profile", "w") -f.write(content) -f.close() - -print "Please run source /etc/profile" - -os.system("ps -ef|grep celery") -print "nohup celery -A judge.judger_controller worker -l DEBUG &" -