1
0
Fork 0
mirror of https://github.com/Findus23/acronomy.git synced 2024-09-19 15:33:45 +02:00

optionally set todays acronyms of the day

This commit is contained in:
Lukas Winkler 2020-07-18 19:15:54 +02:00
parent 47cf64d2cd
commit 708f87a270
Signed by: lukas
GPG key ID: 54DE4D798D244853

View file

@ -8,12 +8,22 @@ from acros.models import Acronym, AcroOfTheDay
class Command(BaseCommand):
help = 'Selects Acronym of the Day for the next day'
def add_arguments(self, parser):
# Named (optional) arguments
parser.add_argument(
'--today',
action='store_true',
help='replace todays acronyms of the day instead of tomorrows',
)
def handle(self, *args, **options):
today = date.today()
tomorrow = today + timedelta(days=1)
AcroOfTheDay.objects.filter(date__gt=today).delete()
if options["today"]:
AcroOfTheDay.objects.filter(date=today).delete()
AcroOfTheDay.objects.filter(date__lt=today).delete()
selected = Acronym.objects.order_by('?')[:5]
for i, acr in enumerate(selected):
AcroOfTheDay.objects.create(acronym=acr, date=tomorrow,order=i)
AcroOfTheDay.objects.create(acronym=acr, date=today if options["today"] else tomorrow, order=i)
print(acr.name)