import os
+import datetime
from optparse import make_option
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
- help = "Delete all exam scripts for a given period"
- args = "period_name"
+ help = "Delete all exam scripts older than a given year"
+ args = "year"
admin_email = 'webmaster@parisson.com'
def add_arguments(self, parser):
parser.add_argument('args', nargs='*')
def handle(self, *args, **options):
- period_name = args[0]
- period = Period.objects.get(name=period_name)
- scripts = Script.objects.filter(period=period)
+ year = int(args[0])
+ date = datetime.datetime(day=31, month=12, year=year)
+ scripts = Script.objects.filter(date_added__lte=date)
for script in scripts:
os.remove(script.file.path)
script.delete()