Skip to content

Commit 5762f49

Browse files
authored
Merge pull request liangliangyy#206 from liangliangyy/dev
升级依赖
2 parents b4e7661 + 3071aeb commit 5762f49

File tree

4 files changed

+70
-25
lines changed

4 files changed

+70
-25
lines changed

DjangoBlog/utils.py

+25
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ def news(*args, **kwargs):
7070

7171

7272
def expire_view_cache(path, servername, serverport, key_prefix=None):
73+
'''
74+
刷新视图缓存
75+
:param path:url路径
76+
:param servername:host
77+
:param serverport:端口
78+
:param key_prefix:前缀
79+
:return:是否成功
80+
'''
7381
from django.http import HttpRequest
7482
from django.utils.cache import get_cache_key
7583

@@ -87,6 +95,14 @@ def expire_view_cache(path, servername, serverport, key_prefix=None):
8795

8896

8997
def block_code(text, lang, inlinestyles=False, linenos=False):
98+
'''
99+
markdown代码高亮
100+
:param text:
101+
:param lang:
102+
:param inlinestyles:
103+
:param linenos:
104+
:return:
105+
'''
90106
if not lang:
91107
text = text.strip()
92108
return u'<pre><code>%s</code></pre>\n' % mistune.escape(text)
@@ -113,6 +129,10 @@ def get_current_site():
113129

114130

115131
class BlogMarkDownRenderer(mistune.Renderer):
132+
'''
133+
markdown渲染
134+
'''
135+
116136
def block_code(self, text, lang=None):
117137
# renderer has an options
118138
inlinestyles = self.options.get('inlinestyles')
@@ -191,6 +211,11 @@ def get_blog_setting():
191211

192212

193213
def save_user_avatar(url):
214+
'''
215+
保存用户头像
216+
:param url:头像url
217+
:return: 本地路径
218+
'''
194219
setting = get_blog_setting()
195220
logger.info(url)
196221
try:

blog/views.py

+33-13
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def get_queryset_data(self):
5454
raise NotImplementedError()
5555

5656
def get_queryset_from_cache(self, cache_key):
57-
# raise NotImplementedError()
57+
'''
58+
缓存页面数据
59+
:param cache_key: 缓存key
60+
:return:
61+
'''
5862
value = cache.get(cache_key)
5963
if value:
6064
logger.info('get view cache.key:{key}'.format(key=cache_key))
@@ -66,6 +70,10 @@ def get_queryset_from_cache(self, cache_key):
6670
return article_list
6771

6872
def get_queryset(self):
73+
'''
74+
重写默认,从缓存获取数据
75+
:return:
76+
'''
6977
key = self.get_queryset_cache_key()
7078
value = self.get_queryset_from_cache(key)
7179
return value
@@ -76,6 +84,9 @@ def get_context_data(self, **kwargs):
7684

7785

7886
class IndexView(ArticleListView):
87+
'''
88+
首页
89+
'''
7990
link_type = 'i'
8091

8192
def get_queryset_data(self):
@@ -88,6 +99,9 @@ def get_queryset_cache_key(self):
8899

89100

