[f57cf3c] | 1 | #!/usr/bin/python |
---|
| 2 | |
---|
| 3 | import csv |
---|
[c547de5] | 4 | import datetime |
---|
[f57cf3c] | 5 | import os |
---|
| 6 | import sys |
---|
| 7 | |
---|
| 8 | if __name__ == '__main__': |
---|
| 9 | cur_file = os.path.abspath(__file__) |
---|
| 10 | django_dir = os.path.abspath(os.path.join(os.path.dirname(cur_file), '..')) |
---|
| 11 | sys.path.append(django_dir) |
---|
| 12 | os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' |
---|
| 13 | |
---|
[a7d30ef] | 14 | from django.db import connection |
---|
[f57cf3c] | 15 | from django.db.models import Q |
---|
[e9af979] | 16 | from django.utils import html |
---|
[f57cf3c] | 17 | |
---|
| 18 | import groups.models |
---|
[a7d30ef] | 19 | import space.models |
---|
[f57cf3c] | 20 | |
---|
[a7d30ef] | 21 | def space_Q(merged_acl=None, building=None, ): |
---|
| 22 | Qspace = Q() |
---|
| 23 | if merged_acl is not None: Qspace = Q(space__merged_acl=merged_acl) |
---|
| 24 | if building: Qspace = Qspace & Q(space__number__startswith=building+'-') |
---|
| 25 | return Q(spaceassignment__in=space.models.SpaceAssignment.current.filter(Qspace)) |
---|
[f57cf3c] | 26 | |
---|
[b90b977] | 27 | Qsa = Q(group_status__slug__in=('active', 'suspended', )) |
---|
[a7d30ef] | 28 | |
---|
[f57cf3c] | 29 | functions = { |
---|
| 30 | 'finboard' : { |
---|
[b90b977] | 31 | 'format' : "%(name)s;%(officer_email)s", |
---|
| 32 | 'predicate' : Qsa & Q(group_funding__slug='undergrad', group_class__slug='mit-funded', ), |
---|
[f57cf3c] | 33 | }, |
---|
| 34 | 'nolist' : { |
---|
[b90b977] | 35 | 'format' : "%(name)s <%(officer_email)s>", |
---|
| 36 | 'predicate' : Qsa & Q(officer_email=""), |
---|
[f57cf3c] | 37 | }, |
---|
| 38 | 'asa-official' : { |
---|
| 39 | 'format' : '"%(name)s" <%(officer_email)s>', |
---|
| 40 | 'predicate' : Q(group_status__slug='active'), |
---|
| 41 | }, |
---|
| 42 | 'emails-only' : { |
---|
[b90b977] | 43 | 'format' : '%(officer_email)s', |
---|
| 44 | 'predicate' : Qsa, |
---|
[f57cf3c] | 45 | }, |
---|
[e9af979] | 46 | 'midway' : { |
---|
| 47 | 'prefix': """ |
---|
[c547de5] | 48 | <!-- |
---|
| 49 | Automatically generated by %(script)s %(mode)s on %(date)s. |
---|
| 50 | Do not edit; instead ask a DB maintainer (asa-db@) to re-run that script (or edit script as necessary). |
---|
| 51 | |
---|
| 52 | A more recent version may be in /mit/asa-db/data/db-dump/midway_groups.html. |
---|
| 53 | Includes active, suspended, applying, and NGE's (status) who aren't Dorm/FSILG (class). |
---|
| 54 | --> |
---|
[e9af979] | 55 | """, |
---|
| 56 | 'format' : '<option value="%(html_name)s">%(html_name)s</option>', |
---|
| 57 | 'predicate' : Q(group_status__slug__in=['active', 'suspended', 'applying', 'nge'], group_class__gets_publicity=True, ), |
---|
| 58 | }, |
---|
[a7d30ef] | 59 | 'w20-locker' : { |
---|
| 60 | 'format' : '%(officer_email)s;%(name)s', |
---|
| 61 | 'predicate' : Qsa & space_Q(merged_acl=True, building='W20'), |
---|
| 62 | }, |
---|
| 63 | 'w20-office' : { |
---|
| 64 | 'format' : '%(officer_email)s;%(name)s', |
---|
| 65 | 'predicate' : Qsa & space_Q(merged_acl=False, building='W20'), |
---|
| 66 | }, |
---|
| 67 | 'all-office' : { |
---|
| 68 | 'format' : '%(officer_email)s;%(name)s', |
---|
| 69 | 'predicate' : Qsa & space_Q(merged_acl=False), |
---|
| 70 | }, |
---|
| 71 | 'all-space' : { |
---|
| 72 | 'format' : '%(officer_email)s;%(name)s', |
---|
| 73 | 'predicate' : Qsa & space_Q(), |
---|
| 74 | }, |
---|
[f57cf3c] | 75 | } |
---|
| 76 | |
---|
| 77 | def do_output(mode): |
---|
[e9af979] | 78 | spec = functions[mode] |
---|
| 79 | format = spec['format'] |
---|
| 80 | predicate = spec['predicate'] |
---|
[a7d30ef] | 81 | gs = groups.models.Group.objects.filter(predicate).distinct() |
---|
[c547de5] | 82 | static_args = { |
---|
| 83 | 'script': 'groups/format_groups.py', |
---|
| 84 | 'mode':mode, |
---|
| 85 | 'date':datetime.datetime.now(), |
---|
| 86 | } |
---|
[e9af979] | 87 | if 'prefix' in spec: |
---|
| 88 | print spec['prefix'] % static_args |
---|
[f57cf3c] | 89 | for group in gs: |
---|
| 90 | print format % { |
---|
| 91 | 'name':group.name, |
---|
[e9af979] | 92 | 'html_name':html.escape(group.name), |
---|
[f57cf3c] | 93 | 'officer_email':group.officer_email, |
---|
| 94 | } |
---|
[e9af979] | 95 | if 'suffix' in spec: |
---|
| 96 | print spec['suffix'] % static_args |
---|
[a7d30ef] | 97 | #for q in connection.queries: print q |
---|
[f57cf3c] | 98 | |
---|
| 99 | if __name__ == "__main__": |
---|
| 100 | do_output(sys.argv[1]) |
---|