Skip to content

Commit

Permalink
Merge e9abb0e into cc40b02
Browse files Browse the repository at this point in the history
  • Loading branch information
liangliangyy committed Dec 22, 2017
2 parents cc40b02 + e9abb0e commit 5c65ef1
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DjangoBlog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
SITE_NAME = '且听风吟'
SITE_URL = 'http://www.lylinux.net'
SITE_DESCRIPTION = '大巧无工,重剑无锋.'
SITE_SEO_DESCRIPTION = '小站主要用来分享和记录学习经验,教程,记录个人生活的点滴以及一些随笔.欢迎大家访问小站'
SITE_SEO_DESCRIPTION = '小站主要用来分享和记录学习经验,教程,记录个人生活的点滴以及一些随笔.'
SITE_SEO_KEYWORDS = 'linux,apache,mysql,服务器,ubuntu,shell,web,csharp,.net,asp,mac,swift,python,django'
ARTICLE_SUB_LENGTH = 300
SHOW_GOOGLE_ADSENSE = False
Expand Down
7 changes: 5 additions & 2 deletions DjangoBlog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ def test_utils(self):
}
data = parse_dict_to_url(d)
self.assertIsNotNone(data)


render = BlogMarkDownRenderer()
s = render.autolink('http://www.baidu.com')
self.assertTrue(s.find('nofollow') > 0)
s = render.link('http://www.baidu.com', 'test', 'test')
self.assertTrue(s.find('nofollow') > 0)
35 changes: 35 additions & 0 deletions blog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django import forms
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse


class ArticleListFilter(admin.SimpleListFilter):
Expand Down Expand Up @@ -33,13 +34,38 @@ class Meta:
fields = '__all__'


def makr_article_publish(modeladmin, request, queryset):
queryset.update(status='p')


def draft_article(modeladmin, request, queryset):
queryset.update(status='d')


def close_article_commentstatus(modeladmin, request, queryset):
queryset.update(comment_status='c')


def open_article_commentstatus(modeladmin, request, queryset):
queryset.update(comment_status='o')


makr_article_publish.short_description = '发布选中文章'
draft_article.short_description = '选中文章设置为草稿'
close_article_commentstatus.short_description = '关闭文章评论'
open_article_commentstatus.short_description = '打开文章评论'


class ArticlelAdmin(admin.ModelAdmin):
search_fields = ('body',)
form = ArticleForm
list_display = ('id', 'title', 'author', 'created_time', 'views', 'status', 'type')
list_display_links = ('id', 'title')
list_filter = (ArticleListFilter, 'status', 'type', 'category', 'tags')
filter_horizontal = ('tags',)
exclude = ('slug', 'created_time', 'last_mod_time')
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)
Expand All @@ -51,6 +77,15 @@ def save_model(self, request, obj, form, change):
from DjangoBlog.utils import cache
cache.clear()

def get_view_on_site_url(self, obj=None):
if obj:
url = obj.get_full_url()
return url
else:
from django.contrib.sites.models import Site
site = Site.objects.get_current().domain
return site


class TagAdmin(admin.ModelAdmin):
exclude = ('slug', 'last_mod_time', 'created_time')
Expand Down
2 changes: 1 addition & 1 deletion blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def comment_list(self):
logger.info('get article comments:{id}'.format(id=self.id))
return value
else:
comments = self.comment_set.all()
comments = self.comment_set.filter(is_enable=True)
cache.set(cache_key, comments)
logger.info('set article comments:{id}'.format(id=self.id))
return comments
Expand Down
2 changes: 1 addition & 1 deletion blog/templatetags/blog_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def load_sidebar(user):
most_read_articles = Article.objects.filter(status='p').order_by('-views')[:settings.SIDEBAR_ARTICLE_COUNT]
dates = Article.objects.datetimes('created_time', 'month', order='DESC')
links = Links.objects.all()
commment_list = Comment.objects.order_by('-id')[:settings.SIDEBAR_COMMENT_COUNT]
commment_list = Comment.objects.filter(is_enable=True).order_by('-id')[:settings.SIDEBAR_COMMENT_COUNT]
show_adsense = settings.SHOW_GOOGLE_ADSENSE
# 标签云 计算字体大小
# 根据总数计算出平均值 大小为 (数目/平均值)*步长
Expand Down
17 changes: 15 additions & 2 deletions comments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
from .models import Comment


def disable_commentstatus(modeladmin, request, queryset):
queryset.update(is_enable=False)


def enable_commentstatus(modeladmin, request, queryset):
queryset.update(is_enable=True)


disable_commentstatus.short_description = '禁用评论'
enable_commentstatus.short_description = '启用评论'


class CommentAdmin(admin.ModelAdmin):
list_display = ('id', 'body', 'author', 'article', 'last_mod_time')
list_display = ('id', 'body', 'author', 'is_enable', 'article', 'last_mod_time')
list_display_links = ('id', 'body')
list_filter = ('author', 'article',)
list_filter = ('author', 'article', 'is_enable')
exclude = ('created_time', 'last_mod_time')
actions = [disable_commentstatus, enable_commentstatus]


admin.site.register(Comment, CommentAdmin)
1 change: 1 addition & 0 deletions comments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Comment(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='作者', on_delete=models.CASCADE)
article = models.ForeignKey(Article, verbose_name='文章', on_delete=models.CASCADE)
parent_comment = models.ForeignKey('self', verbose_name="上级评论", blank=True, null=True)
is_enable = models.BooleanField('是否显示', default=True, blank=False, null=False)

class Meta:
ordering = ['created_time']
Expand Down
2 changes: 1 addition & 1 deletion comments/templatetags/comments_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def parse_commenttree(commentlist, comment):
datas = []

def parse(c):
childs = commentlist.filter(parent_comment=c)
childs = commentlist.filter(parent_comment=c, is_enable=True)
for child in childs:
datas.append(child)
parse(child)
Expand Down

0 comments on commit 5c65ef1

Please sign in to comment.