From d39344d33ab0dcfdd998ecc40e103c6abd65db21 Mon Sep 17 00:00:00 2001
From: liangliangyy
Date: Tue, 4 Apr 2023 14:24:49 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=8E=AF=E5=A2=83?=
=?UTF-8?q?=E5=8F=98=E9=87=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
servermanager/api/commonapi.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/servermanager/api/commonapi.py b/servermanager/api/commonapi.py
index fa146afa..83ad9ff2 100644
--- a/servermanager/api/commonapi.py
+++ b/servermanager/api/commonapi.py
@@ -8,8 +8,8 @@
logger = logging.getLogger(__name__)
openai.api_key = os.environ.get('OPENAI_API_KEY')
-if os.environ.get('PROXY'):
- openai.proxy = os.environ.get('PROXY')
+if os.environ.get('HTTP_PROXY'):
+ openai.proxy = os.environ.get('HTTP_PROXY')
class ChatGPT:
From 0a7087e8b996331db2d6a943fae50e47fdb355ea Mon Sep 17 00:00:00 2001
From: liangliangyy
Date: Mon, 24 Apr 2023 21:51:58 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=AE=A1=E6=A0=B8?=
=?UTF-8?q?=E5=90=8E=E6=89=8D=E8=83=BD=E6=98=BE=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
comments/admin.py | 4 +-
.../0002_alter_comment_is_enable.py | 18 +++++++++
comments/models.py | 5 +--
djangoblog/blog_signals.py | 40 +++++++++----------
djangoblog/settings.py | 2 +-
templates/comments/tags/post_comment.html | 2 +-
6 files changed, 43 insertions(+), 28 deletions(-)
create mode 100644 comments/migrations/0002_alter_comment_is_enable.py
diff --git a/comments/admin.py b/comments/admin.py
index 6897e444..9252174d 100644
--- a/comments/admin.py
+++ b/comments/admin.py
@@ -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]
diff --git a/comments/migrations/0002_alter_comment_is_enable.py b/comments/migrations/0002_alter_comment_is_enable.py
new file mode 100644
index 00000000..17c44db8
--- /dev/null
+++ b/comments/migrations/0002_alter_comment_is_enable.py
@@ -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='是否显示'),
+ ),
+ ]
diff --git a/comments/models.py b/comments/models.py
index d7f5faa6..27c67eff 100644
--- a/comments/models.py
+++ b/comments/models.py
@@ -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']
@@ -36,6 +36,3 @@ class Meta:
def __str__(self):
return self.body
-
- def save(self, *args, **kwargs):
- super().save(*args, **kwargs)
diff --git a/djangoblog/blog_signals.py b/djangoblog/blog_signals.py
index 00ecff12..1b146bd0 100644
--- a/djangoblog/blog_signals.py
+++ b/djangoblog/blog_signals.py
@@ -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()
diff --git a/djangoblog/settings.py b/djangoblog/settings.py
index eae379c9..5c519757 100644
--- a/djangoblog/settings.py
+++ b/djangoblog/settings.py
@@ -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),
diff --git a/templates/comments/tags/post_comment.html b/templates/comments/tags/post_comment.html
index fa31ecd8..8a4fc48a 100644
--- a/templates/comments/tags/post_comment.html
+++ b/templates/comments/tags/post_comment.html
@@ -15,7 +15,7 @@
{{ form.parent_comment_id }}
-
+