90101
class ArticleDetailView(DetailView):
102+
'''
103+
文章详情页面
104+
'''
91105
template_name = 'blog/article_detail.html'
92106
model = Article
93107
pk_url_kwarg = 'article_id'
@@ -103,7 +117,7 @@ def get_context_data(self, **kwargs):
103117
articleid = int(self.kwargs[self.pk_url_kwarg])
104118
comment_form = CommentForm()
105119
user = self.request.user
106-
120+
# 如果用户已经登录,则隐藏邮件和用户名输入框
107121
if user.is_authenticated and not user.is_anonymous and user.email and user.username:
108122
comment_form.fields.update({
109123
'email': forms.CharField(widget=forms.HiddenInput()),
@@ -125,6 +139,9 @@ def get_context_data(self, **kwargs):
125139

126140

127141
class CategoryDetailView(ArticleListView):
142+
'''
143+
分类目录列表
144+
'''
128145
page_type = "分类目录归档"
129146

130147
def get_queryset_data(self):
@@ -158,6 +175,9 @@ def get_context_data(self, **kwargs):
158175

159176

160177
class AuthorDetailView(ArticleListView):
178+
'''
179+
作者详情页
180+
'''
161181
page_type = '作者文章归档'
162182

163183
def get_queryset_cache_key(self):
@@ -177,18 +197,10 @@ def get_context_data(self, **kwargs):
177197
return super(AuthorDetailView, self).get_context_data(**kwargs)
178198

179199

180-
class TagListView(ListView):
181-
template_name = ''
182-
context_object_name = 'tag_list'
183-
184-
def get_queryset(self):
185-
tags_list = []
186-
tags = Tag.objects.all()
187-
for t in tags:
188-
t.article_set.count()
189-
190-
191200
class TagDetailView(ArticleListView):
201+
'''
202+
标签列表页面
203+
'''
192204
page_type = '分类标签归档'
193205

194206
def get_queryset_data(self):
@@ -216,6 +228,9 @@ def get_context_data(self, **kwargs):
216228

217229

218230
class ArchivesView(ArticleListView):
231+
'''
232+
文章归档页面
233+
'''
219234
page_type = '文章归档'
220235
paginate_by = None
221236
page_kwarg = None
@@ -231,6 +246,11 @@ def get_queryset_cache_key(self):
231246

232247
@csrf_exempt
233248
def fileupload(request):
249+
'''
250+
该方法需自己写调用端来上传图片,该方法仅提供图床功能
251+
:param request:
252+
:return:
253+
'''
234254
if request.method == 'POST':
235255
sign = request.GET.get('sign', None)
236256
if not sign:

requirements.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ certifi==2018.11.29
66
cffi==1.11.5
77
chardet==3.0.4
88
coverage==4.5.2
9-
cryptography==2.4.2
9+
cryptography==2.5
1010
Django==2.1.5
1111
django-appconf==1.0.2
12-
django-autoslug==1.9.3
12+
django-autoslug==1.9.4
1313
django-compressor==2.2
1414
django-debug-toolbar==1.11
1515
django-haystack==2.8.1
@@ -19,19 +19,19 @@ django-uuslug==1.1.8
1919
idna==2.8
2020
isort==4.3.4
2121
jieba==0.39
22-
jsonpickle==1.0
22+
jsonpickle==1.1
2323
lazy-object-proxy==1.3.1
2424
markdown2==2.3.7
2525
mccabe==0.6.1
2626
mistune==0.8.4
2727
olefile==0.46
28-
packaging==18.0
28+
packaging==19.0
2929
Pillow==5.4.1
3030
pycparser==2.19
3131
Pygments==2.3.1
3232
pylint==2.2.2
3333
PyMySQL==0.9.3
34-
pyparsing==2.3.0
34+
pyparsing==2.3.1
3535
python-memcached==1.59
3636
python-slugify==2.0.1
3737
pytz==2018.9
@@ -46,5 +46,5 @@ urllib3==1.24.1
4646
webencodings==0.5.1
4747
WeRoBot==1.7.0
4848
Whoosh==2.7.4
49-
wrapt==1.11.0
49+
wrapt==1.11.1
5050
xmltodict==0.11.0

travis_test/requirements.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ certifi==2018.11.29
66
cffi==1.11.5
77
chardet==3.0.4
88
coverage==4.5.2
9-
cryptography==2.4.2
9+
cryptography==2.5
1010
Django==2.1.5
1111
django-appconf==1.0.2
12-
django-autoslug==1.9.3
12+
django-autoslug==1.9.4
1313
django-compressor==2.2
1414
django-debug-toolbar==1.11
1515
django-haystack==2.8.1
@@ -19,19 +19,19 @@ django-uuslug==1.1.8
1919
idna==2.8
2020
isort==4.3.4
2121
jieba==0.39
22-
jsonpickle==1.0
22+
jsonpickle==1.1
2323
lazy-object-proxy==1.3.1
2424
markdown2==2.3.7
2525
mccabe==0.6.1
2626
mistune==0.8.4
2727
olefile==0.46
28-
packaging==18.0
28+
packaging==19.0
2929
Pillow==5.4.1
3030
pycparser==2.19
3131
Pygments==2.3.1
3232
pylint==2.2.2
3333
PyMySQL==0.9.3
34-
pyparsing==2.3.0
34+
pyparsing==2.3.1
3535
python-slugify==2.0.1
3636
pytz==2018.9
3737
raven==6.10.0
@@ -45,5 +45,5 @@ urllib3==1.24.1
4545
webencodings==0.5.1
4646
WeRoBot==1.7.0
4747
Whoosh==2.7.4
48-
wrapt==1.11.0
48+
wrapt==1.11.1
4949
xmltodict==0.11.0

0 commit comments

Comments
 (0)