Skip to content

Commit

Permalink
增加评论审核开关
Browse files Browse the repository at this point in the history
  • Loading branch information
liangliangyy committed May 9, 2023
1 parent a450de8 commit e2e5b29
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 50 deletions.
7 changes: 4 additions & 3 deletions blog/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def seo_processor(requests):
logger.info('set processor cache.')
setting = get_blog_setting()
value = {
'SITE_NAME': setting.sitename,
'SITE_NAME': setting.site_name,
'SHOW_GOOGLE_ADSENSE': setting.show_google_adsense,
'GOOGLE_ADSENSE_CODES': setting.google_adsense_codes,
'SITE_SEO_DESCRIPTION': setting.site_seo_description,
Expand All @@ -30,13 +30,14 @@ def seo_processor(requests):
type='p',
status='p'),
'OPEN_SITE_COMMENT': setting.open_site_comment,
'BEIAN_CODE': setting.beiancode,
'ANALYTICS_CODE': setting.analyticscode,
'BEIAN_CODE': setting.beian_code,
'ANALYTICS_CODE': setting.analytics_code,
"BEIAN_CODE_GONGAN": setting.gongan_beiancode,
"SHOW_GONGAN_CODE": setting.show_gongan_code,
"CURRENT_YEAR": timezone.now().year,
"GLOBAL_HEADER": setting.global_header,
"GLOBAL_FOOTER": setting.global_footer,
"COMMENT_NEED_REVIEW": setting.comment_need_review,
}
cache.set(key, value, 60 * 60 * 10)
return value
17 changes: 17 additions & 0 deletions blog/migrations/0003_blogsettings_comment_need_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.1 on 2023-05-09 07:45

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
('blog', '0002_blogsettings_global_footer_and_more'),
]

operations = [
migrations.AddField(
model_name='blogsettings',
name='comment_need_review',
field=models.BooleanField(default=False, verbose_name='评论是否需要审核'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.1 on 2023-05-09 07:51

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
('blog', '0003_blogsettings_comment_need_review'),
]

operations = [
migrations.RenameField(
model_name='blogsettings',
old_name='analyticscode',
new_name='analytics_code',
),
migrations.RenameField(
model_name='blogsettings',
old_name='beiancode',
new_name='beian_code',
),
migrations.RenameField(
model_name='blogsettings',
old_name='sitename',
new_name='site_name',
),
]
10 changes: 6 additions & 4 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def __str__(self):

class BlogSettings(models.Model):
"""blog的配置"""
sitename = models.CharField(
site_name = models.CharField(
"网站名称",
max_length=200,
null=False,
Expand Down Expand Up @@ -325,13 +325,13 @@ class BlogSettings(models.Model):
open_site_comment = models.BooleanField('是否打开网站评论功能', default=True)
global_header = models.TextField("公共头部", null=True, blank=True, default='')
global_footer = models.TextField("公共尾部", null=True, blank=True, default='')
beiancode = models.CharField(
beian_code = models.CharField(
'备案号',
max_length=2000,
null=True,
blank=True,
default='')
analyticscode = models.TextField(
analytics_code = models.TextField(
"网站统计代码",
max_length=1000,
null=False,
Expand All @@ -345,13 +345,15 @@ class BlogSettings(models.Model):
null=True,
blank=True,
default='')
comment_need_review = models.BooleanField(
'评论是否需要审核', default=False, null=False)

class Meta:
verbose_name = '网站配置'
verbose_name_plural = verbose_name

def __str__(self):
return self.sitename
return self.site_name

def clean(self):
if BlogSettings.objects.exclude(id=self.id).count():
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 @@ -88,7 +88,7 @@ def load_breadcrumb(article):
from djangoblog.utils import get_blog_setting
blogsetting = get_blog_setting()
site = get_current_site().domain
names.append((blogsetting.sitename, '/'))
names.append((blogsetting.site_name, '/'))
names = names[::-1]

return {
Expand Down
5 changes: 4 additions & 1 deletion comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def form_valid(self, form):
raise ValidationError("该文章评论已关闭.")
comment = form.save(False)
comment.article = article

from djangoblog.utils import get_blog_setting
settings = get_blog_setting()
if not settings.comment_need_review:
comment.is_enable = True
comment.author = user

if form.cleaned_data['parent_comment_id']:
Expand Down
6 changes: 3 additions & 3 deletions djangoblog/blog_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from django.db.models.signals import post_save
from django.dispatch import receiver

from comments.models import Comment
from comments.utils import send_comment_email
from djangoblog.spider_notify import SpiderNotify
from djangoblog.utils import cache, expire_view_cache, delete_sidebar_cache, delete_view_cache
from djangoblog.utils import get_current_site
from comments.models import Comment
from comments.utils import send_comment_email
from oauth.models import OAuthUser

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -107,7 +107,7 @@ def model_post_save_callback(
delete_sidebar_cache()
delete_view_cache('article_comments', [str(instance.article.pk)])

_thread.start_new(send_comment_email, (instance,))
_thread.start_new_thread(send_comment_email, (instance,))

if clearcache:
cache.clear()
Expand Down
7 changes: 4 additions & 3 deletions djangoblog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get_blog_setting():
from blog.models import BlogSettings
if not BlogSettings.objects.count():
setting = BlogSettings()
setting.sitename = 'djangoblog'
setting.site_name = 'djangoblog'
setting.site_description = '基于Django的博客系统'
setting.site_seo_description = '基于Django的博客系统'
setting.site_keywords = 'Django,Python'
Expand All @@ -161,9 +161,10 @@ def get_blog_setting():
setting.sidebar_comment_count = 5
setting.show_google_adsense = False
setting.open_site_comment = True
setting.analyticscode = ''
setting.beiancode = ''
setting.analytics_code = ''
setting.beian_code = ''
setting.show_gongan_code = False
setting.comment_need_review = False
setting.save()
value = BlogSettings.objects.first()
logger.info('set cache get_blog_setting')
Expand Down
17 changes: 8 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
coverage==7.2.2
bleach==6.0.0
Django==4.1.7
Django==4.2.1
django-compressor==4.3.1
django-haystack==3.2.1
django-ipware==5.0.0
Expand All @@ -13,16 +13,15 @@ jieba==0.42.1
jsonpickle==3.0.1
Markdown==3.4.3
mysqlclient==2.1.1
Pillow==9.4.0
Pygments==2.14.0
Pillow==9.5.0
Pygments==2.15.1
python-logstash==0.4.8
python-slugify==8.0.1
pytz==2023.2
raven==6.10.0
requests==2.28.2
urllib3==1.26.15
pytz==2023.3
requests==2.30.0
urllib3==2.0.2
WeRoBot==1.13.1
Whoosh==2.7.4
user-agents==2.2.0
redis==4.5.4
openai==0.27.2
redis==4.5.5
openai==0.27.6
6 changes: 5 additions & 1 deletion templates/comments/tags/post_comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ <h3 id="reply-title" class="comment-reply-title">发表评论
</p>
{{ form.parent_comment_id }}
<div class="form-submit">
<span class="comment-markdown"> 支持markdown,评论经审核后才会显示。</span>
{% if COMMENT_NEED_REVIEW %}
<span class="comment-markdown"> 支持markdown,评论经审核后才会显示。</span>
{% else %}
<span class="comment-markdown"> 支持markdown。</span>
{% endif %}
<input name="submit" type="submit" id="submit" class="submit" value="发表评论"/>
<small class="cancel-comment" id="cancel_comment" style="display: none">
<a href="javascript:void(0)" id="cancel-comment-reply-link" onclick="cancel_reply()">取消回复</a>
Expand Down
24 changes: 0 additions & 24 deletions templates/share_layout/analyticscode.html

This file was deleted.

1 change: 0 additions & 1 deletion templates/share_layout/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
|&nbsp;
<a href="https://tongji.baidu.com/sc-web/3478620/home/ico?siteId=11261596" target="_blank"
rel="nofollow">百度统计</a>
{% comment %}{% include 'share_layout/analyticscode.html' %}{% endcomment %}

</div>
<div class="site-info" style="text-align: center">
Expand Down

0 comments on commit e2e5b29

Please sign in to comment.