Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新录像页 #22

Merged
merged 8 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion back_end/saolei/config/flags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
EMAIL_SKIP = True # 是否跳过邮箱验证。用于调试
EMAIL_SKIP = False # 是否跳过邮箱验证。用于调试
BAIDU_VERIFY_SKIP = False # 是否跳过审查步骤。用于调试
DESIGNATOR_SKIP = False # 是否跳过标识检查。用于调试
2 changes: 1 addition & 1 deletion back_end/saolei/saolei/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
try:
with open("secrets.json",'r') as f:
SECRET_KEY = json.load(f)["django_secret_key"]
except KeyError:
except:
SECRET_KEY = "django-insecure-3_(yjnup(rsxz&pd@stz25*meq10bn3m3$lt!n_1+s723#k=ay"

# SECURITY WARNING: don't run with debug turned on in production!
Expand Down
8 changes: 8 additions & 0 deletions back_end/saolei/videomanager/view_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
record_update_fields.append(f"{level}_{stat}_{mode}")
record_update_fields.append(f"{level}_{stat}_id_{mode}")

def fieldname_translate(name: str):
if name in [field.name for field in VideoModel._meta.get_fields()]:
return name
elif name in [field.name for field in ExpandVideoModel._meta.get_fields()]:
return "video__" + name
else:
return name

# 确定用户破某个纪录后,且对应模式、指标的三个级别全部有录像后,更新redis中的数据
def update_3_level_cache_record(realname: str, index: str, mode: str, ms_user: UserMS):
key = f"player_{index}_{mode}_{ms_user.id}"
Expand Down
44 changes: 16 additions & 28 deletions back_end/saolei/videomanager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.auth.decorators import login_required
from .forms import UploadVideoForm
from .models import VideoModel, ExpandVideoModel
from .view_utils import update_personal_record, update_personal_record_stock
from .view_utils import update_personal_record, update_personal_record_stock, fieldname_translate
from userprofile.models import UserProfile
from django.http import HttpResponse, JsonResponse, FileResponse
import json, urllib
Expand Down Expand Up @@ -168,49 +168,37 @@ def video_download(request):

# 录像查询(无需登录)
# 按任何基础指标+难度+模式,排序,分页
# 每项的定义参见 front_end/src/views/VideoView.vue 的 request_videos 函数
@ratelimit(key='ip', rate='20/m')
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:]
values_index = "video__" + index[1:]
else:
order_index = values_index = "video__" + index

values = [fieldname_translate(s) for s in data.getlist("v[]")]
values.append("id")

if data["r"] == "true":
ob = "-" + data["o"]
else:
ob = data["o"]
if data["o"] != "timems":
orderby = (ob, "timems")
else:
orderby = (ob,)

if data["mode"] != "00":
filter = {"level": data["level"], "mode": data["mode"]}
if index in {"id", "upload_time", "bv", "bvs", "-upload_time", "-bv", "-bvs"}:
orderby = (index, "timems")
values = ("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems")
elif index == "timems" or index == "-timems":
orderby = (index,)
values = ("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems")
else:
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"}:
orderby = (index, "timems")
values = ("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems")
elif index == "timems" or index == "-timems":
orderby = (index,)
values = ("id", "upload_time", "player__realname", "player__id", "bv", "bvs", "timems")
else:
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条数据
paginator = Paginator(videos, data["ps"])
page_number = data["page"]
page_videos = paginator.get_page(page_number)
response = {
"total_page": paginator.num_pages,
"count": len(videos),
"videos": list(page_videos)
}
# t=json.dumps(response, cls=ComplexEncoder)
Expand Down
Loading
Loading