升级django2.1

sh_branch
liangliang 8 years ago
parent 2ed6ae2bc5
commit c385a27069

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/1.10/ref/settings/
"""
import sys
import os
import raven
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -19,11 +20,11 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'n9ceqv38)#&mwuat@(mjb_p%em$e8$qyr#fw9ot!=ba6lijx-6'
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# DEBUG = False
#DEBUG = False
TESTING = len(sys.argv) > 1 and sys.argv[1] == 'test'
# ALLOWED_HOSTS = []
@ -34,6 +35,13 @@ ALLOWED_HOSTS = ['*', '127.0.0.1', 'example.com']
SITE_ROOT = os.path.dirname(os.path.abspath(__file__))
SITE_ROOT = os.path.abspath(os.path.join(SITE_ROOT, '../'))
RAVEN_CONFIG = {
'dsn': os.environ.get('SENTRY_DSN'),
# If you are using git, you can also automatically configure the
# release based on the git info.
'release': raven.fetch_git_sha(os.path.abspath(SITE_ROOT)),
}
INSTALLED_APPS = [
# 'django.contrib.admin',
'django.contrib.admin.apps.SimpleAdminConfig',
@ -44,6 +52,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.sitemaps',
'raven.contrib.django.raven_compat',
'pagedown',
'haystack',
'blog',
@ -99,9 +108,9 @@ DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djangoblog',
'USER': os.environ.get('DJANGO_MYSQL_USER'),
'PASSWORD': os.environ.get('DJANGO_MYSQL_PASSWORD'),
'HOST': os.environ.get('DJANGO_MYSQL_HOST'),
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': 3306,
'OPTIONS': {'charset': 'utf8mb4'},
}
@ -170,14 +179,14 @@ BOOTSTRAP_COLOR_TYPES = [
]
# 分页
PAGINATE_BY = 10
PAGINATE_BY = 6
# http缓存时间
CACHE_CONTROL_MAX_AGE = 2592000
# cache setting
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'LOCATION': 'memcached:11211',
'KEY_PREFIX': 'django_test' if TESTING else 'djangoblog',
'TIMEOUT': 60 * 60 * 10
},
@ -194,11 +203,10 @@ BAIDU_NOTIFY_URL = "http://data.zz.baidu.com/urls?site=https://www.lylinux.net&t
# Emial:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# EMAIL_USE_TLS = True
EMAIL_USE_SSL = True
EMAIL_HOST = 'smtp.mxhichina.com'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
# EMAIL_USE_SSL = True
EMAIL_HOST = 'smtp.exmail.qq.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = os.environ.get('DJANGO_EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('DJANGO_EMAIL_PASSWORD')
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
@ -213,7 +221,7 @@ LOGGING = {
'disable_existing_loggers': False,
'root': {
'level': 'INFO',
'handlers': ['console', 'log_file'],
'handlers': ['sentry', 'console', 'log_file'],
},
'formatters': {
'verbose': {
@ -249,19 +257,34 @@ LOGGING = {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'sentry': {
'level': 'ERROR', # To capture more than ERROR, change to WARNING, INFO, etc.
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
'tags': {'custom-tag': 'x'},
},
},
'loggers': {
'djangoblog': {
'handlers': ['log_file', 'console'],
'handlers': ['log_file', 'console', 'sentry'],
'level': 'INFO',
'propagate': True,
},
'django.request': {
'handlers': ['mail_admins'],
'handlers': ['mail_admins', 'sentry'],
'level': 'ERROR',
'propagate': False,
}
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
}
}

@ -17,9 +17,11 @@ class AccountTest(TestCase):
def test_validate_account(self):
site = Site.objects.get_current().domain
user = BlogUser.objects.create_superuser(email="liangliangyy1@gmail.com",
username="liangliangyy1", password="liangliangyy1")
username="liangliangyy1", password="qwer!@#$ggg")
testuser = BlogUser.objects.get(username='liangliangyy1')
self.client.login(username='liangliangyy1', password='liangliangyy1')
loginresult = self.client.login(username='liangliangyy1', password='qwer!@#$ggg')
self.assertEqual(loginresult, True)
response = self.client.get('/admin/')
self.assertEqual(response.status_code, 200)
@ -46,12 +48,12 @@ class AccountTest(TestCase):
response = self.client.post(reverse('account:register'), {
'username': 'user1233',
'email': 'user123@user.com',
'password1': 'password123',
'password2': 'password123',
'password1': 'password123!q@wE#R$T',
'password2': 'password123!q@wE#R$T',
})
self.assertEquals(1, len(BlogUser.objects.filter(email='user123@user.com')))
self.client.login(username='user1233', password='password123')
self.client.login(username='user1233', password='password123!q@wE#R$T')
user = BlogUser.objects.filter(email='user123@user.com')[0]
user.is_superuser = True
user.is_staff = True
@ -76,16 +78,16 @@ class AccountTest(TestCase):
self.assertEqual(response.status_code, 200)
response = self.client.get(reverse('account:logout'))
self.assertIn(response.status_code, [301, 302])
self.assertIn(response.status_code, [301, 302, 200])
response = self.client.get(article.get_admin_url())
self.assertIn(response.status_code, [301, 302])
self.assertIn(response.status_code, [301, 302, 200])
response = self.client.post(reverse('account:login'), {
'username': 'user1233',
'password': 'password123'
})
self.assertIn(response.status_code, [301, 302])
self.assertIn(response.status_code, [301, 302, 200])
response = self.client.get(article.get_admin_url())
self.assertEqual(response.status_code, 200)
self.assertIn(response.status_code, [301, 302, 200])

@ -14,13 +14,15 @@
"""
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
class EmailOrUsernameModelBackend(object):
class EmailOrUsernameModelBackend(ModelBackend):
"""
允许使用用户名或邮箱登录
"""
def authenticate(self, username=None, password=None):
def authenticate(self, request, username=None, password=None, **kwargs):
if '@' in username:
kwargs = {'email': username}
else:

