-
Notifications
You must be signed in to change notification settings - Fork 1
/
BirthdaysAndAnniversaries.py
106 lines (78 loc) · 3.08 KB
/
BirthdaysAndAnniversaries.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# roles=Global
# change the above role name to limit who can run this report
emailRecipientQuery = "UserRole = 57" # Query for who receives the emailed report
emailFromAddress = "go@tenth.org" # the "reply-to" address of the emailed report
emailFromPeopleId = 22029 # the people ID to associate with the sending emailed report
model.Title = "Global Partner Birthdays and Anniversaries" # used as email subject
secEv = "Security Level" # Name of an extra value that indicates partner security
# Determine the range for a birthday or anniversary. Include those are are:
rangeMin = 30 # at least this many days in the future
rangeMax = 70 # but less than this many days in the future
# That's all the configuration needed.
# ##################################################################################################################
global Data, q
# Birthdays
out = "<h2>Upcoming Birthdays</h2>"
out += "<p>Between {} and {} days in the future</p>".format(rangeMin, rangeMax)
out += "<table><tr><th>Partner</th><th>Birthday</th><th>{}</th></tr>".format(secEv)
has = False
for p in q.QueryList('''
(
DaysTillBirthday > {}
AND DaysTillBirthday < {}
)
AND FamilyExtraInt( Name='{}' ) > 0
'''.format(rangeMin, rangeMax, secEv)):
name = p.Name
if p.Age < 20:
name += " (" + str(p.Age + 1) + ")"
elif p.PeopleId not in [p.Family.HeadOfHouseholdId, p.Family.HeadOfHouseholdSpouseId]:
name += " (adult child)"
has = True
out += """
<tr>
<td><a href=\"{}/Person2/{}\">{}</a></td>
<td>{}</td>
<td>{}</td>
</tr>""".format(model.CmsHost, p.PeopleId, name, p.BirthDate.ToString("MMMM d"), p.Family.GetExtra(secEv))
if not has:
out += "<td colspan=2>None this period</td>"
out += "</table>"
# Anniversaries
out += "<h2>Upcoming Anniversaries</h2>"
out += "<p>Between {} and {} days in the future</p>".format(rangeMin, rangeMax)
out += "<table><tr><th>Partners</th><th>Anniversary</th><th>{}</th></tr>".format(secEv)
listedFids = []
has = False
for p in q.QueryList('''
(
DaysTillAnniversary > {}
AND DaysTillAnniversary < {}
)
AND FamilyExtraInt( Name='{}' ) > 0
'''.format(rangeMin, rangeMax, secEv)):
has = True
if p.FamilyId in listedFids:
continue
listedFids.append(p.FamilyId)
out += """
<tr>
<td><a href=\"{0}/Person2/{1}\">{2}</a> & <a href=\"{0}/Person2/{3}\">{4}</a></td>
<td>{5}</td>
<td>{6}</td>
</tr>""".format(
model.CmsHost,
p.Family.HeadOfHousehold.PeopleId, p.Family.HeadOfHousehold.Name,
p.Family.HeadOfHouseholdSpouse.PeopleId, p.Family.HeadOfHouseholdSpouse.Name,
p.WeddingDate.ToString("MMMM d, yyyy"),
p.Family.GetExtra(secEv)
)
if not has:
out += "<td colspan=2>None this period</td>"
out += "</table>"
if model.FromMorningBatch or Data.email != '':
model.Transactional = True
model.Email(emailRecipientQuery, emailFromPeopleId, emailFromAddress,
"Global Outreach Automation", model.Title, out)
else:
print out