From 046baa65ccce3b1e681f5d2c7f48eaad5685ee25 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Sun, 28 Apr 2024 10:06:37 +0100 Subject: [PATCH 1/6] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E7=AE=80=E5=8C=96`video?= =?UTF-8?q?=5Fquery`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back_end/saolei/saolei/settings.py | 19 +++++++------- back_end/saolei/videomanager/views.py | 38 ++++++++++++--------------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/back_end/saolei/saolei/settings.py b/back_end/saolei/saolei/settings.py index f0934ff6..32c66ecc 100644 --- a/back_end/saolei/saolei/settings.py +++ b/back_end/saolei/saolei/settings.py @@ -221,16 +221,17 @@ EMAIL_HOST_PASSWORD = "TdS2ZPt2izAkY25b" # 密码 (注意:这里的密码指的是授权码) # EMAIL_USE_SSL = True # EMAIL_FROM = "wangjianing@88.com" # 邮箱来自 + EMAIL_SKIP = False # 是否跳过邮箱验证。用于调试 -if EMAIL_SKIP: # 以防万一忘了改EMAIL_SKIP - print("已跳过邮箱验证步骤!") - user_input = input("Do you want to continue? (y/n): ") - if user_input.lower() != 'y': - raise SystemExit("Program terminated.") - -BAIDU_VERIFY_SKIP = False -if BAIDU_VERIFY_SKIP: # 以防万一忘了改BAIDU_VERIFY_SKIP - print("已跳过网络审查步骤!") +BAIDU_VERIFY_SKIP = False # 是否跳过审查步骤。用于调试 +DESIGNATOR_SKIP = False # 是否跳过标识检查。用于调试 +if EMAIL_SKIP or BAIDU_VERIFY_SKIP or DESIGNATOR_SKIP: # 以防万一忘了改 + if EMAIL_SKIP: + print("已跳过邮箱验证步骤!\n") + if BAIDU_VERIFY_SKIP: + print("已跳过网络审查步骤!\n") + if DESIGNATOR_SKIP: + print("已跳过标识检查步骤!\n") user_input = input("Do you want to continue? (y/n): ") if user_input.lower() != 'y': raise SystemExit("Program terminated.") diff --git a/back_end/saolei/videomanager/views.py b/back_end/saolei/videomanager/views.py index 2b9fb97a..cadb2efd 100644 --- a/back_end/saolei/videomanager/views.py +++ b/back_end/saolei/videomanager/views.py @@ -163,8 +163,6 @@ def video_download(request): # return response # except Exception: # return JsonResponse({"status": 104, "msg": "file not exist!"}) - - # 录像查询(无需登录) # 按任何基础指标+难度+模式,排序,分页 @@ -172,6 +170,7 @@ def video_download(request): def video_query(request): if request.method == 'GET': data = request.GET + # videos = VideoModel.objects.filter(*data["filter"]).order_by(*data["order_by"]).values(*data["values"]) index = data["index"] if index[0] == '-': order_index = "-video__" + index[1:] @@ -180,32 +179,29 @@ def video_query(request): order_index = values_index = "video__" + index if data["mode"] != "00": + filter = {"level": data["level"], "mode": data["mode"]} if index in {"id", "upload_time", "bv", "bvs", "-upload_time", "-bv", "-bvs"}: - videos = VideoModel.objects.filter(level=data["level"], mode=data["mode"])\ - .order_by(index, "timems")\ - .values("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems") + orderby = (index, "timems") + values = ("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems") elif index == "timems" or index == "-timems": - videos = VideoModel.objects.filter(level=data["level"], mode=data["mode"])\ - .order_by(index)\ - .values("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems") + orderby = (index,) + values = ("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems") else: - videos = VideoModel.objects.filter(level=data["level"], mode=data["mode"])\ - .order_by(order_index, "timems")\ - .values("id", "upload_time", "player__realname", "player__id", "bv", - "bvs", "timems", values_index) + orderby = (order_index, "timems") + values = ("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems", values_index) + videos = VideoModel.objects.filter(**filter).order_by(*orderby).values(*values) else: + filter = {"level": data["level"]} if index in {"id", "upload_time", "bv", "bvs", "-upload_time", "-bv", "-bvs"}: - videos = VideoModel.objects.filter(Q(mode="00")|Q(mode="12")).filter(level=data["level"])\ - .order_by(index, "timems")\ - .values("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems") + orderby = (index, "timems") + values = ("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems") elif index == "timems" or index == "-timems": - videos = VideoModel.objects.filter(Q(mode="00")|Q(mode="12")).filter(level=data["level"])\ - .order_by(index)\ - .values("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems") + orderby = (index,) + values = ("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems") else: - videos = VideoModel.objects.filter(Q(mode="00")|Q(mode="12")).filter(level=data["level"])\ - .order_by(order_index, "timems")\ - .values("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems", values_index) + orderby = (order_index, "timems") + values = ("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems", values_index) + videos = VideoModel.objects.filter(Q(mode="00")|Q(mode="12")).filter(**filter).order_by(*orderby).values(*values) # print(videos) paginator = Paginator(videos, 20) # 每页20条数据 From a77ae718340b921008a5608f3eeb3863a9ffb114 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Sun, 28 Apr 2024 10:10:14 +0100 Subject: [PATCH 2/6] Update views.py --- back_end/saolei/videomanager/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/back_end/saolei/videomanager/views.py b/back_end/saolei/videomanager/views.py index cadb2efd..3b1d7803 100644 --- a/back_end/saolei/videomanager/views.py +++ b/back_end/saolei/videomanager/views.py @@ -24,6 +24,8 @@ # import ms_toollib as ms from django.utils.encoding import escape_uri_path +from saolei.settings import DESIGNATOR_SKIP + logging.getLogger('apscheduler.scheduler').setLevel(logging.WARNING) logger = logging.getLogger(__name__) @@ -41,7 +43,7 @@ def video_upload(request): # print(video_form) if video_form.is_valid(): data = video_form.cleaned_data - if data["designator"] not in request.user.userms.designators: + if not DESIGNATOR_SKIP and data["designator"] not in request.user.userms.designators: # 如果标识是首次使用的,需要得到管理员的审核 data['review_code'] = 2 From a4918d500993db8b22ded60539e14212792cf7e6 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Sun, 28 Apr 2024 10:51:05 +0100 Subject: [PATCH 3/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E9=80=89=E9=A1=B9=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend.yml | 23 +++++++++++++++++++++++ back_end/saolei/config/flags.py | 3 +++ back_end/saolei/test/__main__.py | 19 +++++++++++++++++++ back_end/saolei/userprofile/views.py | 5 +++-- back_end/saolei/utils/__init__.py | 2 +- back_end/saolei/videomanager/views.py | 2 +- 6 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/backend.yml create mode 100644 back_end/saolei/config/flags.py create mode 100644 back_end/saolei/test/__main__.py diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 00000000..b959ce18 --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,23 @@ +name: Back-end Test + +on: + push: + branches: + - main # Adjust the branch name as needed + pull_request: + +jobs: + check_flag: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.10' # Choose the Python version you want to use + + - name: Run Test + run: python back_end/saolei/test \ No newline at end of file diff --git a/back_end/saolei/config/flags.py b/back_end/saolei/config/flags.py new file mode 100644 index 00000000..fab2fbcf --- /dev/null +++ b/back_end/saolei/config/flags.py @@ -0,0 +1,3 @@ +EMAIL_SKIP = True # 是否跳过邮箱验证。用于调试 +BAIDU_VERIFY_SKIP = False # 是否跳过审查步骤。用于调试 +DESIGNATOR_SKIP = True # 是否跳过标识检查。用于调试 \ No newline at end of file diff --git a/back_end/saolei/test/__main__.py b/back_end/saolei/test/__main__.py new file mode 100644 index 00000000..ed3bee14 --- /dev/null +++ b/back_end/saolei/test/__main__.py @@ -0,0 +1,19 @@ +import sys +import os + +# Get the parent directory of the current directory (my_script) +parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) + +# Add the parent directory to the Python path +sys.path.append(parent_dir) + +from config.flags import * + +def main(): + print(EMAIL_SKIP) + assert EMAIL_SKIP == False + assert BAIDU_VERIFY_SKIP == False + assert DESIGNATOR_SKIP == False + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/back_end/saolei/userprofile/views.py b/back_end/saolei/userprofile/views.py index b606cb81..4315239c 100644 --- a/back_end/saolei/userprofile/views.py +++ b/back_end/saolei/userprofile/views.py @@ -22,6 +22,7 @@ from django_ratelimit.decorators import ratelimit from django.utils import timezone from django.conf import settings +from config.flags import EMAIL_SKIP User = get_user_model() @@ -152,9 +153,9 @@ def user_register(request): email_captcha = request.POST.get("email_captcha", None) get_email_captcha = EmailVerifyRecord.objects.filter(hashkey=emailHashkey).first() # get_email_captcha = EmailVerifyRecord.objects.filter(hashkey="5f0db744-180b-4d9f-af5a-2986f4a78769").first() - if settings.EMAIL_SKIP or (get_email_captcha and email_captcha and get_email_captcha.code == email_captcha and\ + if EMAIL_SKIP or (get_email_captcha and email_captcha and get_email_captcha.code == email_captcha and\ get_email_captcha.email == request.POST.get("email", None)): - if settings.EMAIL_SKIP or (timezone.now() - get_email_captcha.send_time).seconds <= 3600: + if EMAIL_SKIP or (timezone.now() - get_email_captcha.send_time).seconds <= 3600: new_user = user_register_form.save(commit=False) # 设置密码(哈希) new_user.set_password( diff --git a/back_end/saolei/utils/__init__.py b/back_end/saolei/utils/__init__.py index e6416503..b8c80fee 100644 --- a/back_end/saolei/utils/__init__.py +++ b/back_end/saolei/utils/__init__.py @@ -6,7 +6,7 @@ from django.http import HttpResponse, JsonResponse, FileResponse from django.shortcuts import render, redirect import requests -from saolei.settings import BAIDU_VERIFY_SKIP +from config.flags import BAIDU_VERIFY_SKIP def generate_code(code_len): """ diff --git a/back_end/saolei/videomanager/views.py b/back_end/saolei/videomanager/views.py index 3b1d7803..14c9bade 100644 --- a/back_end/saolei/videomanager/views.py +++ b/back_end/saolei/videomanager/views.py @@ -24,7 +24,7 @@ # import ms_toollib as ms from django.utils.encoding import escape_uri_path -from saolei.settings import DESIGNATOR_SKIP +from config.flags import DESIGNATOR_SKIP logging.getLogger('apscheduler.scheduler').setLevel(logging.WARNING) logger = logging.getLogger(__name__) From 650ec998d1514b17476cd1653ddbef9ffc765ba8 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Sun, 28 Apr 2024 10:53:04 +0100 Subject: [PATCH 4/6] Update settings.py --- back_end/saolei/saolei/settings.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/back_end/saolei/saolei/settings.py b/back_end/saolei/saolei/settings.py index 32c66ecc..3c86ffc1 100644 --- a/back_end/saolei/saolei/settings.py +++ b/back_end/saolei/saolei/settings.py @@ -222,20 +222,6 @@ # EMAIL_USE_SSL = True # EMAIL_FROM = "wangjianing@88.com" # 邮箱来自 -EMAIL_SKIP = False # 是否跳过邮箱验证。用于调试 -BAIDU_VERIFY_SKIP = False # 是否跳过审查步骤。用于调试 -DESIGNATOR_SKIP = False # 是否跳过标识检查。用于调试 -if EMAIL_SKIP or BAIDU_VERIFY_SKIP or DESIGNATOR_SKIP: # 以防万一忘了改 - if EMAIL_SKIP: - print("已跳过邮箱验证步骤!\n") - if BAIDU_VERIFY_SKIP: - print("已跳过网络审查步骤!\n") - if DESIGNATOR_SKIP: - print("已跳过标识检查步骤!\n") - user_input = input("Do you want to continue? (y/n): ") - if user_input.lower() != 'y': - raise SystemExit("Program terminated.") - SESSION_COOKIE_NAME = "session_id" # Session的cookie保存在浏览器上时的key SESSION_COOKIE_PATH = "/" # Session的cookie保存的路径(默认) SESSION_COOKIE_DOMAIN = None # Session的cookie保存的域名(默认) From 0baca39fa724f02faaadd446abc63b1bc18d1c62 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Sun, 28 Apr 2024 10:54:23 +0100 Subject: [PATCH 5/6] Update flags.py --- back_end/saolei/config/flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back_end/saolei/config/flags.py b/back_end/saolei/config/flags.py index fab2fbcf..43274410 100644 --- a/back_end/saolei/config/flags.py +++ b/back_end/saolei/config/flags.py @@ -1,3 +1,3 @@ EMAIL_SKIP = True # 是否跳过邮箱验证。用于调试 BAIDU_VERIFY_SKIP = False # 是否跳过审查步骤。用于调试 -DESIGNATOR_SKIP = True # 是否跳过标识检查。用于调试 \ No newline at end of file +DESIGNATOR_SKIP = False # 是否跳过标识检查。用于调试 \ No newline at end of file From 52e22734b8b0ec1883ad11e9761ee6534a1de623 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Sun, 28 Apr 2024 11:50:30 +0100 Subject: [PATCH 6/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend.yml | 2 +- back_end/saolei/test/__main__.py | 19 ------------------- back_end/saolei/tests.py | 21 +++++++++++++++++++++ 3 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 back_end/saolei/test/__main__.py create mode 100644 back_end/saolei/tests.py diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index b959ce18..b4334362 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -20,4 +20,4 @@ jobs: python-version: '3.10' # Choose the Python version you want to use - name: Run Test - run: python back_end/saolei/test \ No newline at end of file + run: python -m unittest back_end/saolei/tests.py -v \ No newline at end of file diff --git a/back_end/saolei/test/__main__.py b/back_end/saolei/test/__main__.py deleted file mode 100644 index ed3bee14..00000000 --- a/back_end/saolei/test/__main__.py +++ /dev/null @@ -1,19 +0,0 @@ -import sys -import os - -# Get the parent directory of the current directory (my_script) -parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) - -# Add the parent directory to the Python path -sys.path.append(parent_dir) - -from config.flags import * - -def main(): - print(EMAIL_SKIP) - assert EMAIL_SKIP == False - assert BAIDU_VERIFY_SKIP == False - assert DESIGNATOR_SKIP == False - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/back_end/saolei/tests.py b/back_end/saolei/tests.py new file mode 100644 index 00000000..4aa08f08 --- /dev/null +++ b/back_end/saolei/tests.py @@ -0,0 +1,21 @@ +import unittest + +import sys +import os + +# Get the parent directory of the current directory (my_script) +parent_dir = os.path.abspath(os.path.dirname(__file__)) + +# Add the parent directory to the Python path +sys.path.append(parent_dir) + +from config.flags import * + +class TestFlags(unittest.TestCase): + def test_skip(self): + self.assertFalse(EMAIL_SKIP) + self.assertFalse(BAIDU_VERIFY_SKIP) + self.assertFalse(DESIGNATOR_SKIP) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file