source: asadb/groups/format_groups.py @ 31da85f

space-accessstablestage
Last change on this file since 31da85f was 31da85f, checked in by ASA Group Database <asa-db@…>, 14 years ago

Don't output select tag in format_groups.py midway

  • Property mode set to 100755
File size: 1.9 KB
Line 
1#!/usr/bin/python
2
3import csv
4import os
5import sys
6
7if __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
13from django.db.models import Q
14from django.utils import html
15
16import groups.models
17
18
19Qsa = Q(group_status__slug__in=('active', 'suspended', ))
20functions = {
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
47def 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
64if __name__ == "__main__":
65    do_output(sys.argv[1])
Note: See TracBrowser for help on using the repository browser.