source: asadb/groups/format_groups.py @ c547de5

space-accessstablestage
Last change on this file since c547de5 was c547de5, checked in by Alex Dehnert <adehnert@…>, 13 years ago

Improve the header of the exported HTML files

Files in question are /mit/asa-db/data/db-dump/{midway,website}_groups.html, as
generated by groups/format_groups.py midway and util/export_website_groups.py.

Added information:

  • Paths to /mit/asa-db/data/db-dump/*.html generated files (ASA-#134)
  • Timestamp of generation (ASA-#135)
  • Who can re-run the scripts (ASA-#136)
  • Which groups are included
  • Property mode set to 100755
File size: 3.2 KB
Line 
1#!/usr/bin/python
2
3import csv
4import datetime
5import os
6import sys
7
8if __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
14from django.db import connection
15from django.db.models import Q
16from django.utils import html
17
18import groups.models
19import space.models
20
21def 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))
26
27Qsa = Q(group_status__slug__in=('active', 'suspended', ))
28
29functions = {
30    'finboard' : {
31        'format' : "%(name)s;%(officer_email)s",
32        'predicate' : Qsa & Q(group_funding__slug='undergrad', group_class__slug='mit-funded', ),
33    },
34    'nolist' : {
35        'format' : "%(name)s <%(officer_email)s>",
36        'predicate' : Qsa & Q(officer_email=""),
37    },
38    'asa-official' : {
39        'format' : '"%(name)s" <%(officer_email)s>',
40        'predicate' : Q(group_status__slug='active'),
41    },
42    'emails-only' : {
43        'format' : '%(officer_email)s',
44        'predicate' : Qsa,
45    },
46    'midway' : {
47        'prefix': """
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        -->
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    },
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    },
75}
76
77def do_output(mode):
78    spec = functions[mode]
79    format = spec['format']
80    predicate = spec['predicate']
81    gs = groups.models.Group.objects.filter(predicate).distinct()
82    static_args = {
83        'script': 'groups/format_groups.py',
84        'mode':mode,
85        'date':datetime.datetime.now(),
86    }
87    if 'prefix' in spec:
88        print spec['prefix'] % static_args
89    for group in gs:
90        print format % {
91            'name':group.name,
92            'html_name':html.escape(group.name),
93            'officer_email':group.officer_email,
94        }
95    if 'suffix' in spec:
96        print spec['suffix'] % static_args
97    #for q in connection.queries: print q
98
99if __name__ == "__main__":
100    do_output(sys.argv[1])
Note: See TracBrowser for help on using the repository browser.