-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lovin' the Django admin command interface
- Loading branch information
Showing
8 changed files
with
98 additions
and
44 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from core.models import CorrectSubmission, Team, Problem | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Clears the solves for a specific problem and takes away points.' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('problem', type=str, help='name of problem to clear points for') | ||
|
||
def handle(self, *args, **options): | ||
problem = Problem.objects.get(name=args['problem']) | ||
|
||
for team in Team.objects.all(): | ||
if problem in team.solved.all(): | ||
team.solved.remove(problem) | ||
|
||
correct = CorrectSubmission.objects.get(team=team, problem=problem) | ||
for submission in CorrectSubmission.objects.filter(team=team): | ||
if submission.time >= correct.time: | ||
submission.new_score -= problem.value | ||
submission.save() | ||
|
||
correct.delete() | ||
|
||
team.score -= problem.value | ||
team.save() | ||
|
||
problem.solves = 0 | ||
problem.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from core.models import CorrectSubmission, Team | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Recalculates all team scores in event of scoring error based on CorrectSubmission objects.' | ||
|
||
def handle(self, *args, **options): | ||
i = 0 | ||
|
||
for team in Team.objects.all(): | ||
score = 0 | ||
|
||
team.solved | ||
team.clear() | ||
|
||
for submission in CorrectSubmission.objects.all().filter(team=team).order_by('time'): | ||
score += submission.problem.value | ||
submission.new_score = score | ||
submission.save() | ||
team.solved.add(submission.problem) | ||
|
||
team.score = score | ||
team.save() | ||
|
||
i += 1 | ||
print("Fixed score for team {%d}/{%d}" % (i, Team.objects.count())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.contrib.auth.models import User | ||
|
||
from core.models import Problem, ProblemUpdate, CorrectSubmission, IncorrectSubmission, Team, UserProfile | ||
|
||
class Command(BaseCommand): | ||
help = 'Resets the CTF game for a new year.' | ||
|
||
def handle(self, *args, **options): | ||
def yesno(prompt, default=True): | ||
yes = ['yes', 'ye', 'y'] | ||
no = ['no', 'n'] | ||
|
||
answer = input(prompt + " [Y/n] ") | ||
while answer.lower() not in yes and answer.lower() not in no and answer != "": | ||
answer = input(prompt + " [Y/n] ") | ||
|
||
if answer == "": | ||
return default | ||
elif answer.lower() in yes: | ||
return True | ||
else: | ||
return False | ||
|
||
if yesno("Delete problems, updates, and submissions?"): | ||
Problem.objects.all().delete() | ||
ProblemUpdate.objects.all().delete() | ||
CorrectSubmission.objects.all().delete() | ||
IncorrectSubmission.objects.all().delete() | ||
|
||
if yesno("Delete teams?"): | ||
Team.objects.all().delete() | ||
|
||
if yesno("Delete users?", default=False): | ||
User.objects.all().delete() | ||
UserProfile.objects.all().delete() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters