Skip to content

Commit

Permalink
评论审核后才能显示
Browse files Browse the repository at this point in the history
  • Loading branch information
liangliangyy committed Apr 24, 2023
1 parent d39344d commit 0a7087e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 28 deletions.
4 changes: 2 additions & 2 deletions comments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class CommentAdmin(admin.ModelAdmin):
'link_to_article',
'is_enable',
'created_time')
list_display_links = ('id', 'body')
list_filter = ('author', 'article', 'is_enable')
list_display_links = ('id', 'body', 'is_enable')
list_filter = ('is_enable', 'author', 'article',)
exclude = ('created_time', 'last_mod_time')
actions = [disable_commentstatus, enable_commentstatus]

Expand Down
18 changes: 18 additions & 0 deletions comments/migrations/0002_alter_comment_is_enable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2023-04-24 13:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('comments', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='comment',
name='is_enable',
field=models.BooleanField(default=False, verbose_name='是否显示'),
),
]
5 changes: 1 addition & 4 deletions comments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Comment(models.Model):
null=True,
on_delete=models.CASCADE)
is_enable = models.BooleanField(
'是否显示', default=True, blank=False, null=False)
'是否显示', default=False, blank=False, null=False)

class Meta:
ordering = ['-id']
Expand All @@ -36,6 +36,3 @@ class Meta:

def __str__(self):
return self.body

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
40 changes: 20 additions & 20 deletions djangoblog/blog_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,26 @@ def model_post_save_callback(
clearcache = True

if isinstance(instance, Comment):

path = instance.article.get_absolute_url()
site = get_current_site().domain
if site.find(':') > 0:
site = site[0:site.find(':')]

expire_view_cache(
path,
servername=site,
serverport=80,
key_prefix='blogdetail')
if cache.get('seo_processor'):
cache.delete('seo_processor')
comment_cache_key = 'article_comments_{id}'.format(
id=instance.article.id)
cache.delete(comment_cache_key)
delete_sidebar_cache()
delete_view_cache('article_comments', [str(instance.article.pk)])

_thread.start_new(send_comment_email, (instance,))
if instance.is_enable:
path = instance.article.get_absolute_url()
site = get_current_site().domain
if site.find(':') > 0:
site = site[0:site.find(':')]

expire_view_cache(
path,
servername=site,
serverport=80,
key_prefix='blogdetail')
if cache.get('seo_processor'):
cache.delete('seo_processor')
comment_cache_key = 'article_comments_{id}'.format(
id=instance.article.id)
cache.delete(comment_cache_key)
delete_sidebar_cache()
delete_view_cache('article_comments', [str(instance.article.pk)])

_thread.start_new(send_comment_email, (instance,))

if clearcache:
cache.clear()
Expand Down
2 changes: 1 addition & 1 deletion djangoblog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def env_to_bool(env, default):
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ.get('DJANGO_MYSQL_DATABASE') or 'djangoblog',
'USER': os.environ.get('DJANGO_MYSQL_USER') or 'root',
'PASSWORD': os.environ.get('DJANGO_MYSQL_PASSWORD') or 'djangoblog_123',
'PASSWORD': os.environ.get('DJANGO_MYSQL_PASSWORD') or 'root',
'HOST': os.environ.get('DJANGO_MYSQL_HOST') or '127.0.0.1',
'PORT': int(
os.environ.get('DJANGO_MYSQL_PORT') or 3306),
Expand Down
2 changes: 1 addition & 1 deletion templates/comments/tags/post_comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h3 id="reply-title" class="comment-reply-title">发表评论
</p>
{{ form.parent_comment_id }}
<div class="form-submit">
<span class="comment-markdown"> 支持markdown</span>
<span class="comment-markdown"> 支持markdown,评论经审核后才会显示。</span>
<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

0 comments on commit 0a7087e

Please sign in to comment.