From e7ef1fb70916cc049fcea6124e6a641a9be63578 Mon Sep 17 00:00:00 2001 From: eee555 <2234208506@qq.com> Date: Wed, 7 Aug 2024 22:00:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?designator=E4=BF=AE=E6=94=B9=E4=B8=BAidenti?= =?UTF-8?q?fier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{designator => identifier}/__init__.py | 0 .../saolei/{designator => identifier}/apps.py | 4 +- .../{designator => identifier}/models.py | 4 +- .../saolei/{designator => identifier}/urls.py | 2 +- .../{designator => identifier}/utils.py | 8 ++-- .../{designator => identifier}/views.py | 42 +++++++++---------- back_end/saolei/manage.py | 2 +- back_end/saolei/saolei/settings.py | 2 +- back_end/saolei/saolei/urls.py | 2 +- back_end/saolei/videomanager/models.py | 4 +- back_end/saolei/videomanager/view_utils.py | 4 +- back_end/saolei/videomanager/views.py | 12 +++--- 12 files changed, 43 insertions(+), 43 deletions(-) rename back_end/saolei/{designator => identifier}/__init__.py (100%) rename back_end/saolei/{designator => identifier}/apps.py (61%) rename back_end/saolei/{designator => identifier}/models.py (67%) rename back_end/saolei/{designator => identifier}/urls.py (85%) rename back_end/saolei/{designator => identifier}/utils.py (59%) rename back_end/saolei/{designator => identifier}/views.py (65%) diff --git a/back_end/saolei/designator/__init__.py b/back_end/saolei/identifier/__init__.py similarity index 100% rename from back_end/saolei/designator/__init__.py rename to back_end/saolei/identifier/__init__.py diff --git a/back_end/saolei/designator/apps.py b/back_end/saolei/identifier/apps.py similarity index 61% rename from back_end/saolei/designator/apps.py rename to back_end/saolei/identifier/apps.py index fb3fd091..8673b596 100644 --- a/back_end/saolei/designator/apps.py +++ b/back_end/saolei/identifier/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig -class DesignatorConfig(AppConfig): +class IdentifierConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" - name = "designator" \ No newline at end of file + name = "identifier" \ No newline at end of file diff --git a/back_end/saolei/designator/models.py b/back_end/saolei/identifier/models.py similarity index 67% rename from back_end/saolei/designator/models.py rename to back_end/saolei/identifier/models.py index 3941cc8c..91b742ea 100644 --- a/back_end/saolei/designator/models.py +++ b/back_end/saolei/identifier/models.py @@ -1,7 +1,7 @@ from django.db import models from msuser.models import UserMS -class Designator(models.Model): - designator = models.CharField(max_length=128, unique=True) +class Identifier(models.Model): + identifier = models.CharField(max_length=128, unique=True) userms = models.ForeignKey(UserMS, null=True, on_delete=models.CASCADE, db_index=True) safe = models.BooleanField(default=False) \ No newline at end of file diff --git a/back_end/saolei/designator/urls.py b/back_end/saolei/identifier/urls.py similarity index 85% rename from back_end/saolei/designator/urls.py rename to back_end/saolei/identifier/urls.py index 17b522e0..8c4b3865 100644 --- a/back_end/saolei/designator/urls.py +++ b/back_end/saolei/identifier/urls.py @@ -1,7 +1,7 @@ from django.urls import path from . import views -app_name = 'designator' +app_name = 'identifier' urlpatterns = [ path('del/', views.del_designator), path('add/', views.add_designator), diff --git a/back_end/saolei/designator/utils.py b/back_end/saolei/identifier/utils.py similarity index 59% rename from back_end/saolei/designator/utils.py rename to back_end/saolei/identifier/utils.py index 1b5085e8..6ba28bd3 100644 --- a/back_end/saolei/designator/utils.py +++ b/back_end/saolei/identifier/utils.py @@ -3,13 +3,13 @@ from videomanager.view_utils import update_personal_record_stock, update_state from utils import verify_text -from .models import Designator +from .models import Identifier # 审查标识 # 若未记录该标识则创建条目 -def verify_designator(designator: str): - collision = Designator.objects.filter(designator=designator).first() +def verify_designator(identifier: str): + collision = Identifier.objects.filter(identifier=identifier).first() if collision: return collision.safe - new_designator = Designator.objects.create(designator=designator, safe=verify_text(designator)) + new_designator = Identifier.objects.create(identifier=identifier, safe=verify_text(identifier)) return new_designator.safe diff --git a/back_end/saolei/designator/views.py b/back_end/saolei/identifier/views.py similarity index 65% rename from back_end/saolei/designator/views.py rename to back_end/saolei/identifier/views.py index 30282bf1..7b29cc47 100644 --- a/back_end/saolei/designator/views.py +++ b/back_end/saolei/identifier/views.py @@ -1,5 +1,5 @@ from msuser.models import UserMS -from .models import Designator +from .models import Identifier from userprofile.models import UserProfile from django.http import HttpResponseNotAllowed, HttpResponseForbidden, HttpResponseBadRequest, JsonResponse, HttpResponse, HttpResponseNotFound from django.views.decorators.http import require_GET, require_POST @@ -13,30 +13,30 @@ def add_designator(request): user = UserProfile.objects.filter(id=request.user.id).first() if user == None: return HttpResponseForbidden() - designator_text = request.POST.get('designator') + designator_text = request.POST.get('identifier') if designator_text == None: return HttpResponseBadRequest() - designator = Designator.objects.filter(designator=designator_text).first() - if not designator or not designator.safe: - return JsonResponse({'type': 'error', 'object': 'designator', 'category': 'notFound'}) - if designator.userms: - designator_user = designator.userms.parent + identifier = Identifier.objects.filter(identifier=designator_text).first() + if not identifier or not identifier.safe: + return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'notFound'}) + if identifier.userms: + designator_user = identifier.userms.parent if designator_user.id == user.id: return HttpResponseConflict() # 本人已有该标识 - return JsonResponse({'type': 'error', 'object': 'designator', 'category': 'conflict', 'value': designator_user.id}) # 返回标识冲突的用户 + return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'conflict', 'value': designator_user.id}) # 返回标识冲突的用户 video_list = VideoModel.objects.filter(player=user, video__designator=designator_text) if not video_list: - return JsonResponse({'type': 'error', 'object': 'designator', 'category': 'notFound'}) + return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'notFound'}) for video in video_list: - if video.state == VideoModel.State.DESIGNATOR: + if video.state == VideoModel.State.IDENTIFIER: update_state(video, VideoModel.State.OFFICIAL) - designator.userms = user.userms - designator.save() + identifier.userms = user.userms + identifier.save() user.userms.designators.append(designator_text) user.userms.save() # TODO: 日志 - return JsonResponse({'type': 'success', 'object': 'designator', 'category': 'add', 'value': len(video_list)}) + return JsonResponse({'type': 'success', 'object': 'identifier', 'category': 'add', 'value': len(video_list)}) # 请求删除自己的标识 @require_POST @@ -44,26 +44,26 @@ def del_designator(request): user = UserProfile.objects.filter(id=request.user.id).first() if user == None: return HttpResponseForbidden() - designator_text = request.POST.get('designator', None) + designator_text = request.POST.get('identifier', None) if designator_text == None: return HttpResponseBadRequest() - designator = Designator.objects.filter(designator=designator_text).first() - if not designator: + identifier = Identifier.objects.filter(identifier=designator_text).first() + if not identifier: return HttpResponseNotFound() - if designator.userms.parent.id != user.id: + if identifier.userms.parent.id != user.id: return HttpResponseForbidden() - designator.userms = None - designator.save() + identifier.userms = None + identifier.save() user.userms.designators.remove(designator_text) user.userms.save() # TODO: 日志 video_list = VideoModel.objects.filter(player=user, video__designator=designator_text) for video in video_list: if video.state == VideoModel.State.OFFICIAL: - update_state(video, VideoModel.State.DESIGNATOR, update_ranking=False) + update_state(video, VideoModel.State.IDENTIFIER, update_ranking=False) if video_list: update_personal_record_stock(user) - return JsonResponse({'type': 'success', 'object': 'designator', 'category': 'add', 'value': len(video_list)}) + return JsonResponse({'type': 'success', 'object': 'identifier', 'category': 'add', 'value': len(video_list)}) # 管理员添加标识 def staff_add_designator(request): diff --git a/back_end/saolei/manage.py b/back_end/saolei/manage.py index 493120ea..c56508be 100644 --- a/back_end/saolei/manage.py +++ b/back_end/saolei/manage.py @@ -37,7 +37,7 @@ def main(): # 1,wangjianing@88.com,123456 # pip install django-simple-captcha # python manage.py makemigrations --empty msuser -# ALTER TABLE videomanager_expandvideomodel CHANGE designator identifier varchar(255); +# ALTER TABLE videomanager_expandvideomodel CHANGE identifier identifier varchar(255); # ALTER TABLE msuser_userms CHANGE designators identifiers json; diff --git a/back_end/saolei/saolei/settings.py b/back_end/saolei/saolei/settings.py index 7880dad0..a7950e88 100644 --- a/back_end/saolei/saolei/settings.py +++ b/back_end/saolei/saolei/settings.py @@ -56,7 +56,7 @@ 'msuser', 'article', "ranking", - 'designator', + 'identifier', "monitor", 'django_cleanup.apps.CleanupConfig', # 必须放在最后(文档所言) ] diff --git a/back_end/saolei/saolei/urls.py b/back_end/saolei/saolei/urls.py index 7712f9ae..e87c2081 100644 --- a/back_end/saolei/saolei/urls.py +++ b/back_end/saolei/saolei/urls.py @@ -32,7 +32,7 @@ path('msuser/', include('msuser.urls')), path('monitor/', include('monitor.urls')), path('article/', include('article.urls')), - path('designator/', include('designator.urls')), + path('identifier/', include('identifier.urls')), path(r'', TemplateView.as_view(template_name="index.html")), ] diff --git a/back_end/saolei/videomanager/models.py b/back_end/saolei/videomanager/models.py index 191e779d..3f637cf0 100644 --- a/back_end/saolei/videomanager/models.py +++ b/back_end/saolei/videomanager/models.py @@ -90,7 +90,7 @@ class State(models.TextChoices): PLAIN = "a", ('已上传但未审核') FROZEN = "b", ('审核未通过,被冻结') OFFICIAL = "c", ('已通过审核') - DESIGNATOR = "d", ('标识不匹配') + IDENTIFIER = "d", ('标识不匹配') class Level(models.TextChoices): BEGINNER = "b", ('初级') @@ -159,7 +159,7 @@ def push_redis(self, name: str): "timems": self.timems, "bv": self.bv, "bvs": self.bvs, - "designator": self.video.designator}, cls=ComplexEncoder)) + "identifier": self.video.identifier}, cls=ComplexEncoder)) def pop_redis(self, name: str): cache.hdel(name, self.id) diff --git a/back_end/saolei/videomanager/view_utils.py b/back_end/saolei/videomanager/view_utils.py index ac17ff5a..2d009054 100644 --- a/back_end/saolei/videomanager/view_utils.py +++ b/back_end/saolei/videomanager/view_utils.py @@ -26,7 +26,7 @@ state2redis = { VideoModel.State.PLAIN: 'review_queue', VideoModel.State.FROZEN: 'freeze_queue', - VideoModel.State.DESIGNATOR: 'newest_queue', + VideoModel.State.IDENTIFIER: 'newest_queue', VideoModel.State.OFFICIAL: 'newest_queue', } @@ -203,7 +203,7 @@ def update_state(video: VideoModel, state: VideoModel.State, update_ranking = Tr def new_video(data, user): e_video = ExpandVideoModel.objects.create( - designator=data["designator"], + identifier=data["identifier"], left=data["left"], right=data["right"], double=data["double"], diff --git a/back_end/saolei/videomanager/views.py b/back_end/saolei/videomanager/views.py index c52ab75e..62e8d24c 100644 --- a/back_end/saolei/videomanager/views.py +++ b/back_end/saolei/videomanager/views.py @@ -24,7 +24,7 @@ from django.utils import timezone # import ms_toollib as ms from django.conf import settings -from designator.utils import verify_designator +from identifier.utils import verify_designator from django.views.decorators.http import require_GET, require_POST @login_required(login_url='/') @@ -42,14 +42,14 @@ def video_upload(request): if not video_form.is_valid(): return HttpResponseBadRequest() data = video_form.cleaned_data - designator = data["designator"] - if not verify_designator(designator): # 标识不过审 - return JsonResponse({'type': 'error', 'object': 'designator', 'category': 'censorship'}) - if data['review_code'] == 0 and designator not in request.user.userms.designators: + identifier = data["identifier"] + if not verify_designator(identifier): # 标识不过审 + return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'censorship'}) + if data['review_code'] == 0 and identifier not in request.user.userms.designators: data['review_code'] = 2 # 标识不匹配 # 查重 - collisions = list(VideoModel.objects.filter(timems=data["timems"], bv=data["bv"]).filter(video__cl=data["cl"], video__op=data["op"], video__isl=data["isl"], video__designator=data["designator"])) + collisions = list(VideoModel.objects.filter(timems=data["timems"], bv=data["bv"]).filter(video__cl=data["cl"], video__op=data["op"], video__isl=data["isl"], video__designator=data["identifier"])) if collisions: return JsonResponse({'type': 'error', 'object': 'videomodel', 'category': 'conflict'}) new_video(data, request.user) # 表中添加数据 From 8d3899837f9f6262ceb76f1d0ea2e5937c304fe3 Mon Sep 17 00:00:00 2001 From: eee555 <2234208506@qq.com> Date: Wed, 7 Aug 2024 22:19:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?designator=E4=BF=AE=E6=94=B9=E4=B8=BAidenti?= =?UTF-8?q?fier(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- back_end/saolei/identifier/urls.py | 4 ++-- back_end/saolei/identifier/utils.py | 6 ++--- back_end/saolei/identifier/views.py | 34 +++++++++++++-------------- back_end/saolei/manage.py | 2 +- back_end/saolei/msuser/urls.py | 2 +- back_end/saolei/msuser/views.py | 4 ++-- back_end/saolei/videomanager/views.py | 8 +++---- 8 files changed, 32 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 66f0fea1..931ccc2c 100644 --- a/.gitignore +++ b/.gitignore @@ -171,8 +171,9 @@ front_end/public/flopold front_end/src/assets/article front_end/package-lock.json front_end/yarn.lock -/back_end/saolei/designator/migrations +/back_end/saolei/identifier/migrations /back_end/saolei/userprofile/migrations /back_end/saolei/videomanager/migrations /back_end/saolei/msuser/migrations + diff --git a/back_end/saolei/identifier/urls.py b/back_end/saolei/identifier/urls.py index 8c4b3865..2cd3e775 100644 --- a/back_end/saolei/identifier/urls.py +++ b/back_end/saolei/identifier/urls.py @@ -3,6 +3,6 @@ from . import views app_name = 'identifier' urlpatterns = [ - path('del/', views.del_designator), - path('add/', views.add_designator), + path('del/', views.del_identifier), + path('add/', views.add_identifier), ] \ No newline at end of file diff --git a/back_end/saolei/identifier/utils.py b/back_end/saolei/identifier/utils.py index 6ba28bd3..edca99da 100644 --- a/back_end/saolei/identifier/utils.py +++ b/back_end/saolei/identifier/utils.py @@ -7,9 +7,9 @@ # 审查标识 # 若未记录该标识则创建条目 -def verify_designator(identifier: str): +def verify_identifier(identifier: str): collision = Identifier.objects.filter(identifier=identifier).first() if collision: return collision.safe - new_designator = Identifier.objects.create(identifier=identifier, safe=verify_text(identifier)) - return new_designator.safe + new_identifier = Identifier.objects.create(identifier=identifier, safe=verify_text(identifier)) + return new_identifier.safe diff --git a/back_end/saolei/identifier/views.py b/back_end/saolei/identifier/views.py index 7b29cc47..f5f18b1b 100644 --- a/back_end/saolei/identifier/views.py +++ b/back_end/saolei/identifier/views.py @@ -9,23 +9,23 @@ # 请求修改自己的标识 @require_POST -def add_designator(request): +def add_identifier(request): user = UserProfile.objects.filter(id=request.user.id).first() if user == None: return HttpResponseForbidden() - designator_text = request.POST.get('identifier') - if designator_text == None: + identifier_text = request.POST.get('identifier') + if identifier_text == None: return HttpResponseBadRequest() - identifier = Identifier.objects.filter(identifier=designator_text).first() + identifier = Identifier.objects.filter(identifier=identifier_text).first() if not identifier or not identifier.safe: return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'notFound'}) if identifier.userms: - designator_user = identifier.userms.parent - if designator_user.id == user.id: + identifier_user = identifier.userms.parent + if identifier_user.id == user.id: return HttpResponseConflict() # 本人已有该标识 - return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'conflict', 'value': designator_user.id}) # 返回标识冲突的用户 - video_list = VideoModel.objects.filter(player=user, video__designator=designator_text) + return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'conflict', 'value': identifier_user.id}) # 返回标识冲突的用户 + video_list = VideoModel.objects.filter(player=user, video__identifier=identifier_text) if not video_list: return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'notFound'}) for video in video_list: @@ -33,31 +33,31 @@ def add_designator(request): update_state(video, VideoModel.State.OFFICIAL) identifier.userms = user.userms identifier.save() - user.userms.designators.append(designator_text) + user.userms.identifiers.append(identifier_text) user.userms.save() # TODO: 日志 return JsonResponse({'type': 'success', 'object': 'identifier', 'category': 'add', 'value': len(video_list)}) # 请求删除自己的标识 @require_POST -def del_designator(request): +def del_identifier(request): user = UserProfile.objects.filter(id=request.user.id).first() if user == None: return HttpResponseForbidden() - designator_text = request.POST.get('identifier', None) - if designator_text == None: + identifier_text = request.POST.get('identifier', None) + if identifier_text == None: return HttpResponseBadRequest() - identifier = Identifier.objects.filter(identifier=designator_text).first() + identifier = Identifier.objects.filter(identifier=identifier_text).first() if not identifier: return HttpResponseNotFound() if identifier.userms.parent.id != user.id: return HttpResponseForbidden() identifier.userms = None identifier.save() - user.userms.designators.remove(designator_text) + user.userms.identifiers.remove(identifier_text) user.userms.save() # TODO: 日志 - video_list = VideoModel.objects.filter(player=user, video__designator=designator_text) + video_list = VideoModel.objects.filter(player=user, video__identifier=identifier_text) for video in video_list: if video.state == VideoModel.State.OFFICIAL: update_state(video, VideoModel.State.IDENTIFIER, update_ranking=False) @@ -66,11 +66,11 @@ def del_designator(request): return JsonResponse({'type': 'success', 'object': 'identifier', 'category': 'add', 'value': len(video_list)}) # 管理员添加标识 -def staff_add_designator(request): +def staff_add_identifier(request): # TODO return HttpResponse() # 管理员删除标识 -def staff_del_designator(request): +def staff_del_identifier(request): # TODO return HttpResponse() \ No newline at end of file diff --git a/back_end/saolei/manage.py b/back_end/saolei/manage.py index c56508be..b5bb20a6 100644 --- a/back_end/saolei/manage.py +++ b/back_end/saolei/manage.py @@ -38,7 +38,7 @@ def main(): # pip install django-simple-captcha # python manage.py makemigrations --empty msuser # ALTER TABLE videomanager_expandvideomodel CHANGE identifier identifier varchar(255); -# ALTER TABLE msuser_userms CHANGE designators identifiers json; +# ALTER TABLE msuser_userms CHANGE identifiers identifiers json; diff --git a/back_end/saolei/msuser/urls.py b/back_end/saolei/msuser/urls.py index bff25eef..28e4f1c4 100644 --- a/back_end/saolei/msuser/urls.py +++ b/back_end/saolei/msuser/urls.py @@ -10,5 +10,5 @@ path('update_avatar/', views.update_avatar, name='update_avatar'), path('update_signature/', views.update_signature, name='update_signature'), path('player_rank/', views.player_rank, name='player_rank'), - path('designators/', views.get_designators, name='designators'), + path('identifiers/', views.get_identifiers, name='identifiers'), ] \ No newline at end of file diff --git a/back_end/saolei/msuser/views.py b/back_end/saolei/msuser/views.py index 5004cc93..79b346e3 100644 --- a/back_end/saolei/msuser/views.py +++ b/back_end/saolei/msuser/views.py @@ -134,7 +134,7 @@ def get_info_abstract(request): else: return HttpResponse("别瞎玩") -def get_designators(request): +def get_identifiers(request): if request.method != 'GET': return HttpResponseNotAllowed() id = request.GET.get('id') @@ -143,7 +143,7 @@ def get_designators(request): user = UserProfile.objects.filter(id=id).first() if not user: return HttpResponseNotFound() - return JsonResponse(user.userms.designators, safe=False) + return JsonResponse(user.userms.identifiers, safe=False) # 上传或更新我的地盘里的头像、姓名、个性签名 # 应该写到用户的app里,而不是玩家 diff --git a/back_end/saolei/videomanager/views.py b/back_end/saolei/videomanager/views.py index 62e8d24c..101af37e 100644 --- a/back_end/saolei/videomanager/views.py +++ b/back_end/saolei/videomanager/views.py @@ -24,7 +24,7 @@ from django.utils import timezone # import ms_toollib as ms from django.conf import settings -from identifier.utils import verify_designator +from identifier.utils import verify_identifier from django.views.decorators.http import require_GET, require_POST @login_required(login_url='/') @@ -43,13 +43,13 @@ def video_upload(request): return HttpResponseBadRequest() data = video_form.cleaned_data identifier = data["identifier"] - if not verify_designator(identifier): # 标识不过审 + if not verify_identifier(identifier): # 标识不过审 return JsonResponse({'type': 'error', 'object': 'identifier', 'category': 'censorship'}) - if data['review_code'] == 0 and identifier not in request.user.userms.designators: + if data['review_code'] == 0 and identifier not in request.user.userms.identifiers: data['review_code'] = 2 # 标识不匹配 # 查重 - collisions = list(VideoModel.objects.filter(timems=data["timems"], bv=data["bv"]).filter(video__cl=data["cl"], video__op=data["op"], video__isl=data["isl"], video__designator=data["identifier"])) + collisions = list(VideoModel.objects.filter(timems=data["timems"], bv=data["bv"]).filter(video__cl=data["cl"], video__op=data["op"], video__isl=data["isl"], video__identifier=data["identifier"])) if collisions: return JsonResponse({'type': 'error', 'object': 'videomodel', 'category': 'conflict'}) new_video(data, request.user) # 表中添加数据