mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-24 17:42:23 +00:00
Add a script to extract solutions, ordered in directories
This commit is contained in:
parent
6d01298e24
commit
1ef48fc3b4
45
apps/member/management/commands/extract_solutions.py
Normal file
45
apps/member/management/commands/extract_solutions.py
Normal file
@ -0,0 +1,45 @@
|
||||
import os
|
||||
from shutil import copyfile
|
||||
|
||||
from django.core.management import BaseCommand
|
||||
from django.utils import translation
|
||||
|
||||
from tournament.models import Tournament
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('dir',
|
||||
type=str,
|
||||
default='.',
|
||||
help="Directory where solutions should be saved.")
|
||||
parser.add_argument('--language', '-l',
|
||||
type=str,
|
||||
choices=['en', 'fr'],
|
||||
default='fr',
|
||||
help="Language of the title of the files.")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
"""
|
||||
Copy solutions elsewhere.
|
||||
"""
|
||||
d = options['dir']
|
||||
|
||||
translation.activate(options['language'])
|
||||
|
||||
copied = 0
|
||||
|
||||
for tournament in Tournament.objects.all():
|
||||
os.mkdir(d + '/' + tournament.name)
|
||||
for team in tournament.teams.filter(validation_status='2valid'):
|
||||
os.mkdir(d + '/' + tournament.name + '/' + str(team))
|
||||
for sol in tournament.solutions:
|
||||
if not os.path.isfile('media/' + sol.file.name):
|
||||
self.stdout.write(self.style.WARNING(("Warning: solution '{sol}' is not found. Maybe the file"
|
||||
"was deleted?").format(sol=str(sol))))
|
||||
continue
|
||||
copyfile('media/' + sol.file.name, d + '/' + tournament.name
|
||||
+ '/' + str(sol.team) + '/' + str(sol) + '.pdf')
|
||||
copied += 1
|
||||
|
||||
self.stdout.write(self.style.SUCCESS("Successfully copied {copied} solutions!".format(copied=copied)))
|
Loading…
Reference in New Issue
Block a user