mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-28 16:12:13 +00:00
admin修改username后update submissions;
problem id refresh api
This commit is contained in:
parent
2d00ed802d
commit
343eff1c51
@ -4,7 +4,8 @@ from ..views.oj import (ApplyResetPasswordAPI, ResetPasswordAPI,
|
||||
UserChangePasswordAPI, UserRegisterAPI, UserChangeEmailAPI,
|
||||
UserLoginAPI, UserLogoutAPI, UsernameOrEmailCheck,
|
||||
AvatarUploadAPI, TwoFactorAuthAPI, UserProfileAPI,
|
||||
UserRankAPI, CheckTFARequiredAPI, SessionManagementAPI)
|
||||
UserRankAPI, CheckTFARequiredAPI, SessionManagementAPI,
|
||||
ProfileProblemDisplayIDRefreshAPI)
|
||||
|
||||
from utils.captcha.views import CaptchaAPIView
|
||||
|
||||
@ -19,6 +20,7 @@ urlpatterns = [
|
||||
url(r"^captcha/?$", CaptchaAPIView.as_view(), name="show_captcha"),
|
||||
url(r"^check_username_or_email", UsernameOrEmailCheck.as_view(), name="check_username_or_email"),
|
||||
url(r"^profile/?$", UserProfileAPI.as_view(), name="user_profile_api"),
|
||||
url(r"^profile/fresh_display_id", ProfileProblemDisplayIDRefreshAPI.as_view(), name="display_id_fresh"),
|
||||
url(r"^upload_avatar/?$", AvatarUploadAPI.as_view(), name="avatar_upload_api"),
|
||||
url(r"^tfa_required/?$", CheckTFARequiredAPI.as_view(), name="tfa_required_check"),
|
||||
url(r"^two_factor_auth/?$", TwoFactorAuthAPI.as_view(), name="two_factor_auth_api"),
|
||||
|
@ -1,5 +1,6 @@
|
||||
from django.db.models import Q
|
||||
|
||||
from submission.models import Submission
|
||||
from utils.api import APIView, validate_serializer
|
||||
from utils.shortcuts import rand_str
|
||||
|
||||
@ -25,6 +26,7 @@ class UserAdminAPI(APIView):
|
||||
if User.objects.filter(email=data["email"].lower()).exclude(id=user.id).exists():
|
||||
return self.error("Email already exists")
|
||||
|
||||
pre_username = user.username
|
||||
user.username = data["username"]
|
||||
user.email = data["email"]
|
||||
user.admin_type = data["admin_type"]
|
||||
@ -58,6 +60,8 @@ class UserAdminAPI(APIView):
|
||||
user.two_factor_auth = data["two_factor_auth"]
|
||||
|
||||
user.save()
|
||||
if pre_username != user.username:
|
||||
Submission.objects.filter(username=pre_username).update(username=user.username)
|
||||
return self.success(UserSerializer(user).data)
|
||||
|
||||
@super_admin_required
|
||||
|
@ -11,6 +11,7 @@ from django.utils.timezone import now
|
||||
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||
from otpauth import OtpAuth
|
||||
|
||||
from problem.models import Problem
|
||||
from utils.constants import ContestRuleType
|
||||
from options.options import SysOptions
|
||||
from utils.api import APIView, validate_serializer
|
||||
@ -379,3 +380,21 @@ class UserRankAPI(APIView):
|
||||
else:
|
||||
profiles = profiles.filter(total_score__gt=0).order_by("-total_score")
|
||||
return self.success(self.paginate_data(request, profiles, RankInfoSerializer))
|
||||
|
||||
|
||||
class ProfileProblemDisplayIDRefreshAPI(APIView):
|
||||
@login_required
|
||||
def get(self, request):
|
||||
profile = request.user.userprofile
|
||||
acm_problems = profile.acm_problems_status["problems"]
|
||||
oi_problems = profile.oi_problems_status["problems"]
|
||||
ids = list(acm_problems.keys()) + list(oi_problems.keys())
|
||||
display_ids = Problem.objects.filter(id__in=ids).values_list("_id", flat=True)
|
||||
id_map = dict(zip(ids, display_ids))
|
||||
print(id_map)
|
||||
for k, v in acm_problems.items():
|
||||
v["_id"] = id_map[k]
|
||||
for k, v in oi_problems.items():
|
||||
v["_id"] = id_map[k]
|
||||
profile.save(update_fields=["acm_problems_status", "oi_problems_status"])
|
||||
return self.success()
|
||||
|
@ -16,7 +16,7 @@ class ContestAnnouncementListAPI(APIView):
|
||||
def get(self, request):
|
||||
contest_id = request.GET.get("contest_id")
|
||||
if not contest_id:
|
||||
return self.error("Invalid parameter")
|
||||
return self.error("Invalid parameter, contest_id is required")
|
||||
data = ContestAnnouncement.objects.select_related("created_by").filter(contest_id=contest_id, visible=True)
|
||||
max_id = request.GET.get("max_id")
|
||||
if max_id:
|
||||
@ -28,7 +28,7 @@ class ContestAPI(APIView):
|
||||
def get(self, request):
|
||||
id = request.GET.get("id")
|
||||
if not id:
|
||||
return self.error("Invalid parameter")
|
||||
return self.error("Invalid parameter, id is required")
|
||||
try:
|
||||
contest = Contest.objects.get(id=id)
|
||||
return self.success(ContestSerializer(contest).data)
|
||||
|
Loading…
Reference in New Issue
Block a user