| 1 | #!/usr/bin/python |
|---|
| 2 | |
|---|
| 3 | import csv |
|---|
| 4 | import os |
|---|
| 5 | import sys |
|---|
| 6 | |
|---|
| 7 | if __name__ == '__main__': |
|---|
| 8 | cur_file = os.path.abspath(__file__) |
|---|
| 9 | django_dir = os.path.abspath(os.path.join(os.path.dirname(cur_file), '..')) |
|---|
| 10 | sys.path.append(django_dir) |
|---|
| 11 | os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' |
|---|
| 12 | |
|---|
| 13 | from django.db.models import Q |
|---|
| 14 | from django.utils import html |
|---|
| 15 | |
|---|
| 16 | import groups.models |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | Qsa = Q(group_status__slug__in=('active', 'suspended', )) |
|---|
| 20 | functions = { |
|---|
| 21 | 'finboard' : { |
|---|
| 22 | 'format' : "%(name)s;%(officer_email)s", |
|---|
| 23 | 'predicate' : Qsa & Q(group_funding__slug='undergrad', group_class__slug='mit-funded', ), |
|---|
| 24 | }, |
|---|
| 25 | 'nolist' : { |
|---|
| 26 | 'format' : "%(name)s <%(officer_email)s>", |
|---|
| 27 | 'predicate' : Qsa & Q(officer_email=""), |
|---|
| 28 | }, |
|---|
| 29 | 'asa-official' : { |
|---|
| 30 | 'format' : '"%(name)s" <%(officer_email)s>', |
|---|
| 31 | 'predicate' : Q(group_status__slug='active'), |
|---|
| 32 | }, |
|---|
| 33 | 'emails-only' : { |
|---|
| 34 | 'format' : '%(officer_email)s', |
|---|
| 35 | 'predicate' : Qsa, |
|---|
| 36 | }, |
|---|
| 37 | 'midway' : { |
|---|
| 38 | 'prefix': """ |
|---|
| 39 | <!-- Automatically generated by %(script)s %(mode)s. |
|---|
| 40 | Do not edit; instead re-run that script (or edit it as necessary). --> |
|---|
| 41 | """, |
|---|
| 42 | 'format' : '<option value="%(html_name)s">%(html_name)s</option>', |
|---|
| 43 | 'predicate' : Q(group_status__slug__in=['active', 'suspended', 'applying', 'nge'], group_class__gets_publicity=True, ), |
|---|
| 44 | }, |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | def do_output(mode): |
|---|
| 48 | spec = functions[mode] |
|---|
| 49 | format = spec['format'] |
|---|
| 50 | predicate = spec['predicate'] |
|---|
| 51 | gs = groups.models.Group.objects.filter(predicate) |
|---|
| 52 | static_args = {'script': 'groups/format_groups.py', 'mode':mode, } |
|---|
| 53 | if 'prefix' in spec: |
|---|
| 54 | print spec['prefix'] % static_args |
|---|
| 55 | for group in gs: |
|---|
| 56 | print format % { |
|---|
| 57 | 'name':group.name, |
|---|
| 58 | 'html_name':html.escape(group.name), |
|---|
| 59 | 'officer_email':group.officer_email, |
|---|
| 60 | } |
|---|
| 61 | if 'suffix' in spec: |
|---|
| 62 | print spec['suffix'] % static_args |
|---|
| 63 | |
|---|
| 64 | if __name__ == "__main__": |
|---|
| 65 | do_output(sys.argv[1]) |
|---|