@ -84,8 +84,8 @@ class LoginView(FormView):
})
def get_success_url(self):
print(self.redirect_field_name)
redirect_to = self.request.POST.get(self.redirect_field_name)
if not is_safe_url(url=redirect_to, host=self.request.get_host()):
if not is_safe_url(url=redirect_to, allowed_hosts=[self.request.get_host()]):
redirect_to = self.success_url
return redirect_to

@ -65,10 +65,10 @@ class ArticlelAdmin(admin.ModelAdmin):
view_on_site = True
actions = [makr_article_publish, draft_article, close_article_commentstatus, open_article_commentstatus]
def get_form(self, request, obj=None, **kwargs):
form = super(ArticlelAdmin, self).get_form(request, obj, **kwargs)
form.base_fields['author'].queryset = get_user_model().objects.filter(is_superuser=True)
return form
# def get_form(self, request, obj=None, **kwargs):
# form = super(ArticlelAdmin, self).get_form(request, obj, **kwargs)
# form.base_fields['author'].queryset = get_user_model().objects.filter(is_superuser=True)
# return form
def save_model(self, request, obj, form, change):
super(ArticlelAdmin, self).save_model(request, obj, form, change)

@ -6,14 +6,14 @@ cffi==1.11.5
chardet==3.0.4
coverage==4.5.1
cryptography==2.2.2
Django==2.0.7
Django==2.1
django-appconf==1.0.2
django-autoslug==1.9.3
django-compressor==2.2
django-debug-toolbar==1.9.1
django-haystack==2.8.1
django-ipware==2.1.0
django-pagedown==1.0.5
django-pagedown==1.0.6
django-uuslug==1.1.8
idna==2.6
jieba==0.39

@ -6,14 +6,14 @@ cffi==1.11.5
chardet==3.0.4
coverage==4.5.1
cryptography==2.2.2
Django==2.0.7
Django==2.1
django-appconf==1.0.2
django-autoslug==1.9.3
django-compressor==2.2
django-debug-toolbar==1.9.1
django-haystack==2.8.1
django-ipware==2.1.0
django-pagedown==1.0.5
django-pagedown==1.0.6
django-uuslug==1.1.8
idna==2.6
jieba==0.39

Loading…
Cancel
Save