diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ef316bf3..6b43f5c7 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -19,14 +19,13 @@ jobs: uses: awalsh128/cache-apt-pkgs-action@latest with: packages: ffmpeg - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v3 with: python-version: "3.10" - name: Install dependencies run: | cd hinghwa-dict-backend - python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip3 install -r requirements.txt; fi - name: Start django service run: | diff --git a/hinghwa-dict-backend/article/views.py b/hinghwa-dict-backend/article/views.py index 244e8042..1dc72b9c 100644 --- a/hinghwa-dict-backend/article/views.py +++ b/hinghwa-dict-backend/article/views.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.http import JsonResponse from django.utils import timezone from django.views.decorators.csrf import csrf_exempt @@ -70,7 +70,7 @@ def get(self, request) -> JsonResponse: def post(self, request) -> JsonResponse: token = token_pass(request.headers) user = token_user(token) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) article_form = ArticleForm(body) if not article_form.is_valid(): raise BadRequestException() @@ -90,7 +90,7 @@ def post(self, request) -> JsonResponse: # AT0202 文章内容批量获取 def put(self, request) -> JsonResponse: - body = demjson.decode(request.body) + body = demjson3.decode(request.body) result = Article.objects.filter(id__in=body["articles"]) try: token = token_pass(request.headers) @@ -156,7 +156,7 @@ def put(self, request, id) -> JsonResponse: raise ArticleNotFoundException() article = article[0] token = token_pass(request.headers, article.author.id) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) body = body["article"] article_form = ArticleForm(body) for key in body: @@ -196,7 +196,7 @@ def put(self, request, id) -> JsonResponse: if not article.exists(): raise ArticleNotFoundException() article = article[0] - body = demjson.decode(request.body) + body = demjson3.decode(request.body) article.visibility = body["result"] if article.visibility: content = f"恭喜您的 文章(id={id}) 已通过审核" @@ -271,7 +271,7 @@ def post(self, request, id) -> JsonResponse: ): raise ArticleNotFoundException() article = article[0] - body = demjson.decode(request.body) + body = demjson3.decode(request.body) comment_form = CommentForm(body) if not comment_form.is_valid(): raise BadRequestException() @@ -292,7 +292,7 @@ def delete(self, request, id) -> JsonResponse: article[0].visibility or user.is_superuser or user == article[0].author ): raise ArticleNotFoundException() - body = demjson.decode(request.body) + body = demjson3.decode(request.body) comment = Comment.objects.get(id=body["id"]) if token_pass(request.headers, comment.user.id) or token_pass( request.headers, -1 @@ -305,7 +305,7 @@ def delete(self, request, id) -> JsonResponse: class SearchComment(View): # AT0403 评论内容批量获取 def put(self, request) -> JsonResponse: - body = demjson.decode(request.body) + body = demjson3.decode(request.body) result = Comment.objects.filter(id__in=body["comments"]) result = filterInOrder(result, body["comments"]) comments = [] diff --git a/hinghwa-dict-backend/music/views.py b/hinghwa-dict-backend/music/views.py index 2d23e875..0aacb651 100644 --- a/hinghwa-dict-backend/music/views.py +++ b/hinghwa-dict-backend/music/views.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from django.views import View @@ -32,7 +32,7 @@ def get(self, request) -> JsonResponse: def post(self, request) -> JsonResponse: token = token_pass(request.headers) user = token_user(token) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) music_form = MusicForm(body) if not music_form.is_valid(): raise BadRequestException() @@ -43,7 +43,7 @@ def post(self, request) -> JsonResponse: # MC0202 音乐批量获取 def put(self, request) -> JsonResponse: - body = demjson.decode(request.body) + body = demjson3.decode(request.body) result = Music.objects.filter(id__in=body["music"]) result = filterInOrder(result, body["music"]) musics = [] @@ -73,7 +73,7 @@ def put(self, request, id) -> JsonResponse: raise MusicNotFoundException() music = music[0] token = token_pass(request.headers, music.contributor.id) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) body = body["music"] music_form = MusicForm(body) for key in body: diff --git a/hinghwa-dict-backend/quiz/cert/view/cert_all.py b/hinghwa-dict-backend/quiz/cert/view/cert_all.py index fc847e8e..ad817572 100644 --- a/hinghwa-dict-backend/quiz/cert/view/cert_all.py +++ b/hinghwa-dict-backend/quiz/cert/view/cert_all.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.http import JsonResponse from django.views import View from ...models import Cert @@ -17,7 +17,7 @@ class AllCert(View): # QZ0502创建证书 def post(self, request): token_pass(request.headers, -1) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) cert_form = CertForm(body["cert"]) if not cert_form.is_valid(): raise BadRequestException() diff --git a/hinghwa-dict-backend/quiz/paper/view/manage_all.py b/hinghwa-dict-backend/quiz/paper/view/manage_all.py index b9b75655..3c6eacfe 100644 --- a/hinghwa-dict-backend/quiz/paper/view/manage_all.py +++ b/hinghwa-dict-backend/quiz/paper/view/manage_all.py @@ -1,5 +1,5 @@ from django.http import JsonResponse -import demjson +import demjson3 from ..dto.paper_all import paper_all from django.views import View from django.views.decorators.csrf import csrf_exempt @@ -15,7 +15,7 @@ class ManageAllPaper(View): def post(self, request): token_pass(request.headers, -1) number = int(request.GET["number"]) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) title = body["title"] request_type = request.GET["type"] type_list = request_type.split(",") diff --git a/hinghwa-dict-backend/quiz/paper/view/manage_single.py b/hinghwa-dict-backend/quiz/paper/view/manage_single.py index e3c76c7a..fca956bd 100644 --- a/hinghwa-dict-backend/quiz/paper/view/manage_single.py +++ b/hinghwa-dict-backend/quiz/paper/view/manage_single.py @@ -1,4 +1,3 @@ -import demjson from django.http import JsonResponse from ..dto.paper_all import paper_all from django.views import View diff --git a/hinghwa-dict-backend/quiz/paper/view/paper_record_all.py b/hinghwa-dict-backend/quiz/paper/view/paper_record_all.py index d11c2993..f74b020b 100644 --- a/hinghwa-dict-backend/quiz/paper/view/paper_record_all.py +++ b/hinghwa-dict-backend/quiz/paper/view/paper_record_all.py @@ -1,5 +1,4 @@ from django.http import JsonResponse -import demjson from ..dto.paper_record_dto import paper_record_all from django.views import View from ...models import Quiz, Paper diff --git a/hinghwa-dict-backend/quiz/quiz_record/view/quiz_record_all.py b/hinghwa-dict-backend/quiz/quiz_record/view/quiz_record_all.py index 1bf01479..b8c80c25 100644 --- a/hinghwa-dict-backend/quiz/quiz_record/view/quiz_record_all.py +++ b/hinghwa-dict-backend/quiz/quiz_record/view/quiz_record_all.py @@ -1,5 +1,5 @@ from django.http import JsonResponse -import demjson +import demjson3 from ..dto.quiz_record import quiz_record from django.views import View from ...models import Quiz, Paper, QuizRecord @@ -21,7 +21,7 @@ class QuizRecordAll(View): # QZ0401创建答题记录 def post(self, request): token_pass(request.headers) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) record_form = QuizRecordForm(body) quiz_id = request.GET["quiz_id"] quiz = Quiz.objects.filter(id=quiz_id) diff --git a/hinghwa-dict-backend/quiz/quiz_record/view/quiz_record_single.py b/hinghwa-dict-backend/quiz/quiz_record/view/quiz_record_single.py index 53fd2fb4..00f6df74 100644 --- a/hinghwa-dict-backend/quiz/quiz_record/view/quiz_record_single.py +++ b/hinghwa-dict-backend/quiz/quiz_record/view/quiz_record_single.py @@ -1,5 +1,5 @@ from django.http import JsonResponse -import demjson +import demjson3 from ..dto.quiz_record import quiz_record from django.views import View from ...models import Paper, QuizRecord, PaperRecord @@ -27,7 +27,7 @@ def get(self, request, record_id): # QZ0404更改特定答题记录 def put(self, request, record_id): token_pass(request.headers, -1) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) if body["paper_record"] != "": paper = PaperRecord.objects.filter(id=body["paper_record"]) if not paper.exists(): diff --git a/hinghwa-dict-backend/quiz/views.py b/hinghwa-dict-backend/quiz/views.py index 112bbfd4..50986245 100644 --- a/hinghwa-dict-backend/quiz/views.py +++ b/hinghwa-dict-backend/quiz/views.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.http import JsonResponse from django.conf import settings from django.views import View @@ -40,7 +40,7 @@ def get(self, request, id) -> JsonResponse: # QZ0103 修改单个测试 def put(self, request, id) -> JsonResponse: try: - body = demjson.decode(request.body) + body = demjson3.decode(request.body) token = token_pass(request.headers) user = token_user(token) quiz = Quiz.objects.filter(id=id) @@ -107,7 +107,7 @@ def get(self, request) -> JsonResponse: # QZ0102 增加单个测试 def post(self, request) -> JsonResponse: - body = demjson.decode(request.body) + body = demjson3.decode(request.body) token = token_pass(request.headers) user = token_user(token) quiz_form = QuizForm(body) @@ -142,7 +142,7 @@ def put(self, request, id) -> JsonResponse: if not quiz.exists(): raise QuizNotFoundException() quiz = quiz[0] - body = demjson.decode(request.body) + body = demjson3.decode(request.body) quiz.visibility = body["result"] if quiz.visibility: content = f"问题(id={id})已通过审核" diff --git a/hinghwa-dict-backend/requirements.txt b/hinghwa-dict-backend/requirements.txt index e442acc0..7390e2a8 100644 --- a/hinghwa-dict-backend/requirements.txt +++ b/hinghwa-dict-backend/requirements.txt @@ -1,6 +1,6 @@ setuptools==69.1.1 django==5.0.3 -demjson~=2.2.4 +demjson3~=3.0.6 pyjwt~=2.4.0 django-cors-headers~=4.3.1 xlrd~=2.0.1 diff --git a/hinghwa-dict-backend/rewards/orders/views/Manage_all.py b/hinghwa-dict-backend/rewards/orders/views/Manage_all.py index bb360cd2..668407d9 100644 --- a/hinghwa-dict-backend/rewards/orders/views/Manage_all.py +++ b/hinghwa-dict-backend/rewards/orders/views/Manage_all.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt @@ -29,7 +29,7 @@ def post(self, request) -> JsonResponse: if not product.exists(): raise ProductsNotFoundException() product = product[0] - body = demjson.decode(request.body) + body = demjson3.decode(request.body) if user.user_info.points_now < product.points: return JsonResponse({"msg": "用户积分不足"}, status=403) if product.quantity <= 0: diff --git a/hinghwa-dict-backend/rewards/orders/views/Manage_single.py b/hinghwa-dict-backend/rewards/orders/views/Manage_single.py index 509b46cb..24d0e4e5 100644 --- a/hinghwa-dict-backend/rewards/orders/views/Manage_single.py +++ b/hinghwa-dict-backend/rewards/orders/views/Manage_single.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from ..dto.orders_all import order_all @@ -46,7 +46,7 @@ def put(self, request, order_id): user_id = order.user.id token = token_pass(request.headers, -1) or token_pass(request.headers, user_id) if token: - body = demjson.decode(request.body) + body = demjson3.decode(request.body) for key in body: setattr(order, key, body[key]) diff --git a/hinghwa-dict-backend/rewards/products/views/Manage_all.py b/hinghwa-dict-backend/rewards/products/views/Manage_all.py index 29f8b10f..b9787e58 100644 --- a/hinghwa-dict-backend/rewards/products/views/Manage_all.py +++ b/hinghwa-dict-backend/rewards/products/views/Manage_all.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from ..dto.product_all import product_all @@ -16,7 +16,7 @@ class ManageAllProducts(View): @csrf_exempt def post(self, request) -> JsonResponse: token = token_pass(request.headers, -1) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) products_form = ProductInfoForm(body) if not products_form.is_valid(): raise BadRequestException() diff --git a/hinghwa-dict-backend/rewards/products/views/Manage_single.py b/hinghwa-dict-backend/rewards/products/views/Manage_single.py index 87280c90..38dbb82f 100644 --- a/hinghwa-dict-backend/rewards/products/views/Manage_single.py +++ b/hinghwa-dict-backend/rewards/products/views/Manage_single.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from ..dto.product_all import product_all @@ -37,7 +37,7 @@ def put(self, request, id) -> JsonResponse: if not products.exists(): raise ProductsNotFoundException() products = products[0] - body = demjson.decode(request.body) + body = demjson3.decode(request.body) for key in body: setattr(products, key, body[key]) products.save() diff --git a/hinghwa-dict-backend/rewards/titles/views/Manage_all.py b/hinghwa-dict-backend/rewards/titles/views/Manage_all.py index aa11c939..9a02ddb4 100644 --- a/hinghwa-dict-backend/rewards/titles/views/Manage_all.py +++ b/hinghwa-dict-backend/rewards/titles/views/Manage_all.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from ..dto.title_all import title_all @@ -40,7 +40,7 @@ def get(self, request): @csrf_exempt def post(self, request) -> JsonResponse: token = token_pass(request.headers, -1) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) title_form = TitleInfoForm(body) if not title_form.is_valid(): raise BadRequestException() diff --git a/hinghwa-dict-backend/rewards/titles/views/Manage_single.py b/hinghwa-dict-backend/rewards/titles/views/Manage_single.py index 05ae3fc3..8cb8b556 100644 --- a/hinghwa-dict-backend/rewards/titles/views/Manage_single.py +++ b/hinghwa-dict-backend/rewards/titles/views/Manage_single.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from ..dto.title_all import title_all @@ -37,7 +37,7 @@ def put(self, request, id) -> JsonResponse: if not title.exists(): raise TitleNotFoundException() title = title[0] - body = demjson.decode(request.body) + body = demjson3.decode(request.body) for key in body: setattr(title, key, body[key]) title.save() diff --git a/hinghwa-dict-backend/user/view/forget.py b/hinghwa-dict-backend/user/view/forget.py index fe8de800..ccfc6cf0 100644 --- a/hinghwa-dict-backend/user/view/forget.py +++ b/hinghwa-dict-backend/user/view/forget.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.contrib.auth.models import User from django.http import JsonResponse from django.views import View @@ -27,7 +27,7 @@ def get(self, request): # LG0202 重置密码 def put(self, request, id): # 检查验证码并重置用户密码 - body = demjson.decode(request.body) + body = demjson3.decode(request.body) user = check_request_user(request, id) if user.username != body["username"]: raise ForbiddenException("用户名不匹配") diff --git a/hinghwa-dict-backend/user/view/manage.py b/hinghwa-dict-backend/user/view/manage.py index 4655db05..9502dbad 100644 --- a/hinghwa-dict-backend/user/view/manage.py +++ b/hinghwa-dict-backend/user/view/manage.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.db.models import Sum from django.http import JsonResponse from django.views import View @@ -93,7 +93,7 @@ def put(self, request, id): if request_user.id != id: raise ForbiddenException user = get_user_by_id(id) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) info = body["user"] print(info) print(info["town"]) @@ -125,7 +125,7 @@ def put(self, request, id) -> JsonResponse: user = get_request_user(request) if user.id != id: raise ForbiddenException - body = demjson.decode(request.body) + body = demjson3.decode(request.body) if not user.check_password(body["oldpassword"]): raise WrongPassword() password_validator(body["newpassword"]) @@ -146,7 +146,7 @@ def put(self, request, id) -> JsonResponse: user = get_request_user(request) if user.id != id: raise ForbiddenException - body = demjson.decode(request.body) + body = demjson3.decode(request.body) if not email_check(body["email"], body["code"]): raise BadRequestException("验证码错误") user.email = body["email"] diff --git a/hinghwa-dict-backend/user/view/wechat.py b/hinghwa-dict-backend/user/view/wechat.py index 403feedf..9cd5ab86 100644 --- a/hinghwa-dict-backend/user/view/wechat.py +++ b/hinghwa-dict-backend/user/view/wechat.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 import requests from django.conf import settings from django.http import JsonResponse @@ -39,7 +39,7 @@ def get_openid(self) -> str: class WechatLogin(View): # LG0102 微信登录 def post(self, request): - body = demjson.decode(request.body) + body = demjson3.decode(request.body) jscode = body["jscode"] openid = OpenId(jscode).get_openid() user_info = UserInfo.objects.filter(wechat__contains=openid) @@ -54,7 +54,7 @@ def post(self, request): class WechatRegister(View): # US0102 新建用户(微信) def post(self, request): - body = demjson.decode(request.body) + body = demjson3.decode(request.body) user_form = UserFormByWechat(body) jscode = body["jscode"] # 获取微信信息 @@ -86,7 +86,7 @@ class BindWechat(View): # US0304 绑定微信 def put(self, request, id) -> JsonResponse: user = check_request_user(request, id) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) jscode = body["jscode"] openid = OpenId(jscode).get_openid() if UserInfo.objects.filter(wechat=openid).exists(): @@ -117,7 +117,7 @@ def post(self, request, id) -> JsonResponse: user = check_request_user(request, id) if user.id != id: raise ForbiddenException - body = demjson.decode(request.body) + body = demjson3.decode(request.body) jscode = body["jscode"] openid = OpenId(jscode).get_openid() # 基于jscode获取的用户 diff --git a/hinghwa-dict-backend/user/views.py b/hinghwa-dict-backend/user/views.py index 29e5aa63..9ad93b83 100644 --- a/hinghwa-dict-backend/user/views.py +++ b/hinghwa-dict-backend/user/views.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.conf import settings from django.contrib.auth import authenticate from django.http import JsonResponse @@ -33,7 +33,7 @@ def router_users(request): # US0101 新建用户 elif request.method == "POST": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) user_form = UserForm(body) code = body["code"] if user_form.is_valid(): @@ -68,7 +68,7 @@ def router_users(request): def login(request): try: if request.method == "POST": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) username = body["username"] password = body["password"] user = authenticate(username=username, password=password) diff --git a/hinghwa-dict-backend/website/notification/views.py b/hinghwa-dict-backend/website/notification/views.py index 9d5cc7d9..6b785737 100644 --- a/hinghwa-dict-backend/website/notification/views.py +++ b/hinghwa-dict-backend/website/notification/views.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.contrib.auth.models import User from django.core.paginator import Paginator from django.http import JsonResponse @@ -18,7 +18,7 @@ def post(self, request): user = get_request_user(request) if not user.id: raise UnauthorizedException() - body = demjson.decode(request.body) + body = demjson3.decode(request.body) if len(body["recipients"]) == 1 and body["recipients"][0] == -1: recipients = None else: diff --git a/hinghwa-dict-backend/website/views.py b/hinghwa-dict-backend/website/views.py index 243590fd..0b23bf2d 100644 --- a/hinghwa-dict-backend/website/views.py +++ b/hinghwa-dict-backend/website/views.py @@ -3,7 +3,7 @@ import os import random -import demjson +import demjson3 import jwt import requests from apscheduler.schedulers.background import BackgroundScheduler @@ -136,7 +136,7 @@ def check(email): return str(email).find("@") == -1 try: - body = demjson.decode(request.body) + body = demjson3.decode(request.body) email = body["email"].replace(" ", "") if check(email): return JsonResponse({}, status=400) @@ -228,7 +228,7 @@ def announcements(request): ) return JsonResponse({"announcements": announcements}, status=200) elif request.method == "PUT": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) token = request.headers["token"] if token_check(token, settings.JWT_KEY, -1): if isinstance(body["announcements"], list): @@ -277,7 +277,7 @@ def hot_articles(request): ) return JsonResponse({"hot_articles": hot_articles}, status=200) elif request.method == "PUT": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) token = request.headers["token"] if token_check(token, settings.JWT_KEY, -1): if isinstance(body["hot_articles"], list): @@ -313,7 +313,7 @@ def word_of_the_day(request): status=200, ) elif request.method == "PUT": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) token = request.headers["token"] if token_check(token, settings.JWT_KEY, -1): if isinstance(body["word_of_the_day"], int): @@ -337,7 +337,7 @@ def carousel(request): {"carousel": eval(item.carousel) if item.carousel else []}, status=200 ) elif request.method == "PUT": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) token = request.headers["token"] if token_check(token, settings.JWT_KEY, -1): if isinstance(body["carousel"], list) and isinstance( @@ -437,7 +437,7 @@ def files(request): url = upload_file(path, key) return JsonResponse({"url": url}, status=200) elif request.method == "DELETE": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) try: suffix = body["url"].split("/", 4)[-1] type = suffix.split("/", 2)[0] @@ -559,7 +559,7 @@ def searchDailyExpression(request): token = request.headers["token"] user = token_check(token, settings.JWT_KEY, -1) if user: - body = demjson.decode(request.body) + body = demjson3.decode(request.body) word_form = DailyExpressionForm(body) if word_form.is_valid(): word = word_form.save(commit=False) @@ -596,7 +596,7 @@ def manageDailyExpression(request, id): if word.exists(): word = word[0] if request.method == "PUT": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) for property in body["daily_expression"]: setattr(word, property, body["daily_expression"][property]) word.save() @@ -708,7 +708,7 @@ def manageNotificationUnread(request): user = token_check(token, settings.JWT_KEY) if user: if request.method == "PUT": - body = demjson.decode(request.body) if len(request.body) else {} + body = demjson3.decode(request.body) if len(request.body) else {} notifications = Notification.objects.filter(recipient_id=user.id) if "notifications" in body: notifications = notifications.filter(id__in=body["notifications"]) diff --git a/hinghwa-dict-backend/word/application/views.py b/hinghwa-dict-backend/word/application/views.py index eb4199fd..87455deb 100644 --- a/hinghwa-dict-backend/word/application/views.py +++ b/hinghwa-dict-backend/word/application/views.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from django.conf import settings from django.http import JsonResponse from django.views import View @@ -39,7 +39,7 @@ def post(self, request) -> JsonResponse: """ try: user = token_user(token_pass(request.headers, 0)) # user = 操作用户 - body = demjson.decode(request.body) # body = 申请内容 + body = demjson3.decode(request.body) # body = 申请内容 # 检查申请修改的词语是否存在(为0表示新建词语) word = Word.objects.filter(id=body["word"]) @@ -112,7 +112,7 @@ def put(self, request, id) -> JsonResponse: application = find_application(id) application.verifier = user feedback = None - body = demjson.decode(request.body) # body = 申请内容 + body = demjson3.decode(request.body) # body = 申请内容 if not "result" in body: raise BadRequestException("缺少result字段") diff --git a/hinghwa-dict-backend/word/character/views.py b/hinghwa-dict-backend/word/character/views.py index f763bc3d..d98265ab 100644 --- a/hinghwa-dict-backend/word/character/views.py +++ b/hinghwa-dict-backend/word/character/views.py @@ -1,7 +1,7 @@ import os import re -import demjson +import demjson3 import xlrd from django.conf import settings from django.db.models import Q @@ -30,7 +30,7 @@ def searchCharacters(request): characters = [character.id for character in characters] return JsonResponse({"characters": characters}, status=200) elif request.method == "POST": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) token = request.headers["token"] user = token_check(token, settings.JWT_KEY, -1) if user: @@ -47,7 +47,7 @@ def searchCharacters(request): else: return JsonResponse({}, status=401) elif request.method == "PUT": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) result = Character.objects.filter(id__in=body["characters"]) characters = [] result = filterInOrder(result, body["characters"]) @@ -217,7 +217,7 @@ def manageCharacter(request, id): status=200, ) elif request.method == "PUT": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) token = request.headers["token"] if token_check(token, settings.JWT_KEY, -1): body = body["character"] @@ -250,7 +250,7 @@ def manageCharacter(request, id): @csrf_exempt def load_character(request): try: - body = demjson.decode(request.body) + body = demjson3.decode(request.body) token = request.headers["token"] user = token_check(token, settings.JWT_KEY, -1) if user: diff --git a/hinghwa-dict-backend/word/lists/view/manage_all_list.py b/hinghwa-dict-backend/word/lists/view/manage_all_list.py index b5626c89..89846012 100644 --- a/hinghwa-dict-backend/word/lists/view/manage_all_list.py +++ b/hinghwa-dict-backend/word/lists/view/manage_all_list.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from ...models import List, Word from ..dto.list_all import list_all from django.http import JsonResponse @@ -18,7 +18,7 @@ class ManageAllLists(View): def post(self, request): token = token_pass(request.headers, -1) user = token_user(token) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) list_form = ListForm(body) if not list_form.is_valid(): raise BadRequestException() diff --git a/hinghwa-dict-backend/word/lists/view/manage_single_list.py b/hinghwa-dict-backend/word/lists/view/manage_single_list.py index 43411b4b..f956670d 100644 --- a/hinghwa-dict-backend/word/lists/view/manage_single_list.py +++ b/hinghwa-dict-backend/word/lists/view/manage_single_list.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from ...models import List, Word from ..dto.list_all import list_all from django.http import JsonResponse @@ -30,7 +30,7 @@ def put(self, request, list_id): if not list.exists(): raise ListsNotFoundException() list = list[0] - body = demjson.decode(request.body) + body = demjson3.decode(request.body) for key in body: if key != "words": setattr(list, key, body[key]) diff --git a/hinghwa-dict-backend/word/lists/view/manage_word_in_list.py b/hinghwa-dict-backend/word/lists/view/manage_word_in_list.py index e6092784..2404ae74 100644 --- a/hinghwa-dict-backend/word/lists/view/manage_word_in_list.py +++ b/hinghwa-dict-backend/word/lists/view/manage_word_in_list.py @@ -1,4 +1,4 @@ -import demjson +import demjson3 from ...models import List, Word from ..dto.list_all import list_all from django.http import JsonResponse @@ -21,7 +21,7 @@ def post(self, request, list_id): if not list.exists(): raise ListsNotFoundException() list = list[0] - body = demjson.decode(request.body) + body = demjson3.decode(request.body) for id in body["words"]: word = Word.objects.get(id=id) list.words.add(word) @@ -33,7 +33,7 @@ def post(self, request, list_id): @csrf_exempt def delete(self, request, list_id): token_pass(request.headers, -1) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) list = List.objects.filter(id=list_id) if not list.exists(): raise ListsNotFoundException() diff --git a/hinghwa-dict-backend/word/pronunciation/views.py b/hinghwa-dict-backend/word/pronunciation/views.py index 0dd8a86c..b63c049b 100644 --- a/hinghwa-dict-backend/word/pronunciation/views.py +++ b/hinghwa-dict-backend/word/pronunciation/views.py @@ -2,7 +2,7 @@ import shutil import time import datetime -import demjson +import demjson3 import numpy as np import pydub from django.conf import settings @@ -101,7 +101,7 @@ def get(self, request) -> JsonResponse: def post(self, request) -> JsonResponse: token = token_pass(request.headers) user = token_user(token) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) body = body["pronunciation"] pronunciation_form = PronunciationForm(body) if not pronunciation_form.is_valid(): @@ -308,7 +308,7 @@ def get(self, request, id): def put(self, request, id): token_pass(request.headers, -1) pronunciation = get_pronunciation_by_id(id) - body = demjson.decode(request.body) if len(request.body) else {} + body = demjson3.decode(request.body) if len(request.body) else {} if "pronunciation" not in body: return BadRequestException("缺少pronunciation字段") pronunciation_form = PronunciationForm(body["pronunciation"]) @@ -327,7 +327,7 @@ def put(self, request, id): def delete(self, request, id): token_pass(request.headers, -1) pronunciation = get_pronunciation_by_id(id) - body = demjson.decode(request.body) if len(request.body) else {} + body = demjson3.decode(request.body) if len(request.body) else {} if "message" in body: message = body["message"] else: @@ -349,7 +349,7 @@ class ManageApproval(View): def post(self, request, id): token_pass(request.headers, -1) verifier = get_request_user(request) - body = demjson.decode(request.body) if len(request.body) else {} + body = demjson3.decode(request.body) if len(request.body) else {} if "result" in body: result = body["result"] else: @@ -384,7 +384,7 @@ def post(self, request, id): def put(self, request, id): token_pass(request.headers, -1) verifier = get_request_user(request) - body = demjson.decode(request.body) if len(request.body) else {} + body = demjson3.decode(request.body) if len(request.body) else {} if "message" in body: message = body["message"] else: diff --git a/hinghwa-dict-backend/word/word/views.py b/hinghwa-dict-backend/word/word/views.py index e383a7b0..8528444d 100644 --- a/hinghwa-dict-backend/word/word/views.py +++ b/hinghwa-dict-backend/word/word/views.py @@ -1,7 +1,7 @@ import csv import os -import demjson +import demjson3 import xlrd import re from django.conf import settings @@ -79,7 +79,7 @@ def searchWords(request): return JsonResponse({"result": result, "words": words}, status=200) # WD0102 管理员上传新词语 elif request.method == "POST": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) token = request.headers["token"] user = token_check(token, settings.JWT_KEY, -1) if user: @@ -110,7 +110,7 @@ def searchWords(request): return JsonResponse({}, status=401) # WD0202 词语内容批量获取 elif request.method == "PUT": - body = demjson.decode(request.body) + body = demjson3.decode(request.body) words = [] result = Word.objects.filter(id__in=body["words"]) result = filterInOrder(result, body["words"]) @@ -161,7 +161,7 @@ def put(self, request, id): raise WordNotFoundException() word = word[0] token = token_pass(request.headers, word.contributor.id) - body = demjson.decode(request.body) + body = demjson3.decode(request.body) body = body["word"] word_form = WordForm(body) item = re.split("[^a-z]", str(word.standard_pinyin)) # 去括号引号 @@ -212,7 +212,7 @@ def delete(self, request, id): def load_word(request): try: # WD0301 文件批量添加 - body = demjson.decode(request.body) + body = demjson3.decode(request.body) file = body["file"] sheet = open(os.path.join("material", "word", file)) lines = sheet.readlines() @@ -419,7 +419,7 @@ def get(self, request) -> JsonResponse: class DictionarySearch(View): def post(self, request) -> JsonResponse: - body = demjson.decode(request.body) + body = demjson3.decode(request.body) query = r"^" length = 0 if body["order"]: