Skip to content

Commit

Permalink
Merge pull request #206 from liangliangyy/dev
Browse files Browse the repository at this point in the history
升级依赖
  • Loading branch information
liangliangyy committed Feb 5, 2019
2 parents b4e7661 + 3071aeb commit 5762f49
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 25 deletions.
25 changes: 25 additions & 0 deletions DjangoBlog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def news(*args, **kwargs):


def expire_view_cache(path, servername, serverport, key_prefix=None):
'''
刷新视图缓存
:param path:url路径
:param servername:host
:param serverport:端口
:param key_prefix:前缀
:return:是否成功
'''
from django.http import HttpRequest
from django.utils.cache import get_cache_key

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


def block_code(text, lang, inlinestyles=False, linenos=False):
'''
markdown代码高亮
:param text:
:param lang:
:param inlinestyles:
:param linenos:
:return:
'''
if not lang:
text = text.strip()
return u'<pre><code>%s</code></pre>\n' % mistune.escape(text)
Expand All @@ -113,6 +129,10 @@ def get_current_site():


class BlogMarkDownRenderer(mistune.Renderer):
'''
markdown渲染
'''

def block_code(self, text, lang=None):
# renderer has an options
inlinestyles = self.options.get('inlinestyles')
Expand Down Expand Up @@ -191,6 +211,11 @@ def get_blog_setting():


def save_user_avatar(url):
'''
保存用户头像
:param url:头像url
:return: 本地路径
'''
setting = get_blog_setting()
logger.info(url)
try:
Expand Down
46 changes: 33 additions & 13 deletions blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def get_queryset_data(self):
raise NotImplementedError()

def get_queryset_from_cache(self, cache_key):
# raise NotImplementedError()
'''
缓存页面数据
:param cache_key: 缓存key
:return:
'''
value = cache.get(cache_key)
if value:
logger.info('get view cache.key:{key}'.format(key=cache_key))
Expand All @@ -66,6 +70,10 @@ def get_queryset_from_cache(self, cache_key):
return article_list

def get_queryset(self):
'''
重写默认,从缓存获取数据
:return:
'''
key = self.get_queryset_cache_key()
value = self.get_queryset_from_cache(key)
return value
Expand All @@ -76,6 +84,9 @@ def get_context_data(self, **kwargs):


class IndexView(ArticleListView):
'''
首页
'''
link_type = 'i'

def get_queryset_data(self):
Expand All @@ -88,6 +99,9 @@ def get_queryset_cache_key(self):


class ArticleDetailView(DetailView):
'''
文章详情页面
'''
template_name = 'blog/article_detail.html'
model = Article
pk_url_kwarg = 'article_id'
Expand All @@ -103,7 +117,7 @@ def get_context_data(self, **kwargs):
articleid = int(self.kwargs[self.pk_url_kwarg])
comment_form = CommentForm()
user = self.request.user

# 如果用户已经登录,则隐藏邮件和用户名输入框
if user.is_authenticated and not user.is_anonymous and user.email and user.username:
comment_form.fields.update({
'email': forms.CharField(widget=forms.HiddenInput()),
Expand All @@ -125,6 +139,9 @@ def get_context_data(self, **kwargs):


class CategoryDetailView(ArticleListView):
'''
分类目录列表
'''
page_type = "分类目录归档"

def get_queryset_data(self):
Expand Down Expand Up @@ -158,6 +175,9 @@ def get_context_data(self, **kwargs):


class AuthorDetailView(ArticleListView):
'''
作者详情页
'''
page_type = '作者文章归档'

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


class TagListView(ListView):
template_name = ''
context_object_name = 'tag_list'

def get_queryset(self):
tags_list = []
tags = Tag.objects.all()
for t in tags:
t.article_set.count()


class TagDetailView(ArticleListView):
'''
标签列表页面
'''
page_type = '分类标签归档'

def get_queryset_data(self):
Expand Down Expand Up @@ -216,6 +228,9 @@ def get_context_data(self, **kwargs):


class ArchivesView(ArticleListView):
'''
文章归档页面
'''
page_type = '文章归档'
paginate_by = None
page_kwarg = None
Expand All @@ -231,6 +246,11 @@ def get_queryset_cache_key(self):

@csrf_exempt
def fileupload(request):
'''
该方法需自己写调用端来上传图片,该方法仅提供图床功能
:param request:
:return:
'''
if request.method == 'POST':
sign = request.GET.get('sign', None)
if not sign:
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ certifi==2018.11.29
cffi==1.11.5
chardet==3.0.4
coverage==4.5.2
cryptography==2.4.2
cryptography==2.5
Django==2.1.5
django-appconf==1.0.2
django-autoslug==1.9.3
django-autoslug==1.9.4
django-compressor==2.2
django-debug-toolbar==1.11
django-haystack==2.8.1
Expand All @@ -19,19 +19,19 @@ django-uuslug==1.1.8
idna==2.8
isort==4.3.4
jieba==0.39
jsonpickle==1.0
jsonpickle==1.1
lazy-object-proxy==1.3.1
markdown2==2.3.7
mccabe==0.6.1
mistune==0.8.4
olefile==0.46
packaging==18.0
packaging==19.0
Pillow==5.4.1
pycparser==2.19
Pygments==2.3.1
pylint==2.2.2
PyMySQL==0.9.3
pyparsing==2.3.0
pyparsing==2.3.1
python-memcached==1.59
python-slugify==2.0.1
pytz==2018.9
Expand All @@ -46,5 +46,5 @@ urllib3==1.24.1
webencodings==0.5.1
WeRoBot==1.7.0
Whoosh==2.7.4
wrapt==1.11.0
wrapt==1.11.1
xmltodict==0.11.0
12 changes: 6 additions & 6 deletions travis_test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ certifi==2018.11.29
cffi==1.11.5
chardet==3.0.4
coverage==4.5.2
cryptography==2.4.2
cryptography==2.5
Django==2.1.5
django-appconf==1.0.2
django-autoslug==1.9.3
django-autoslug==1.9.4
django-compressor==2.2
django-debug-toolbar==1.11
django-haystack==2.8.1
Expand All @@ -19,19 +19,19 @@ django-uuslug==1.1.8
idna==2.8
isort==4.3.4
jieba==0.39
jsonpickle==1.0
jsonpickle==1.1
lazy-object-proxy==1.3.1
markdown2==2.3.7
mccabe==0.6.1
mistune==0.8.4
olefile==0.46
packaging==18.0
packaging==19.0
Pillow==5.4.1
pycparser==2.19
Pygments==2.3.1
pylint==2.2.2
PyMySQL==0.9.3
pyparsing==2.3.0
pyparsing==2.3.1
python-slugify==2.0.1
pytz==2018.9
raven==6.10.0
Expand All @@ -45,5 +45,5 @@ urllib3==1.24.1
webencodings==0.5.1
WeRoBot==1.7.0
Whoosh==2.7.4
wrapt==1.11.0
wrapt==1.11.1
xmltodict==0.11.0

0 comments on commit 5762f49

Please sign in to comment.