space-accessstablestage
Last change
on this file since 7e8ea71 was
884ab7c,
checked in by ASA Group Database <asa-db@…>, 13 years ago
|
Handle unicode when exporting groups for website
|
-
Property mode set to
100755
|
File size:
1.0 KB
|
Rev | Line | |
---|
[d9137a7] | 1 | #!/usr/bin/python |
---|
| 2 | # |
---|
| 3 | # Use as e.g. |
---|
| 4 | # ./export_website_groups.py > /mit/asa/resources/group-include.html |
---|
| 5 | |
---|
[884ab7c] | 6 | import codecs |
---|
[d9137a7] | 7 | import os |
---|
| 8 | import sys |
---|
| 9 | |
---|
| 10 | if __name__ == '__main__': |
---|
| 11 | cur_file = os.path.abspath(__file__) |
---|
| 12 | django_dir = os.path.abspath(os.path.join(os.path.dirname(cur_file), '..')) |
---|
| 13 | sys.path.append(django_dir) |
---|
| 14 | os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' |
---|
| 15 | |
---|
| 16 | from django.template import Template, Context |
---|
| 17 | import groups.models |
---|
| 18 | |
---|
[884ab7c] | 19 | TMPL = Template(u""" |
---|
[d9137a7] | 20 | <!-- Automatically generated by asadb/util/export_website_groups.py. |
---|
| 21 | Do not edit; instead re-run that script (or edit it as necessary). --> |
---|
| 22 | {% for group in groups %} |
---|
| 23 | <tr><td> |
---|
| 24 | {% if group.website_url %} |
---|
| 25 | <a href="{{group.website_url}}">{{group.name}}</a> |
---|
| 26 | {% else %} |
---|
| 27 | {{group.name}} |
---|
| 28 | {% endif %} |
---|
| 29 | </td><td>{{group.description}}</td></tr> |
---|
| 30 | {% endfor %} |
---|
| 31 | """) |
---|
| 32 | |
---|
| 33 | if __name__ == '__main__': |
---|
| 34 | ctx = Context( |
---|
| 35 | {'groups': groups.models.Group.objects.filter(group_status__is_active=True)} |
---|
| 36 | ) |
---|
[884ab7c] | 37 | out = codecs.getwriter('utf8')(sys.stdout) |
---|
| 38 | out.write(TMPL.render(ctx)) |
---|
Note: See
TracBrowser
for help on using the repository browser.