source: asadb/groups/find_missing_transition.py @ 68c93e8

space-accessstablestage
Last change on this file since 68c93e8 was a451497, checked in by ASA Group Database <asa-db@…>, 13 years ago

Ease seeing which groups just lack basic info

  • Property mode set to 100755
File size: 3.0 KB
RevLine 
[1aaa525]1#!/usr/bin/python
2import csv
3import os
4import sys
5
6if __name__ == '__main__':
7    cur_file = os.path.abspath(__file__)
8    django_dir = os.path.abspath(os.path.join(os.path.dirname(cur_file), '..'))
9    sys.path.append(django_dir)
10    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
11
12from django.core import mail
13from django.template import Context, Template
14from django.template.loader import get_template
15
16import groups.models
17
18def get_roles():
[a451497]19    require_any_role = False
20    require_any_role = True
[1aaa525]21    roles = [
[a451497]22        ['president', require_any_role, 'No president listed', ],
23        ['treasurer', require_any_role, 'No treasurer listed', ],
[8cf11c9]24        ['financial', False, 'No financial signatories listed. At minimum, this should generally be your president and treasurer.', ],
25        ['reservation', False, 'No reservation signatories listed. Members reserving space for the group should be reservation signatories.', ],
[1aaa525]26    ]
27    for role in roles:
28        obj = groups.models.OfficerRole.objects.get(slug=role[0])
29        role[0] = obj
30    return roles
31
32def check_group(group, roles, ):
33    problems = []
[8cf11c9]34    fail = False
[1aaa525]35    if group.officer_email or group.description:
36        pass
37    else:
38        problems.append("No basic group information listed")
[8cf11c9]39        fail = True
40    for role, cause_fail, msg in roles:
[1aaa525]41        if len(group.officers(role=role)) == 0:
42            problems.append(msg)
[8cf11c9]43            if cause_fail: fail = True
44    return fail, problems
[1aaa525]45
[2a587e4]46def canonicalize_email(email):
47    if '@' in email: return email
48    elif email == '': return ''
49    else: return email + "@mit.edu"
50
[1aaa525]51def officers_lists(fd, ):
52    reader = csv.DictReader(fd)
53    lists = {}
54    for d in reader:
55        pk = int(d['ASA_STUDENT_GROUP_KEY'])
[2a587e4]56        lists[pk] = canonicalize_email(d['OFFICER_EMAIL'])
[1aaa525]57    return lists
58
59def check_groups(old_groups_data):
60    roles = get_roles()
61    officers = officers_lists(open(old_groups_data, 'r'))
62    tmpl = get_template('groups/letters/missing-transition.txt')
63    emails = []
64    for group in groups.models.Group.active_groups.all():
[8cf11c9]65        fail, problems = check_group(group, roles, )
66        if fail:
[0dc771d]67            try:
68                to = [officers[group.pk]]
69            except KeyError:
70                print "Group %s not found in CSV" % (group, )
[1aaa525]71            if group.officer_email:
72                to.append(group.officer_email)
73            ctx = Context({
74                'group': group,
75                'problems': problems,
76            })
77            body = tmpl.render(ctx)
78            email = mail.EmailMessage(
79                subject="[ASA] Missing information for %s" % (group.name, ),
80                body=body,
81                from_email='asa-exec@mit.edu',
82                to=to,
[2a587e4]83                bcc=['asa-db-outgoing@mit.edu'],
[1aaa525]84            )
85            emails.append(email)
86
87    connection = mail.get_connection()
[2a587e4]88    #connection.send_messages(emails)
[0dc771d]89    for email in emails:
90        print email.subject
91    print email.body
[2a587e4]92    print len(emails)
[1aaa525]93
94if __name__ == '__main__':
95    check_groups(sys.argv[1])
Note: See TracBrowser for help on using the repository browser.