公告记录:
-ID | -时间 | -内容 | -
---|---|---|
#{{ record.pk }} | -{{ record.time }} | -{{ record.body |safe }} | -
diff --git a/apps/api/views.py b/apps/api/views.py
index 86cde643d..93b08fe56 100644
--- a/apps/api/views.py
+++ b/apps/api/views.py
@@ -4,13 +4,13 @@
import pendulum
from django.conf import settings
from django.contrib.auth.decorators import login_required, permission_required
+from django.db.models.query import QuerySet
from django.http import HttpResponse, HttpResponseBadRequest, JsonResponse
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
-from django.db.models.query import QuerySet
from apps.ext import lock
from apps.proxy import models as m
diff --git a/apps/sspanel/models.py b/apps/sspanel/models.py
index 2e5dec5c7..a817fe95e 100644
--- a/apps/sspanel/models.py
+++ b/apps/sspanel/models.py
@@ -1,13 +1,11 @@
import datetime
import random
-import re
import time
from decimal import Decimal
from socket import timeout
from urllib.parse import urlencode
from uuid import uuid4
-import markdown
import pendulum
from django.conf import settings
from django.contrib import messages
@@ -17,6 +15,7 @@
from django.db import IntegrityError, models, transaction
from django.utils import functional, timezone
from redis.exceptions import LockError
+from trix_editor.fields import TrixEditorField
from apps import constants as c
from apps.ext import cache, encoder, lock, pay
@@ -1008,7 +1007,7 @@ class Announcement(models.Model):
"""公告"""
time = models.DateTimeField("时间", auto_now_add=True)
- body = models.TextField("主体")
+ body = TrixEditorField("主体")
class Meta:
verbose_name = "系统公告"
@@ -1018,11 +1017,6 @@ class Meta:
def __str__(self):
return "日期:{}".format(str(self.time)[:9])
- def save(self, *args, **kwargs):
- md = markdown.Markdown(extensions=["markdown.extensions.extra"])
- self.body = md.convert(self.body)
- super(Announcement, self).save(*args, **kwargs)
-
@classmethod
def send_first_visit_msg(cls, request):
anno = cls.objects.order_by("-time").first()
@@ -1031,17 +1025,6 @@ def send_first_visit_msg(cls, request):
request.session["first_visit"] = True
messages.warning(request, anno.plain_text, extra_tags="最新通知!")
- @property
- def plain_text(self):
- # TODO 现在db里存的是md转换成的html,这里之后可能要优化。转换的逻辑移到前端去
- re_br = re.compile("
") # 处理换行
- re_h = re.compile("?\w+[^>]*>") # HTML标签
- s = re_br.sub("", self.body) # 去掉br
- s = re_h.sub("", s) # 去掉HTML 标签
- blank_line = re.compile("\n+") # 去掉多余的空行
- s = blank_line.sub("", s)
- return s
-
class Ticket(models.Model):
"""工单"""
diff --git a/apps/urls.py b/apps/urls.py
index 99aa38a7f..eab9d45dd 100644
--- a/apps/urls.py
+++ b/apps/urls.py
@@ -12,6 +12,7 @@
name="password_reset",
), # NOTE 重写了重置密码的逻辑 一定要在`django.contrib.auth.urls`之前注册,不然会被覆盖
path("accounts/", include("django.contrib.auth.urls")),
+ path("trix-editor/", include("trix_editor.urls")),
]
# append sspanel template urls
@@ -29,11 +30,6 @@
path("admin/", admin.site.urls, name="admin"),
)
-# append prometheus urls
-urlpatterns.append(
- path("prom/", include("django_prometheus.urls")),
-)
-
# append openapi urls
urlpatterns.append(
path("openapi/v1/", include(openapi_router.urls)),
diff --git a/configs/default/common.py b/configs/default/common.py
index f20dffde0..a5c53c7d4 100644
--- a/configs/default/common.py
+++ b/configs/default/common.py
@@ -13,8 +13,8 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"rest_framework",
+ "trix_editor",
"corsheaders",
- "django_prometheus",
"django_telegram_login",
"anymail",
"apps.sspanel",
@@ -25,7 +25,6 @@
MIDDLEWARE = [
- "django_prometheus.middleware.PrometheusBeforeMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
@@ -35,7 +34,6 @@
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"apps.mw.ErrorHandlerMiddleware",
- "django_prometheus.middleware.PrometheusAfterMiddleware",
]
ROOT_URLCONF = "apps.urls"
diff --git a/configs/default/db.py b/configs/default/db.py
index 7181677bd..318b0210b 100644
--- a/configs/default/db.py
+++ b/configs/default/db.py
@@ -6,7 +6,7 @@
# mysql 设置
DATABASES = {
"default": {
- "ENGINE": "django_prometheus.db.backends.mysql",
+ "ENGINE": "django.db.backends.mysql",
"NAME": "sspanel",
"PASSWORD": os.getenv("MYSQL_PASSWORD", "yourpass"),
"HOST": os.getenv("MYSQL_HOST", "127.0.0.1"),
diff --git a/configs/development.py b/configs/development.py
index fc4b8563c..666722608 100644
--- a/configs/development.py
+++ b/configs/development.py
@@ -6,5 +6,5 @@
# NOTE for django debug toolbar
DEBUG = True
INTERNAL_IPS = os.getenv("DEBUG_INTERNAL_IPS", "127.0.0.1,0.0.0.0").split(",")
-INSTALLED_APPS.insert(INSTALLED_APPS.index("django_prometheus"), "debug_toolbar")
+INSTALLED_APPS.insert(INSTALLED_APPS.index("django_telegram_login"), "debug_toolbar")
MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware")
diff --git a/poetry.lock b/poetry.lock
index b249b7a02..228defa85 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1,4 +1,4 @@
-# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
+# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.
[[package]]
name = "aiohappyeyeballs"
@@ -767,20 +767,6 @@ files = [
django = ">=4.2.9"
sqlparse = ">=0.2"
-[[package]]
-name = "django-prometheus"
-version = "2.3.1"
-description = "Django middlewares to monitor your application with Prometheus.io."
-optional = false
-python-versions = "*"
-files = [
- {file = "django-prometheus-2.3.1.tar.gz", hash = "sha256:f9c8b6c780c9419ea01043c63a437d79db2c33353451347894408184ad9c3e1e"},
- {file = "django_prometheus-2.3.1-py2.py3-none-any.whl", hash = "sha256:cf9b26f7ba2e4568f08f8f91480a2882023f5908579681bcf06a4d2465f12168"},
-]
-
-[package.dependencies]
-prometheus-client = ">=0.7"
-
[[package]]
name = "django-simpleui"
version = "2024.4.1"
@@ -805,6 +791,20 @@ files = [
{file = "django_telegram_login-0.2.3-py3-none-any.whl", hash = "sha256:e0c0aeafab55f33bca1b5a5f33b06fc257d286c7a3911ec8517df83a716d3371"},
]
+[[package]]
+name = "django-trix-editor"
+version = "0.3"
+description = "Django App To Integrate Trix Editor"
+optional = false
+python-versions = "*"
+files = [
+ {file = "django_trix_editor-0.3-py3-none-any.whl", hash = "sha256:ff67cee5ae48007c24af42e7954bb78d7359d2e9185a3b24ccac80919e386cea"},
+ {file = "django_trix_editor-0.3.tar.gz", hash = "sha256:daf8d89f8a0c40159152621629a65d081078818b0dc1840ef59bef4ad5f9a4f9"},
+]
+
+[package.dependencies]
+Django = ">=4.1"
+
[[package]]
name = "djangorestframework"
version = "3.15.2"
@@ -1160,21 +1160,6 @@ sqs = ["boto3 (>=1.26.143)", "pycurl (>=7.43.0.5)", "urllib3 (>=1.26.16)"]
yaml = ["PyYAML (>=3.10)"]
zookeeper = ["kazoo (>=2.8.0)"]
-[[package]]
-name = "markdown"
-version = "3.7"
-description = "Python implementation of John Gruber's Markdown."
-optional = false
-python-versions = ">=3.8"
-files = [
- {file = "Markdown-3.7-py3-none-any.whl", hash = "sha256:7eb6df5690b81a1d7942992c97fad2938e956e79df20cbc6186e9c3a77b1c803"},
- {file = "markdown-3.7.tar.gz", hash = "sha256:2ae2471477cfd02dbbf038d5d9bc226d40def84b4fe2986e49b59b6b472bbed2"},
-]
-
-[package.extras]
-docs = ["mdx-gh-links (>=0.2)", "mkdocs (>=1.5)", "mkdocs-gen-files", "mkdocs-literate-nav", "mkdocs-nature (>=0.6)", "mkdocs-section-index", "mkdocstrings[python]"]
-testing = ["coverage", "pyyaml"]
-
[[package]]
name = "matplotlib-inline"
version = "0.1.7"
@@ -1543,20 +1528,6 @@ docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx-
test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"]
type = ["mypy (>=1.8)"]
-[[package]]
-name = "prometheus-client"
-version = "0.20.0"
-description = "Python client for the Prometheus monitoring system."
-optional = false
-python-versions = ">=3.8"
-files = [
- {file = "prometheus_client-0.20.0-py3-none-any.whl", hash = "sha256:cde524a85bce83ca359cc837f28b8c0db5cac7aa653a588fd7e84ba061c329e7"},
- {file = "prometheus_client-0.20.0.tar.gz", hash = "sha256:287629d00b147a32dcb2be0b9df905da599b2d82f80377083ec8463309a4bb89"},
-]
-
-[package.extras]
-twisted = ["twisted"]
-
[[package]]
name = "prompt-toolkit"
version = "3.0.47"
@@ -2336,4 +2307,4 @@ multidict = ">=4.0"
[metadata]
lock-version = "2.0"
python-versions = "^3.11"
-content-hash = "c81d507946bff329101c8c568fc38d05dd83058bcaa9c32792e80b1e558e7420"
+content-hash = "4ca44e3ed1e44319c9ec79970332067d41750bad3267722f1864310b961f1d4f"
diff --git a/pyproject.toml b/pyproject.toml
index c3fa99297..bc656c41d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -32,14 +32,12 @@ package-mode = false
[tool.poetry.dependencies]
aiohttp = "^3.9.3"
Django = "^5.1"
-Markdown = "^3.3.4"
PyMySQL = "^1.1.0"
celery = "^5.3.4"
django-anymail = "^11.1"
django-cors-headers = "^4.2.0"
django-countries = "^7.1"
django-debug-toolbar = "^4.2.0"
-django-prometheus = "^2.1.0"
django-simpleui = "^2024.4.1"
django-telegram-login = "^0.2.3"
ipicn = "^2021.5.5"
@@ -54,6 +52,7 @@ short_url = "^1.2.2"
tomd = "^0.1.3"
uWSGI = "^2.0.24"
djangorestframework = "^3.14.0"
+django-trix-editor = "^0.3"
[tool.poetry.group.dev.dependencies]
autoflake = "^2.2.1"
diff --git a/templates/web/announcement.html b/templates/web/announcement.html
index 72460ea9f..3c7d833d0 100644
--- a/templates/web/announcement.html
+++ b/templates/web/announcement.html
@@ -10,28 +10,19 @@
公告记录:
-ID | -时间 | -内容 | -
---|---|---|
#{{ record.pk }} | -{{ record.time }} | -{{ record.body |safe }} | -