From afe773351a24c03e0171f4a1561ec8234cc7ceb5 Mon Sep 17 00:00:00 2001 From: haoming9245 Date: Sun, 30 Jul 2023 23:03:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accounts/tests.py | 1 - accounts/urls.py | 2 +- blog/admin.py | 2 +- blog/documents.py | 19 +------------- blog/middleware.py | 4 +-- blog/migrations/0001_initial.py | 1 - blog/models.py | 20 ++++++++------- blog/views.py | 28 ++++++++++++++------ comments/migrations/0001_initial.py | 1 - comments/models.py | 4 +-- djangoblog/admin_site.py | 4 +-- djangoblog/spider_notify.py | 2 +- djangoblog/utils.py | 12 ++++----- djangoblog/whoosh_cn_backend.py | 17 ++++++++---- docs/docker.md | 40 ++++++++++++++--------------- oauth/admin.py | 2 +- oauth/migrations/0001_initial.py | 1 - oauth/models.py | 5 ++-- oauth/oauthmanager.py | 4 +-- owntracks/models.py | 1 + owntracks/views.py | 6 ++--- requirements.txt | 2 +- servermanager/api/commonapi.py | 4 +-- servermanager/models.py | 3 ++- servermanager/robot.py | 4 +-- servermanager/tests.py | 4 +-- 26 files changed, 97 insertions(+), 96 deletions(-) diff --git a/accounts/tests.py b/accounts/tests.py index ae3ae69..bff4238 100644 --- a/accounts/tests.py +++ b/accounts/tests.py @@ -1,4 +1,3 @@ -from django.conf import settings from django.test import Client, RequestFactory, TestCase from django.urls import reverse from django.utils import timezone diff --git a/accounts/urls.py b/accounts/urls.py index e11dd73..cb7efd3 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -1,4 +1,4 @@ -from django.urls import include, re_path +from django.urls import re_path from django.urls import path from . import views diff --git a/blog/admin.py b/blog/admin.py index 9a07b3d..db7597c 100644 --- a/blog/admin.py +++ b/blog/admin.py @@ -16,7 +16,7 @@ class ArticleListFilter(admin.SimpleListFilter): def lookups(self, request, model_admin): authors = list(set(map(lambda x: x.author, Article.objects.all()))) for author in authors: - yield (author.id, _(author.username)) + yield author.id, _(author.username) def queryset(self, request, queryset): id = self.value() diff --git a/blog/documents.py b/blog/documents.py index 0f1db7b..843e226 100644 --- a/blog/documents.py +++ b/blog/documents.py @@ -1,6 +1,5 @@ import time -import elasticsearch.client from django.conf import settings from elasticsearch_dsl import Document, InnerDoc, Date, Integer, Long, Text, Object, GeoPoint, Keyword, Boolean from elasticsearch_dsl.connections import connections @@ -15,22 +14,6 @@ if ELASTICSEARCH_ENABLED: from elasticsearch import Elasticsearch es = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts']) - from elasticsearch.client import IngestClient - - c = IngestClient(es) - try: - c.get_pipeline('geoip') - except elasticsearch.exceptions.NotFoundError: - c.put_pipeline('geoip', body='''{ - "description" : "Add geoip info", - "processors" : [ - { - "geoip" : { - "field" : "ip" - } - } - ] - }''') class GeoIp(InnerDoc): @@ -164,7 +147,7 @@ class ArticleDocument(Document): doc_type = 'Article' -class ArticleDocumentManager(): +class ArticleDocumentManager: def __init__(self): self.create_index() diff --git a/blog/middleware.py b/blog/middleware.py index 94dd70c..881c347 100644 --- a/blog/middleware.py +++ b/blog/middleware.py @@ -15,7 +15,7 @@ class OnlineMiddleware(object): super().__init__() def __call__(self, request): - ''' page render time ''' + """ page render time """ start_time = time.time() response = self.get_response(request) http_user_agent = request.META.get('HTTP_USER_AGENT', '') @@ -25,7 +25,7 @@ class OnlineMiddleware(object): try: cast_time = time.time() - start_time if ELASTICSEARCH_ENABLED: - time_taken = round((cast_time) * 1000, 2) + time_taken = round(cast_time * 1000, 2) url = request.path from django.utils import timezone ElaspedTimeDocumentManager.create( diff --git a/blog/migrations/0001_initial.py b/blog/migrations/0001_initial.py index 3d391b6..9d7b817 100644 --- a/blog/migrations/0001_initial.py +++ b/blog/migrations/0001_initial.py @@ -2,7 +2,6 @@ from django.conf import settings from django.db import migrations, models -import django.db.models.deletion import django.utils.timezone import mdeditor.fields diff --git a/blog/models.py b/blog/models.py index 59e72c6..007e54a 100644 --- a/blog/models.py +++ b/blog/models.py @@ -59,6 +59,7 @@ class BaseModel(models.Model): class Article(BaseModel): """文章""" + objects = None STATUS_CHOICES = ( ('d', '草稿'), ('p', '发表'), @@ -93,9 +94,8 @@ class Article(BaseModel): blank=False, null=False, on_delete=models.CASCADE) - article_order = models.IntegerField( - '排序,数字越大越靠前', blank=False, null=False, default=0) - show_toc = models.BooleanField("是否显示toc目录", blank=False, null=False, default=False) + article_order = models.IntegerField('排序,数字越大越靠前', default=0) + show_toc = models.BooleanField("是否显示toc目录", default=False) category = models.ForeignKey( 'Category', verbose_name='分类', @@ -168,6 +168,7 @@ class Article(BaseModel): class Category(BaseModel): """文章分类""" + objects = None name = models.CharField('分类名', max_length=30, unique=True) parent_category = models.ForeignKey( 'self', @@ -231,6 +232,7 @@ class Category(BaseModel): class Tag(BaseModel): """文章标签""" + objects = None name = models.CharField('标签名', max_length=30, unique=True) slug = models.SlugField(default='no-slug', max_length=60, blank=True) @@ -253,11 +255,11 @@ class Tag(BaseModel): class Links(models.Model): """友情链接""" + objects = None name = models.CharField('链接名称', max_length=30, unique=True) link = models.URLField('链接地址') sequence = models.IntegerField('排序', unique=True) - is_enable = models.BooleanField( - '是否显示', default=True, blank=False, null=False) + is_enable = models.BooleanField('是否显示', default=True) show_type = models.CharField( '显示类型', max_length=1, @@ -277,6 +279,7 @@ class Links(models.Model): class SideBar(models.Model): """侧边栏,可以展示一些html内容""" + objects = None name = models.CharField('标题', max_length=100) content = models.TextField("内容") sequence = models.IntegerField('排序', unique=True) @@ -295,6 +298,7 @@ class SideBar(models.Model): class BlogSettings(models.Model): """blog的配置""" + objects = None site_name = models.CharField( "网站名称", max_length=200, @@ -337,16 +341,14 @@ class BlogSettings(models.Model): null=False, blank=False, default='') - show_gongan_code = models.BooleanField( - '是否显示公安备案号', default=False, null=False) + show_gongan_code = models.BooleanField('是否显示公安备案号', default=False) gongan_beiancode = models.TextField( '公安备案号', max_length=2000, null=True, blank=True, default='') - comment_need_review = models.BooleanField( - '评论是否需要审核', default=False, null=False) + comment_need_review = models.BooleanField('评论是否需要审核', default=False) class Meta: verbose_name = '网站配置' diff --git a/blog/views.py b/blog/views.py index 18bd080..d98deb0 100644 --- a/blog/views.py +++ b/blog/views.py @@ -57,11 +57,11 @@ class ArticleListView(ListView): raise NotImplementedError() def get_queryset_from_cache(self, cache_key): - ''' + """ 缓存页面数据 :param cache_key: 缓存key :return: - ''' + """ value = cache.get(cache_key) if value: logger.info('get view cache.key:{key}'.format(key=cache_key)) @@ -73,10 +73,10 @@ class ArticleListView(ListView): return article_list def get_queryset(self): - ''' + """ 重写默认,从缓存获取数据 :return: - ''' + """ key = self.get_queryset_cache_key() value = self.get_queryset_from_cache(key) return value @@ -87,9 +87,9 @@ class ArticleListView(ListView): class IndexView(ArticleListView): - ''' + """ 首页 - ''' + """ # 友情链接类型 link_type = LinkShowType.I @@ -111,6 +111,10 @@ class ArticleDetailView(DetailView): pk_url_kwarg = 'article_id' context_object_name = "article" + def __init__(self, **kwargs): + super().__init__(kwargs) + self.object = None + def get_object(self, queryset=None): obj = super(ArticleDetailView, self).get_object() obj.viewed() @@ -157,11 +161,15 @@ class ArticleDetailView(DetailView): class CategoryDetailView(ArticleListView): - ''' + """ 分类目录列表 - ''' + """ page_type = "分类目录归档" + def __init__(self, **kwargs): + super().__init__(kwargs) + self.categoryname = None + def get_queryset_data(self): slug = self.kwargs['category_name'] category = get_object_or_404(Category, slug=slug) @@ -227,6 +235,10 @@ class TagDetailView(ArticleListView): ''' page_type = '分类标签归档' + def __init__(self, **kwargs): + super().__init__(kwargs) + self.name = None + def get_queryset_data(self): slug = self.kwargs['tag_name'] tag = get_object_or_404(Tag, slug=slug) diff --git a/comments/migrations/0001_initial.py b/comments/migrations/0001_initial.py index 61d1e53..0f1363c 100644 --- a/comments/migrations/0001_initial.py +++ b/comments/migrations/0001_initial.py @@ -2,7 +2,6 @@ from django.conf import settings from django.db import migrations, models -import django.db.models.deletion import django.utils.timezone diff --git a/comments/models.py b/comments/models.py index 27c67ef..68c67e5 100644 --- a/comments/models.py +++ b/comments/models.py @@ -8,6 +8,7 @@ from blog.models import Article # Create your models here. class Comment(models.Model): + objects = None body = models.TextField('正文', max_length=300) created_time = models.DateTimeField('创建时间', default=now) last_mod_time = models.DateTimeField('修改时间', default=now) @@ -25,8 +26,7 @@ class Comment(models.Model): blank=True, null=True, on_delete=models.CASCADE) - is_enable = models.BooleanField( - '是否显示', default=False, blank=False, null=False) + is_enable = models.BooleanField('是否显示', default=False) class Meta: ordering = ['-id'] diff --git a/djangoblog/admin_site.py b/djangoblog/admin_site.py index f120405..7115467 100644 --- a/djangoblog/admin_site.py +++ b/djangoblog/admin_site.py @@ -38,7 +38,7 @@ class DjangoBlogAdminSite(AdminSite): # return urls + my_urls -admin_site = DjangoBlogAdminSite(name='admin') +admin_site = DjangoBlogAdminSite() admin_site.register(Article, ArticlelAdmin) admin_site.register(Category, CategoryAdmin) @@ -47,7 +47,7 @@ admin_site.register(Links, LinksAdmin) admin_site.register(SideBar, SideBarAdmin) admin_site.register(BlogSettings, BlogSettingsAdmin) -admin_site.register(commands, CommandsAdmin) +admin_site.register(Commands, CommandsAdmin) admin_site.register(EmailSendLog, EmailSendLogAdmin) admin_site.register(BlogUser, BlogUserAdmin) diff --git a/djangoblog/spider_notify.py b/djangoblog/spider_notify.py index f77c09b..88e2a6e 100644 --- a/djangoblog/spider_notify.py +++ b/djangoblog/spider_notify.py @@ -7,7 +7,7 @@ from django.contrib.sitemaps import ping_google logger = logging.getLogger(__name__) -class SpiderNotify(): +class SpiderNotify: @staticmethod def baidu_notify(urls): try: diff --git a/djangoblog/utils.py b/djangoblog/utils.py index 160f9b8..ee37f7f 100644 --- a/djangoblog/utils.py +++ b/djangoblog/utils.py @@ -22,7 +22,7 @@ logger = logging.getLogger(__name__) def get_max_articleid_commentid(): from blog.models import Article from comments.models import Comment - return (Article.objects.latest().pk, Comment.objects.latest().pk) + return Article.objects.latest().pk, Comment.objects.latest().pk def get_sha256(str): @@ -67,14 +67,14 @@ def cache_decorator(expiration=3 * 60): 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 @@ -139,7 +139,7 @@ def generate_code() -> str: def parse_dict_to_url(dict): from urllib.parse import quote - url = '&'.join(['{}={}'.format(quote(k, safe='/'), quote(v, safe='/')) + url = '&'.join(['{}={}'.format(quote(k), quote(v)) for k, v in dict.items()]) return url @@ -173,11 +173,11 @@ def get_blog_setting(): def save_user_avatar(url): - ''' + """ 保存用户头像 :param url:头像url :return: 本地路径 - ''' + """ logger.info(url) try: diff --git a/djangoblog/whoosh_cn_backend.py b/djangoblog/whoosh_cn_backend.py index c285cc2..09881a8 100644 --- a/djangoblog/whoosh_cn_backend.py +++ b/djangoblog/whoosh_cn_backend.py @@ -85,6 +85,11 @@ class WhooshSearchBackend(BaseSearchBackend): self).__init__( connection_alias, **connection_options) + self.index = None + self.parser = None + self.schema = None + self.content_field_name = None + self.storage = None self.setup_complete = False self.use_file_storage = True self.post_limit = getattr( @@ -167,8 +172,8 @@ class WhooshSearchBackend(BaseSearchBackend): schema_fields[field_class.index_fieldname] = DATETIME( stored=field_class.stored, sortable=True) elif field_class.field_type == 'integer': - schema_fields[field_class.index_fieldname] = NUMERIC( - stored=field_class.stored, numtype=int, field_boost=field_class.boost) + schema_fields[field_class.index_fieldname] = NUMERIC(stored=field_class.stored, + field_boost=field_class.boost) elif field_class.field_type == 'float': schema_fields[field_class.index_fieldname] = NUMERIC( stored=field_class.stored, numtype=float, field_boost=field_class.boost) @@ -180,7 +185,7 @@ class WhooshSearchBackend(BaseSearchBackend): schema_fields[field_class.index_fieldname] = NGRAM( minsize=3, maxsize=15, stored=field_class.stored, field_boost=field_class.boost) elif field_class.field_type == 'edge_ngram': - schema_fields[field_class.index_fieldname] = NGRAMWORDS(minsize=2, maxsize=15, at='start', + schema_fields[field_class.index_fieldname] = NGRAMWORDS(maxsize=15, at='start', stored=field_class.stored, field_boost=field_class.boost) else: @@ -197,7 +202,7 @@ class WhooshSearchBackend(BaseSearchBackend): raise SearchBackendError( "No fields were found in any search_indexes. Please correct this before attempting to search.") - return (content_field_name, Schema(**schema_fields)) + return content_field_name, Schema(**schema_fields) def update(self, index, iterable, commit=True): if not self.setup_complete: @@ -267,6 +272,7 @@ class WhooshSearchBackend(BaseSearchBackend): exc_info=True) def clear(self, models=None, commit=True): + global models_to_delete if not self.setup_complete: self.setup() @@ -570,6 +576,7 @@ class WhooshSearchBackend(BaseSearchBackend): limit_to_registered_models=None, result_class=None, **kwargs): + global searcher if not self.setup_complete: self.setup() @@ -804,7 +811,7 @@ class WhooshSearchBackend(BaseSearchBackend): """ if hasattr(value, 'strftime'): if not hasattr(value, 'hour'): - value = datetime(value.year, value.month, value.day, 0, 0, 0) + value = datetime(value.year, value.month, value.day) elif isinstance(value, bool): if value: value = 'true' diff --git a/docs/docker.md b/docs/docker.md index 92af9fa..a25c08b 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -31,27 +31,27 @@ docker-compose -f docker-compose.yml -f docker-compose.es.yml up -d 本项目较多配置都基于环境变量,所有的环境变量如下所示: -| 环境变量名称 | 默认值 | 备注 | -|---------------------------|----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------| -| DJANGO_DEBUG | False | | +| 环境变量名称 | 默认值 | 备注 | +|---------------------------|----------------------------------------------------------------------------|------------------------------------------------------------------------------------| +| DJANGO_DEBUG | False | | | DJANGO_SECRET_KEY | DJANGO_BLOG_CHANGE_ME | 请务必修改,建议[随机生成](https://www.random.org/passwords/?num=5&len=24&format=html&rnd=new) | -| DJANGO_MYSQL_DATABASE | djangoblog | | -| DJANGO_MYSQL_USER | root | | -| DJANGO_MYSQL_PASSWORD | djangoblog_123 | | -| DJANGO_MYSQL_HOST | 127.0.0.1 | | -| DJANGO_MYSQL_PORT | 3306 | | -| DJANGO_MEMCACHED_ENABLE | True | | -| DJANGO_MEMCACHED_LOCATION | 127.0.0.1:11211 | | -| DJANGO_BAIDU_NOTIFY_URL | http://data.zz.baidu.com/urls?site=https://www.example.org&token=CHANGE_ME | 请在[百度站长平台](https://ziyuan.baidu.com/linksubmit/index)获取接口地址 | -| DJANGO_EMAIL_TLS | False | | -| DJANGO_EMAIL_SSL | True | | -| DJANGO_EMAIL_HOST | smtp.example.org | | -| DJANGO_EMAIL_PORT | 465 | | -| DJANGO_EMAIL_USER | SMTP_USER_CHANGE_ME | | -| DJANGO_EMAIL_PASSWORD | SMTP_PASSWORD_CHANGE_ME | | -| DJANGO_ADMIN_EMAIL | admin@example.org | | -| DJANGO_WEROBOT_TOKEN | DJANGO_BLOG_CHANGE_ME -|DJANGO_ELASTICSEARCH_HOST| +| DJANGO_MYSQL_DATABASE | djangoblog | | +| DJANGO_MYSQL_USER | root | | +| DJANGO_MYSQL_PASSWORD | djangoblog_123 | | +| DJANGO_MYSQL_HOST | 127.0.0.1 | | +| DJANGO_MYSQL_PORT | 3306 | | +| DJANGO_MEMCACHED_ENABLE | True | | +| DJANGO_MEMCACHED_LOCATION | 127.0.0.1:11211 | | +| DJANGO_BAIDU_NOTIFY_URL | http://data.zz.baidu.com/urls?site=https://www.example.org&token=CHANGE_ME | 请在[百度站长平台](https://ziyuan.baidu.com/linksubmit/index)获取接口地址 | +| DJANGO_EMAIL_TLS | False | | +| DJANGO_EMAIL_SSL | True | | +| DJANGO_EMAIL_HOST | smtp.example.org | | +| DJANGO_EMAIL_PORT | 465 | | +| DJANGO_EMAIL_USER | SMTP_USER_CHANGE_ME | | +| DJANGO_EMAIL_PASSWORD | SMTP_PASSWORD_CHANGE_ME | | +| DJANGO_ADMIN_EMAIL | admin@example.org | | +| DJANGO_WEROBOT_TOKEN | DJANGO_BLOG_CHANGE_ME | | +| DJANGO_ELASTICSEARCH_HOST | | | 第一次启动之后,使用如下命令来创建超级用户: ```shell diff --git a/oauth/admin.py b/oauth/admin.py index 57eab5f..b79f385 100644 --- a/oauth/admin.py +++ b/oauth/admin.py @@ -43,7 +43,7 @@ class OAuthUserAdmin(admin.ModelAdmin): img = obj.picture return format_html( u'' % - (img)) + img) link_to_usermodel.short_description = '用户' show_user_image.short_description = '用户头像' diff --git a/oauth/migrations/0001_initial.py b/oauth/migrations/0001_initial.py index 3aa3e03..7ebb0dd 100644 --- a/oauth/migrations/0001_initial.py +++ b/oauth/migrations/0001_initial.py @@ -2,7 +2,6 @@ from django.conf import settings from django.db import migrations, models -import django.db.models.deletion import django.utils.timezone diff --git a/oauth/models.py b/oauth/models.py index ff82607..c0e4c6c 100644 --- a/oauth/models.py +++ b/oauth/models.py @@ -7,6 +7,7 @@ from django.utils.translation import gettext_lazy as _ class OAuthUser(models.Model): + objects = None author = models.ForeignKey( settings.AUTH_USER_MODEL, verbose_name='用户', @@ -33,6 +34,7 @@ class OAuthUser(models.Model): class OAuthConfig(models.Model): + objects = None TYPE = ( ('weibo', '微博'), ('google', '谷歌'), @@ -48,8 +50,7 @@ class OAuthConfig(models.Model): verbose_name='回调地址', blank=False, default='http://www.baidu.com') - is_enable = models.BooleanField( - '是否显示', default=True, blank=False, null=False) + is_enable = models.BooleanField('是否显示', default=True) created_time = models.DateTimeField('创建时间', default=now) last_mod_time = models.DateTimeField('修改时间', default=now) diff --git a/oauth/oauthmanager.py b/oauth/oauthmanager.py index 2e7ceef..68e1087 100644 --- a/oauth/oauthmanager.py +++ b/oauth/oauthmanager.py @@ -13,9 +13,9 @@ logger = logging.getLogger(__name__) class OAuthAccessTokenException(Exception): - ''' + """ oauth授权失败异常 - ''' + """ class BaseOauthManager(metaclass=ABCMeta): diff --git a/owntracks/models.py b/owntracks/models.py index 30f6ec1..a4e0e53 100644 --- a/owntracks/models.py +++ b/owntracks/models.py @@ -5,6 +5,7 @@ from django.utils.timezone import now # Create your models here. class OwnTrackLog(models.Model): + objects = None tid = models.CharField(max_length=100, null=False, verbose_name='用户') lat = models.FloatField(verbose_name='纬度') lon = models.FloatField(verbose_name='经度') diff --git a/owntracks/views.py b/owntracks/views.py index 27a89c8..903163e 100644 --- a/owntracks/views.py +++ b/owntracks/views.py @@ -99,12 +99,10 @@ def get_datas(request): from django.utils.timezone import utc now = django.utils.timezone.now().replace(tzinfo=utc) - querydate = django.utils.timezone.datetime( - now.year, now.month, now.day, 0, 0, 0) + querydate = django.utils.timezone.datetime(now.year, now.month, now.day) if request.GET.get('date', None): date = list(map(lambda x: int(x), request.GET.get('date').split('-'))) - querydate = django.utils.timezone.datetime( - date[0], date[1], date[2], 0, 0, 0) + querydate = django.utils.timezone.datetime(date[0], date[1], date[2]) querydate = django.utils.timezone.make_aware(querydate) nextdate = querydate + datetime.timedelta(days=1) models = OwnTrackLog.objects.filter( diff --git a/requirements.txt b/requirements.txt index 9489a06..684f275 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,7 @@ Pygments==2.15.1 python-logstash==0.4.8 python-slugify==8.0.1 pytz==2023.3 -requests==2.30.0 +requests==2.31.0 WeRoBot==1.13.1 Whoosh==2.7.4 user-agents==2.2.0 diff --git a/servermanager/api/commonapi.py b/servermanager/api/commonapi.py index 83ad9ff..b7a0257 100644 --- a/servermanager/api/commonapi.py +++ b/servermanager/api/commonapi.py @@ -3,7 +3,7 @@ import os import openai -from servermanager.models import commands +from servermanager.models import Commands logger = logging.getLogger(__name__) @@ -27,7 +27,7 @@ class ChatGPT: class CommandHandler: def __init__(self): - self.commands = commands.objects.all() + self.commands = Commands.objects.all() def run(self, title): """ diff --git a/servermanager/models.py b/servermanager/models.py index f75c930..29f84bb 100644 --- a/servermanager/models.py +++ b/servermanager/models.py @@ -2,7 +2,8 @@ from django.db import models # Create your models here. -class commands(models.Model): +class Commands(models.Model): + objects = None title = models.CharField('命令标题', max_length=300) command = models.CharField('命令', max_length=2000) describe = models.CharField('命令描述', max_length=300) diff --git a/servermanager/robot.py b/servermanager/robot.py index 7b45736..603b1f5 100644 --- a/servermanager/robot.py +++ b/servermanager/robot.py @@ -21,7 +21,7 @@ if memstorage.is_available: else: if os.path.exists(os.path.join(settings.BASE_DIR, 'werobot_session')): os.remove(os.path.join(settings.BASE_DIR, 'werobot_session')) - robot.config['SESSION_STORAGE'] = FileStorage(filename='werobot_session') + robot.config['SESSION_STORAGE'] = FileStorage() blogapi = BlogApi() cmd_handler = CommandHandler() @@ -179,7 +179,7 @@ class MessageHandler: return ChatGPT.chat(info) -class WxUserInfo(): +class WxUserInfo: def __init__(self): self.isAdmin = False self.isPasswordSet = False diff --git a/servermanager/tests.py b/servermanager/tests.py index 40fa9ec..f06e346 100644 --- a/servermanager/tests.py +++ b/servermanager/tests.py @@ -5,7 +5,7 @@ from werobot.messages.messages import TextMessage from accounts.models import BlogUser from blog.models import Category, Article from servermanager.api.commonapi import ChatGPT -from .models import commands +from .models import Commands from .robot import MessageHandler, CommandHandler from .robot import search, category, recents @@ -50,7 +50,7 @@ class ServerManagerTest(TestCase): rsp = recents(None, None) self.assertTrue(rsp != '暂时还没有文章') - cmd = commands() + cmd = Commands() cmd.title = "test" cmd.command = "ls" cmd.describe = "test" -- Gitee From b888bb49adbcda84091708ecaaec804913b05db2 Mon Sep 17 00:00:00 2001 From: haoming9245 Date: Mon, 31 Jul 2023 08:48:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E8=A1=A5=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comments/migrations/0001_initial.py | 3 ++- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/comments/migrations/0001_initial.py b/comments/migrations/0001_initial.py index 0f1363c..456ab18 100644 --- a/comments/migrations/0001_initial.py +++ b/comments/migrations/0001_initial.py @@ -23,7 +23,8 @@ class Migration(migrations.Migration): ('created_time', models.DateTimeField(default=django.utils.timezone.now, verbose_name='创建时间')), ('last_mod_time', models.DateTimeField(default=django.utils.timezone.now, verbose_name='修改时间')), ('is_enable', models.BooleanField(default=True, verbose_name='是否显示')), - ('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.article', verbose_name='文章')), + ('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, + to='blog.article', verbose_name='文章')), ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='作者')), ('parent_comment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='comments.comment', verbose_name='上级评论')), ], diff --git a/requirements.txt b/requirements.txt index 684f275..63fa4a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ coverage==7.2.2 bleach==6.0.0 -Django==4.2.1 +Django==4.2.3 django-compressor==4.3.1 django-haystack==3.2.1 django-ipware==5.0.0 -- Gitee