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
RevLine 
[f57cf3c]1#!/usr/bin/python
2
3import csv
[c547de5]4import datetime
[f57cf3c]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
[a7d30ef]14from django.db import connection
[f57cf3c]15from django.db.models import Q
[e9af979]16from django.utils import html
[f57cf3c]17
18import groups.models
[a7d30ef]19import space.models
[f57cf3c]20
[a7d30ef]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))
[f57cf3c]26
[b90b977]27Qsa = Q(group_status__slug__in=('active', 'suspended', ))
[a7d30ef]28
[f57cf3c]29functions = {
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
77def 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
99if __name__ == "__main__":
100    do_output(sys.argv[1])
Note: See TracBrowser for help on using the repository browser.