-
Notifications
You must be signed in to change notification settings - Fork 0
/
tournament_creator.py
executable file
·86 lines (74 loc) · 4.17 KB
/
tournament_creator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#############################################################################
# #
# FLEQ (Free LibreSoft Educational Quizbowl) #
# A synchronous on-line competition software to improve and #
# motivate learning. #
# #
# Copyright (C) 2012 Arturo Moral, Gregorio Robles & Felix Redondo #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as #
# published by the Free Software Foundation, either version 3 of the #
# License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Affero General Public License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
# Contact authors : Arturo Moral <amoral@gmail.com> #
# Gregorio Robles <grex@gsyc.urjc.es> #
# Felix Redondo <felix.redondo.sierra@gmail.com> #
# #
#############################################################################
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# El script se lanza a las 00:01 #
# #
# #### #### #
# #
# @@@@@@@@@@ #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
from django.core.management import setup_environ
import settings
setup_environ(settings)
from quizbowl.models import Round, Score, Tournament
from quizbowl.views_notify import notify_user
import datetime
import sys
###
#from django.core.mail import send_mail
#import os
#os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
#send_mail("Tournament creator", "Creando nuevos torneos", 'fleq.libresoft@gmail.com', ['j.gonzalezna@gmail.com'])
###
t = Tournament.objects.filter(start_date = datetime.date.today())
for tournament in t:
if tournament.players.all().count() < 2:
# tournaments with one or no users are deleted before starting
#notify_user(tournament.admin, 'tournament_canceled', tournament)
if tournament.players.all().count() > 0:
p = tournament.players.all()
#for player in p:
#notify_user(player, 'tournament_canceled', tournament)
tournament.delete()
else:
p = tournament.players.all()
#for player in p:
#notify_user(player, 'new_tournament', tournament)
i = 1
actual_date = tournament.start_date
while True:
if i <= tournament.rounds:
round = Round(round_number = i, start_date = actual_date, finish_date = actual_date + datetime.timedelta(tournament.days_per_round-1), tournament = tournament)
round.save()
actual_date += datetime.timedelta(tournament.days_per_round)
i += 1
else:
break