author | nishanth |
Fri, 03 Sep 2010 15:59:06 +0530 | |
branch | anoop |
changeset 235 | 7583311884e1 |
parent 219 | 3d3e4e4afb61 |
permissions | -rw-r--r-- |
217
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1 |
# Note: Most of the code below is hard coded with values. Please change it |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2 |
# required. Reprensented as (HC) for Hard Coded values. |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
3 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
4 |
from sage_days.sdi.events import send_acco_confirm_mail |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
5 |
from sage_days.sdi.events import send_acco_reject_mail |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
6 |
from sage_days.sdi.models import ParticipantInfo, RegistrantInfo |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
8 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
9 |
def allot(): |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
10 |
"""Performs the allotment of accomodation based on availability for the |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
11 |
participants who have requested accommodation. |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
12 |
""" |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
14 |
# (HC) |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
15 |
# Availability for number of people at various locations. Here in the |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
# Order of IITB Hostel, IITB Guest house and then NITIE |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
17 |
availability = [30, 20, 20] |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
18 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
19 |
# (HC) |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
20 |
acco_info = ParticipantInfo.objects.filter( |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
21 |
participant__acco_required=True) |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
acco_given = acco_info[:65] |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
23 |
acco_rejected = acco_info[65:] |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
24 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
25 |
for participant in acco_given: |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
26 |
if availability[0] <= 0: |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
27 |
break |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
28 |
if participant.will_sprint == '3' or participant.will_sprint == '2': |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
29 |
if participant.participant.profession.lower() == 'student': |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
30 |
reg_info = participant.participant.registrantinfo_set.get() |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
31 |
reg_info.status_of_accomodation = '2' |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
32 |
reg_info.acco_location = '0' |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
33 |
availability[0] -= 1 |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
34 |
reg_info.save() |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
35 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
36 |
for participant in acco_given: |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
37 |
if availability[1] <= 0: |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
38 |
break |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
39 |
if participant.participant.gender == 'F': |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
40 |
reg_info = participant.participant.registrantinfo_set.get() |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
41 |
reg_info.status_of_accomodation = '2' |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
42 |
reg_info.acco_location = '1' |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
43 |
availability[1] -= 1 |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
44 |
reg_info.save() |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
45 |
if participant.participant.gender == 'M': |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
46 |
if (participant.will_sprint == '3' or |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
47 |
participant.will_sprint == '2'): |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
48 |
if participant.participant.profession.lower() != 'student': |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
49 |
reg_info = participant.participant.registrantinfo_set.get() |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
50 |
reg_info.status_of_accomodation = '2' |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
51 |
reg_info.acco_location = '1' |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
52 |
availability[1] -= 1 |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
53 |
reg_info.save() |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
54 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
55 |
for participant in acco_given: |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
56 |
if availability[2] <= 0: |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
57 |
break |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
58 |
if (participant.will_sprint == '1' |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
59 |
and participant.participant.gender == 'M'): |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
60 |
reg_info = participant.participant.registrantinfo_set.get() |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
61 |
reg_info.status_of_accomodation = '2' |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
62 |
reg_info.acco_location = '2' |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
63 |
availability[2] -= 1 |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
64 |
reg_info.save() |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
65 |
|
219
3d3e4e4afb61
Fixed a blatant bug with the looping element in the send mail script for accommodation allotment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
217
diff
changeset
|
66 |
for participant in acco_rejected: |
217
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
67 |
reg_info = participant.participant.registrantinfo_set.get() |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
68 |
reg_info.status_of_accomodation = '3' |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
69 |
reg_info.save() |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
70 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
71 |
def send_mails(): |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
72 |
"""Sends mails to all those who have been alloted accommodation. |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
73 |
""" |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
74 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
75 |
hostel_participants = RegistrantInfo.objects.filter( |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
76 |
status_of_accomodation=2, acco_location=0) |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
77 |
ghouse_partiticpants = RegistrantInfo.objects.filter( |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
78 |
status_of_accomodation=2, acco_location=1) |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
79 |
nitie_participants = RegistrantInfo.objects.filter( |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
80 |
status_of_accomodation=2, acco_location=2) |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
81 |
acco_rejected = RegistrantInfo.objects.filter( |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
82 |
status_of_accomodation=3) |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
83 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
84 |
for p in hostel_participants: |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
85 |
send_acco_confirm_mail(p.registrant, 'IIT Bombay Hostel', |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
86 |
'150', True) |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
87 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
88 |
for p in ghouse_partiticpants: |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
89 |
send_acco_confirm_mail(p.registrant, 'IIT Bombay Guest House', '300') |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
90 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
91 |
for p in nitie_participants: |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
92 |
send_acco_confirm_mail(p.registrant, 'NITIE House', '500') |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
93 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
94 |
for p in acco_rejected: |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
95 |
send_acco_reject_mail(p.registrant) |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
96 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
97 |
|
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
98 |
#65 |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
99 |
#Participants attending sprints: 21 |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
100 |
#Female participants attending sprints: 2 |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
101 |
#Male participants attending sprints: 19 |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
102 |
#Female participants may be attending sprints: 4 |
69f9624b0129
Script to allot accommodation and send mails have been added.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
103 |
#Male participants may beattending sprints: 21 |