mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-29 08:32:08 +00:00
添加initinstall命令
This commit is contained in:
parent
c16543c830
commit
2d00ed802d
@ -1,4 +1,3 @@
|
||||
from django.core.exceptions import MultipleObjectsReturned
|
||||
from django.db.models import Q
|
||||
|
||||
from utils.api import APIView, validate_serializer
|
||||
|
@ -26,7 +26,7 @@ if [ $? -ne 0 ]; then
|
||||
let "n+=1"
|
||||
continue
|
||||
fi
|
||||
python manage.py initadmin
|
||||
python manage.py initinstall
|
||||
break
|
||||
done
|
||||
|
||||
|
@ -120,3 +120,8 @@ class ContestProblemSafeSerializer(BaseProblemSerializer):
|
||||
model = Problem
|
||||
exclude = ("test_case_score", "test_case_id", "visible", "is_public", "difficulty",
|
||||
"submission_number", "accepted_number", "statistic_info")
|
||||
|
||||
|
||||
class ContestProblemMakePublicSerializer(serializers.Serializer):
|
||||
id = serializers.IntegerField()
|
||||
display_id = serializers.CharField(max_length=32)
|
||||
|
@ -13,7 +13,7 @@ from utils.shortcuts import rand_str, natural_sort_key
|
||||
from ..models import Problem, ProblemRuleType, ProblemTag
|
||||
from ..serializers import (CreateContestProblemSerializer, ContestProblemAdminSerializer,
|
||||
CreateProblemSerializer, EditProblemSerializer, EditContestProblemSerializer,
|
||||
ProblemAdminSerializer, TestCaseUploadForm)
|
||||
ProblemAdminSerializer, TestCaseUploadForm, ContestProblemMakePublicSerializer)
|
||||
|
||||
|
||||
class TestCaseUploadAPI(CSRFExemptAPIView):
|
||||
@ -339,15 +339,19 @@ class ContestProblemAPI(ProblemBase):
|
||||
|
||||
|
||||
class MakeContestProblemPublicAPIView(APIView):
|
||||
@validate_serializer(ContestProblemMakePublicSerializer)
|
||||
@problem_permission_required
|
||||
def post(self, request):
|
||||
problem_id = request.data.get("problem_id")
|
||||
if not problem_id:
|
||||
return self.error("problem_id is required")
|
||||
data = request.data
|
||||
display_id = data.get("display_id")
|
||||
if Problem.objects.filter(_id=display_id, contest_id__isnull=True).exists():
|
||||
return self.error("Duplicate display ID")
|
||||
|
||||
try:
|
||||
problem = Problem.objects.get(id=problem_id)
|
||||
problem = Problem.objects.get(id=data["id"])
|
||||
except Problem.DoesNotExist:
|
||||
return self.error("Problem does not exist")
|
||||
|
||||
if not problem.contest or problem.is_public:
|
||||
return self.error("Alreay be a public problem")
|
||||
problem.is_public = True
|
||||
@ -356,6 +360,7 @@ class MakeContestProblemPublicAPIView(APIView):
|
||||
tags = problem.tags.all()
|
||||
problem.pk = None
|
||||
problem.contest = None
|
||||
problem._id = display_id
|
||||
problem.submission_number = problem.accepted_number = 0
|
||||
problem.statistic_info = {}
|
||||
problem.save()
|
||||
|
@ -4,6 +4,7 @@ from judge.tasks import judge_task
|
||||
# from judge.dispatcher import JudgeDispatcher
|
||||
from problem.models import Problem, ProblemRuleType
|
||||
from contest.models import Contest, ContestStatus, ContestRuleType
|
||||
from options.options import SysOptions
|
||||
from utils.api import APIView, validate_serializer
|
||||
from utils.throttling import TokenBucket, BucketController
|
||||
from utils.captcha import Captcha
|
||||
@ -144,7 +145,7 @@ class SubmissionListAPI(APIView):
|
||||
except Problem.DoesNotExist:
|
||||
return self.error("Problem doesn't exist")
|
||||
submissions = submissions.filter(problem=problem)
|
||||
if myself and myself == "1":
|
||||
if (myself and myself == "1") and not SysOptions.submission_list_show_all:
|
||||
submissions = submissions.filter(user_id=request.user.id)
|
||||
elif username:
|
||||
submissions = submissions.filter(username=username)
|
||||
|
@ -1,4 +1,3 @@
|
||||
import os
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from account.models import AdminType, ProblemPermission, User, UserProfile
|
||||
@ -10,7 +9,6 @@ class Command(BaseCommand):
|
||||
try:
|
||||
admin = User.objects.get(username="root")
|
||||
if admin.admin_type == AdminType.SUPER_ADMIN:
|
||||
if os.environ.get("OJ_ENV") != "production":
|
||||
self.stdout.write(self.style.WARNING("Super admin user 'root' already exists, "
|
||||
"would you like to reset it's password?\n"
|
||||
"Input yes to confirm: "))
|
||||
|
17
utils/management/commands/initinstall.py
Normal file
17
utils/management/commands/initinstall.py
Normal file
@ -0,0 +1,17 @@
|
||||
import os
|
||||
from account.models import User
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
if User.objects.exists():
|
||||
self.stdout.write(self.style.WARNING("Nothing happened\n"))
|
||||
return
|
||||
try:
|
||||
if os.system("python manage.py initadmin") != 0:
|
||||
self.stdout.write(self.style.ERROR("Failed to execute command 'initadmin'"))
|
||||
exit(1)
|
||||
self.stdout.write(self.style.SUCCESS("Done"))
|
||||
except Exception as e:
|
||||
self.stdout.write(self.style.ERROR("Failed to initialize, error: " + str(e)))
|
Loading…
Reference in New Issue
Block a user