Skip to content

Commit

Permalink
update(project): only for test.
Browse files Browse the repository at this point in the history
  • Loading branch information
CapooL committed Mar 14, 2024
1 parent 0c458b7 commit b7cd08c
Show file tree
Hide file tree
Showing 30 changed files with 91 additions and 94 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
16 changes: 8 additions & 8 deletions hinghwa-dict-backend/article/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}) 已通过审核"
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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 = []
Expand Down
8 changes: 4 additions & 4 deletions hinghwa-dict-backend/music/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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 = []
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions hinghwa-dict-backend/quiz/cert/view/cert_all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import demjson
import demjson3
from django.http import JsonResponse
from django.views import View
from ...models import Cert
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions hinghwa-dict-backend/quiz/paper/view/manage_all.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(",")
Expand Down
1 change: 0 additions & 1 deletion hinghwa-dict-backend/quiz/paper/view/manage_single.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import demjson
from django.http import JsonResponse
from ..dto.paper_all import paper_all
from django.views import View
Expand Down
1 change: 0 additions & 1 deletion hinghwa-dict-backend/quiz/paper/view/paper_record_all.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions hinghwa-dict-backend/quiz/quiz_record/view/quiz_record_all.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions hinghwa-dict-backend/quiz/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import demjson
import demjson3
from django.http import JsonResponse
from django.conf import settings
from django.views import View
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})已通过审核"
Expand Down
2 changes: 1 addition & 1 deletion hinghwa-dict-backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions hinghwa-dict-backend/rewards/orders/views/Manage_all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import demjson
import demjson3
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions hinghwa-dict-backend/rewards/orders/views/Manage_single.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions hinghwa-dict-backend/rewards/products/views/Manage_all.py
Original file line number Diff line number Diff line change
@@ -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
Expand 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()
Expand Down
4 changes: 2 additions & 2 deletions hinghwa-dict-backend/rewards/products/views/Manage_single.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions hinghwa-dict-backend/rewards/titles/views/Manage_all.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions hinghwa-dict-backend/rewards/titles/views/Manage_single.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions hinghwa-dict-backend/user/view/forget.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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("用户名不匹配")
Expand Down
8 changes: 4 additions & 4 deletions hinghwa-dict-backend/user/view/manage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import demjson
import demjson3
from django.db.models import Sum
from django.http import JsonResponse
from django.views import View
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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"])
Expand All @@ -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"]
Expand Down
Loading

0 comments on commit b7cd08c

Please sign in to comment.