commit 00052d8e9ba380875955232252652effe2da1279 Author: virusdefender Date: Fri Jun 26 15:59:53 2015 +0800 创建新工程 添加了一些通用代码和数据库模型 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d6c724 --- /dev/null +++ b/.gitignore @@ -0,0 +1,58 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +# C extensions +*.so +# Distribution / packaging +.Python +env/ +bin/ +build/ +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg +# Installer logs +pip-log.txt +pip-delete-this-directory.txt +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml +# Translations +*.mo +# Mr Developer +.mr.developer.cfg +.project +.pydevproject +# Rope +.ropeproject +.idea/ +# Django stuff: +*.log +*.pot +# Sphinx documentation +docs/_build/ +# Back up file +*~ +#db file +db.db +#vim cache +*swp +*swo +#redis dump +*.rdb +#*.out +db.sqlite3 +.DS_Store +log/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/account/__init__.py b/account/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/account/admin.py b/account/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/account/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/account/migrations/__init__.py b/account/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/account/models.py b/account/models.py new file mode 100644 index 0000000..3b4bef7 --- /dev/null +++ b/account/models.py @@ -0,0 +1,15 @@ +# coding=utf-8 +from django.db import models +from django.contrib.auth.models import AbstractBaseUser + + +class AdminGroup(models.Model): + pass + + +class User(AbstractBaseUser): + username = models.CharField(max_length=30, unique=True) + admin_group = models.ForeignKey(AdminGroup, null=True, on_delete=models.SET_NULL) + + class Meta: + db_table = "user" diff --git a/account/tests.py b/account/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/account/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/account/views.py b/account/views.py new file mode 100644 index 0000000..a9ec5d8 --- /dev/null +++ b/account/views.py @@ -0,0 +1 @@ +from django.shortcuts import render \ No newline at end of file diff --git a/admin/__init__.py b/admin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/admin/admin.py b/admin/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/admin/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/admin/migrations/__init__.py b/admin/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/admin/models.py b/admin/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/admin/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/admin/tests.py b/admin/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/admin/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/admin/views.py b/admin/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/admin/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/contest/__init__.py b/contest/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/contest/admin.py b/contest/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/contest/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/contest/migrations/__init__.py b/contest/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/contest/models.py b/contest/models.py new file mode 100644 index 0000000..1088232 --- /dev/null +++ b/contest/models.py @@ -0,0 +1,8 @@ +# coding=utf-8 +from django.db import models + +from problem.models import AbstractProblem + + +class ContestProblem(AbstractProblem): + pass diff --git a/contest/tests.py b/contest/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/contest/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/contest/views.py b/contest/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/contest/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/judge/__init__.py b/judge/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/judge/admin.py b/judge/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/judge/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/judge/migrations/__init__.py b/judge/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/judge/models.py b/judge/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/judge/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/judge/tests.py b/judge/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/judge/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/judge/views.py b/judge/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/judge/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..b4ba977 --- /dev/null +++ b/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qduoj.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/problem/__init__.py b/problem/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/problem/admin.py b/problem/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/problem/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/problem/migrations/__init__.py b/problem/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/problem/models.py b/problem/models.py new file mode 100644 index 0000000..584fc24 --- /dev/null +++ b/problem/models.py @@ -0,0 +1,19 @@ +# coding=utf-8 +from django.db import models + +from account.models import User + + +class AbstractProblem(models.Model): + + class Meta: + abstract = True + + +class Problem(AbstractProblem): + pass + + +class Solution(models.Model): + user = models.ForeignKey(User) + problem = models.ForeignKey(Problem) \ No newline at end of file diff --git a/problem/tests.py b/problem/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/problem/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/problem/views.py b/problem/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/problem/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/qduoj/__init__.py b/qduoj/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/qduoj/local_settings.py b/qduoj/local_settings.py new file mode 100644 index 0000000..5e898d3 --- /dev/null +++ b/qduoj/local_settings.py @@ -0,0 +1,2 @@ +# coding=utf-8 +LOG_PATH = "LOG/" \ No newline at end of file diff --git a/qduoj/server_settings.py b/qduoj/server_settings.py new file mode 100644 index 0000000..9bad579 --- /dev/null +++ b/qduoj/server_settings.py @@ -0,0 +1 @@ +# coding=utf-8 diff --git a/qduoj/settings.py b/qduoj/settings.py new file mode 100644 index 0000000..cf9ab2d --- /dev/null +++ b/qduoj/settings.py @@ -0,0 +1,154 @@ +# coding=utf-8 +""" +Django settings for qduoj project. + +Generated by 'django-admin startproject' using Django 1.8. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.8/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +# todo 判断运行环境 +ENV = "local" + +if ENV == "local": + from .local_settings import * +else: + from .server_settings import * + +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' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django.middleware.security.SecurityMiddleware', +) + +ROOT_URLCONF = 'qduoj.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'template')], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'qduoj.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.8/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'CONN_MAX_AGE': 1, + } +} + + +# Internationalization +# https://docs.djangoproject.com/en/1.8/topics/i18n/ + +LANGUAGE_CODE = 'zh-cn' + +TIME_ZONE = 'Asia/Shanghai' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.8/howto/static-files/ + +STATIC_URL = '/static/' + +STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),) + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'formatters': { + 'standard': { + 'format': '%(asctime)s [%(threadName)s:%(thread)d] [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s'} + # 日志格式 + }, + 'handlers': { + 'file_handler': { + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', + 'filename': LOG_PATH + 'info.log', + 'formatter': 'standard' + }, + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + 'formatter': 'standard' + } + }, + 'loggers': { + 'info_logger': { + 'handlers': ['file_handler', "console"], + 'level': 'DEBUG', + 'propagate': True + }, + 'django.request': { + 'handlers': ['file_handler', 'console'], + 'level': 'DEBUG', + 'propagate': True, + }, + 'django.db.backends': { + 'handlers': ['console'], + 'level': 'DEBUG', + 'propagate': True, + } + }, +} diff --git a/qduoj/urls.py b/qduoj/urls.py new file mode 100644 index 0000000..3f06f9a --- /dev/null +++ b/qduoj/urls.py @@ -0,0 +1,12 @@ +# coding=utf-8 +from django.conf.urls import include, url +from django.contrib import admin +from django.views.generic import TemplateView + +urlpatterns = [ + # Examples: + # url(r'^$', 'qduoj.views.home', name='home'), + # url(r'^blog/', include('blog.urls')), + + url(r'^admin/', include(admin.site.urls)), +] diff --git a/qduoj/wsgi.py b/qduoj/wsgi.py new file mode 100644 index 0000000..5fe94cc --- /dev/null +++ b/qduoj/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for qduoj project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qduoj.settings") + +application = get_wsgi_application() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..21a0a19 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +django +MySQL-python +redis +django-redis-sessions +djangorestframework +celery diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000..9bad579 --- /dev/null +++ b/utils/__init__.py @@ -0,0 +1 @@ +# coding=utf-8 diff --git a/utils/shortcuts.py b/utils/shortcuts.py new file mode 100644 index 0000000..9bad579 --- /dev/null +++ b/utils/shortcuts.py @@ -0,0 +1 @@ +# coding=utf-8