Changeset 3cb9b1e


Ignore:
Timestamp:
Feb 8, 2013, 5:09:01 AM (13 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage
Children:
8d3b651
Parents:
afc5348
git-author:
Alex Dehnert <adehnert@…> (02/08/13 05:09:01)
git-committer:
Alex Dehnert <adehnert@…> (02/08/13 05:09:01)
Message:

Add group listing <option> tags to reporting page

Non-DB-maintainers can use this to generate customized HTML forms without
futzing around with HTML escaping, spreadsheet CONCATENATE functions, etc..
This fixes ASA-#173.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/views.py

    r8124413 r3cb9b1e  
    10971097    )
    10981098
     1099    special_fields_choices = (
     1100        ('option_entry', '<option> entry', ),
     1101    )
     1102    special_fields = forms.fields.MultipleChoiceField(
     1103        choices=special_fields_choices,
     1104        widget=forms.CheckboxSelectMultiple,
     1105        required=False,
     1106    )
     1107
    10991108    _format_choices = [
    11001109        ('html/inline',     "Web (HTML)", ),
     
    11121121            ('fields', {
    11131122                'legend': 'Data to display',
    1114                 'fields': ['basic_fields', 'people_fields', 'show_as_emails', ],
     1123                'fields': ['basic_fields', 'people_fields', 'show_as_emails', 'special_fields', ],
    11151124            }),
    11161125            ('final', {
     
    11521161        escaped = html.escape(email)
    11531162        return mark_safe("<a href='mailto:%s'>%s</a>" % (escaped, escaped))
     1163
     1164def format_option_entry(group):
     1165    name = html.escape(group.name)
     1166    return '<option value="%s">%s</option>' % (name, name, )
    11541167
    11551168reporting_html_formatters = {
     
    11931206            col_labels.append(field.display_name)
    11941207
     1208        # Set up special fields
     1209        special_formatters = []
     1210        if 'option_entry' in form.cleaned_data['special_fields']:
     1211            col_labels.append('option_entry')
     1212            special_formatters.append(format_option_entry)
     1213
    11951214        # Assemble data
    11961215        if output_format == 'html':
     
    12041223                val = formatters[field](val)
    12051224            return val
     1225
    12061226        for group in qs:
    12071227            group_data = [fetch_item(group, field) for field in basic_fields]
     
    12101230                if show_as_emails: people = ["%s@mit.edu" % p for p in people]
    12111231                group_data.append(", ".join(people))
     1232
     1233            for formatter in special_formatters:
     1234                group_data.append(formatter(group))
    12121235
    12131236            report_groups.append(group_data)
Note: See TracChangeset for help on using the changeset viewer.