Skip to content

Commit 9d41401

Browse files
committed
1 parent 478719c commit 9d41401

38 files changed

+54
-49
lines changed

DjangoBlog/blog_signals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: blog_signals.py
1313
@time: 2017/8/12 上午10:18

DjangoBlog/feeds.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: feed.py
1313
@time: 2016/12/22 下午10:16

DjangoBlog/sitemap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: sitemap.py
1313
@time: 2016/12/15 下午10:26

DjangoBlog/spider_notify.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: spider_notify.py
1313
@time: 2017/1/15 下午1:41

DjangoBlog/tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_utils(self):
3636
import os
3737
```
3838
39-
[url](https://www.lylinux.org/)
39+
[url](https://www.lylinux.net/)
4040
4141
[ddd](http://www.baidu.com)
4242

DjangoBlog/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: utils.py
1313
@time: 2017/1/19 上午2:30

accounts/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: forms.py
1313
@time: 2016/11/20 下午3:16

accounts/templatetags/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: __init__.py
1313
@time: 2016/11/2 下午9:15

accounts/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: urls.py
1313
@time: 2016/11/20 下午3:52

accounts/user_login_backend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: user_login_backend.py
1313
@time: 2017/2/17 下午8:45

blog/context_processors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: context_processors.py
1313
@time: 2016/11/6 下午4:23

blog/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: forms.py
1313
@time: 2017/1/7 上午12:36

blog/management/commands/clear_cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: clear_cache.py
1313
@time: 2017/2/17 下午10:30

blog/management/commands/create_testdata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: create_testdata.py
1313
@time: 2017/3/11 上午1:58

blog/management/commands/ping_baidu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: ping_baidu.py
1313
@time: 2017/1/17 下午15:29

blog/middleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: middleware.py
1313
@time: 2017/1/19 上午12:36

blog/search_indexes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: search_indexes.py
1313
@time: 2017/1/7 上午12:44

blog/templatetags/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: __init__.py
1313
@time: 2016/11/2 下午9:15

blog/templatetags/blog_tags.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: blog_tags.py
1313
@time: 2016/11/2 下午11:10
@@ -142,7 +142,6 @@ def load_sidebar(user, linktype):
142142
dates = Article.objects.datetimes('created_time', 'month', order='DESC')
143143
links = Links.objects.filter(is_enable=True).filter(Q(show_type=str(linktype)) | Q(show_type='a'))
144144
commment_list = Comment.objects.filter(is_enable=True).order_by('-id')[:blogsetting.sidebar_comment_count]
145-
# show_adsense = settings.SHOW_GOOGLE_ADSENSE
146145
# 标签云 计算字体大小
147146
# 根据总数计算出平均值 大小为 (数目/平均值)*步长
148147
increment = 5
@@ -151,8 +150,10 @@ def load_sidebar(user, linktype):
151150
if tags and len(tags) > 0:
152151
s = list(map(lambda t: (t, t.get_article_count()), tags))
153152
count = sum(map(lambda t: t[1], s))
154-
dd = 1 if count == 0 and not len(tags) else count / len(tags)
153+
dd = 1 if (count == 0 and not len(tags)) else count / len(tags)
154+
import random
155155
sidebar_tags = list(map(lambda x: (x[0], x[1], (x[1] / dd) * increment + 10), s))
156+
random.shuffle(sidebar_tags)
156157

157158
return {
158159
'recent_articles': recent_articles,
@@ -282,8 +283,6 @@ def gravatar_url(email, size=40):
282283
return url
283284

284285

285-
# return an image tag with the gravatar
286-
# TEMPLATE USE: {{ email|gravatar:150 }}
287286
@register.filter
288287
def gravatar(email, size=40):
289288
"""获得gravatar头像"""

blog/tests.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.test import Client, RequestFactory, TestCase
22
from blog.models import Article, Category, Tag, SideBar
33
from django.contrib.auth import get_user_model
4-
from DjangoBlog.utils import get_current_site
4+
from DjangoBlog.utils import get_current_site, get_md5
55
from blog.forms import BlogSearchForm
66
from django.core.paginator import Paginator
77
from blog.templatetags.blog_tags import load_pagination_info, load_articletags
@@ -156,10 +156,13 @@ def test_image(self):
156156
imagepath = os.path.join(settings.BASE_DIR, 'python.png')
157157
with open(imagepath, 'wb') as file:
158158
file.write(rsp.content)
159+
rsp = self.client.post('/upload')
160+
self.assertEqual(rsp.status_code, 403)
161+
sign = get_md5(get_md5(settings.SECRET_KEY))
159162
with open(imagepath, 'rb') as file:
160163
imgfile = SimpleUploadedFile('python.png', file.read(), content_type='image/jpg')
161164
form_data = {'python.png': imgfile}
162-
rsp = self.client.post('/upload', form_data, follow=True)
165+
rsp = self.client.post('/upload?sign=' + sign, form_data, follow=True)
163166

164167
self.assertEqual(rsp.status_code, 200)
165168
from DjangoBlog.utils import save_user_avatar, send_email

blog/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: urls.py
1313
@time: 2016/11/2 下午7:15

blog/views.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
from django.views.generic.detail import DetailView
88
from django.conf import settings
99
from django import forms
10-
from django.http import HttpResponse
11-
from django.http import HttpResponseRedirect
10+
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
1211
from django.views.decorators.csrf import csrf_exempt
1312
from django.contrib.auth.decorators import login_required
14-
from DjangoBlog.utils import cache
13+
from DjangoBlog.utils import cache, get_md5, get_blog_setting
1514
from django.shortcuts import get_object_or_404
1615
from blog.models import Article, Category, Tag
1716
from comments.forms import CommentForm
@@ -233,16 +232,21 @@ def get_queryset_cache_key(self):
233232
@csrf_exempt
234233
def fileupload(request):
235234
if request.method == 'POST':
235+
sign = request.GET.get('sign', None)
236+
if not sign:
237+
return HttpResponseForbidden()
238+
if not sign == get_md5(get_md5(settings.SECRET_KEY)):
239+
return HttpResponseForbidden()
236240
response = []
237241
for filename in request.FILES:
238242
timestr = datetime.datetime.now().strftime('%Y/%m/%d')
239243
imgextensions = ['jpg', 'png', 'jpeg', 'bmp']
240244
fname = u''.join(str(filename))
241-
242245
isimage = len([i for i in imgextensions if fname.find(i) >= 0]) > 0
246+
blogsetting = get_blog_setting()
243247

244-
basepath = r'/var/www/resource/{type}/{timestr}'.format(
245-
type='files' if not isimage else 'image', timestr=timestr)
248+
basepath = r'{basedir}/{type}/{timestr}'.format(basedir=blogsetting.resource_path,
249+
type='files' if not isimage else 'image', timestr=timestr)
246250
if settings.TESTING:
247251
basepath = settings.BASE_DIR + '/uploads'
248252
url = 'https://resource.lylinux.net/{type}/{timestr}/{filename}'.format(
@@ -274,7 +278,6 @@ def refresh_memcache(request):
274278
cache.clear()
275279
return HttpResponse("ok")
276280
else:
277-
from django.http import HttpResponseForbidden
278281
return HttpResponseForbidden()
279282
except Exception as e:
280283
logger.error(e)

comments/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: forms.py
1313
@time: 2016/11/12 下午2:45

comments/templatetags/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: __init__.py
1313
@time: 2016/11/2 下午9:15

comments/templatetags/comments_tags.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: comments_tags.py
1313
@time: 2016/11/2 下午9:17

comments/tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_validate_comment(self):
7272
import os
7373
```
7474
75-
[url](https://www.lylinux.org/)
75+
[url](https://www.lylinux.net/)
7676
7777
[ddd](http://www.baidu.com)
7878

comments/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: urls.py
1313
@time: 2016/11/12 下午3:03

oauth/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: forms.py
1313
@time: 2017/3/7 下午8:58

oauth/oauthmanager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: oauthmanager.py
1313
@time: 2016/11/26 下午5:09

oauth/templatetags/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: __init__.py
1313
@time: 2017/3/4 下午3:22

oauth/templatetags/oauth_tags.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: oauth_tags.py
1313
@time: 2017/3/4 下午3:22

oauth/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: urls.py
1313
@time: 2016/11/26 下午5:25

servermanager/Api/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: __init__.py.py
1313
@time: 2017/8/27 上午11:40

servermanager/Api/blogapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: blogapi.py
1313
@time: 2017/8/27 上午11:40

servermanager/Api/commonapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@author: liangliangyy
88
@license: MIT Licence
99
10-
@site: https://www.lylinux.org/
10+
@site: https://www.lylinux.net/
1111
@software: PyCharm
1212
@file: commonapi.py
1313
@time: 2017/9/2 上午1:43

0 commit comments

Comments
 (0)