source: asadb/util/export_website_groups.py

space-accessstablestage
Last change on this file 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: 1.3 KB
Line 
1#!/usr/bin/python
2#
3# Use as e.g.
4# ./export_website_groups.py > /mit/asa/resources/group-include.html
5
6import codecs
7import datetime
8import os
9import sys
10
11if __name__ == '__main__':
12    cur_file = os.path.abspath(__file__)
13    django_dir = os.path.abspath(os.path.join(os.path.dirname(cur_file), '..'))
14    sys.path.append(django_dir)
15    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
16
17from django.template import Template, Context
18import groups.models
19
20TMPL = Template(u"""
21<!--
22Automatically generated by asadb/util/export_website_groups.py on {{date}}.
23Do not edit; instead ask a DB maintainer (asa-db@) to re-run that script (or edit script as necessary).
24
25A more recent version may be in /mit/asa-db/data/db-dump/website_groups.html.
26Includes groups with status is_active=True (ie, Suspended and Active groups).
27-->
28{% for group in groups %}
29<tr><td>
30{% if group.website_url %}
31<a href="{{group.website_url}}">{{group.name}}</a>
32{% else %}
33{{group.name}}
34{% endif %}
35</td><td>{{group.description}}</td></tr>
36{% endfor %}
37""")
38
39if __name__ == '__main__':
40    ctx = Context({
41        'groups': groups.models.Group.objects.filter(group_status__is_active=True),
42        'date': datetime.datetime.now(),
43    })
44    out = codecs.getwriter('utf-8')(sys.stdout)
45    out.write(TMPL.render(ctx))
Note: See TracBrowser for help on using the repository browser.