Changeset b523fed for asadb/groups/views.py
- Timestamp:
- Feb 11, 2014, 2:56:32 AM (12 years ago)
- Branches:
- master, stable, stage
- Children:
- 8442dd7
- Parents:
- d4f571c
- git-author:
- Alex Dehnert <adehnert@…> (02/11/14 02:56:32)
- git-committer:
- Alex Dehnert <adehnert@…> (02/11/14 02:56:32)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asadb/groups/views.py
ref118cf rb523fed 1128 1128 ####################### 1129 1129 1130 name_formats = collections.OrderedDict() 1131 name_formats['username'] = ('username', False, '%(user)s') 1132 name_formats['email'] = ('username@mit.edu', False, '%(user)s@mit.edu') 1133 name_formats['name'] = ('First Last', True, '%(first)s %(last)s') 1134 name_formats['name-email'] = ('First Last <username@mit.edu>', True, '%(first)s %(last)s <%(user)s@mit.edu>') 1135 1130 1136 class ReportingForm(form_utils.forms.BetterForm): 1131 1137 special_filters = forms.fields.MultipleChoiceField( … … 1149 1155 required=False, 1150 1156 ) 1151 show_as_emails = forms.BooleanField( 1152 help_text='Append "@mit.edu" to each value of people fields to allow use as email addresses?', 1153 required=False, 1157 name_format = forms.ChoiceField( 1158 help_text='How to format the names of the President, Treasurer, etc., if displayed', 1159 choices=[(k, v[0]) for k,v in name_formats.items()], 1160 initial='username', 1161 required=True, 1154 1162 ) 1155 1163 … … 1182 1190 ('fields', { 1183 1191 'legend': 'Data to display', 1184 'fields': ['basic_fields', 'people_fields', ' show_as_emails', 'special_fields', ],1192 'fields': ['basic_fields', 'people_fields', 'name_format', 'special_fields', ], 1185 1193 }), 1186 1194 ('final', { … … 1276 1284 for field in people_fields: 1277 1285 col_labels.append(field.display_name) 1286 # Figure out the format, and if necessary fetch human names 1287 nf_slug = form.cleaned_data['name_format'] 1288 nf_label, nf_need_name, nf_fmt = name_formats[nf_slug] 1289 name_map = collections.defaultdict(lambda: ('???', '???')) 1290 if nf_need_name: 1291 people_usernames = people_data.values('person') 1292 name_data = groups.models.AthenaMoiraAccount.objects.filter(username__in=people_usernames) 1293 for account in name_data: 1294 name_map[account.username] = (account.first_name, account.last_name) 1278 1295 1279 1296 # Set up special fields … … 1288 1305 else: 1289 1306 formatters = {} 1290 show_as_emails = form.cleaned_data['show_as_emails']1291 1307 def fetch_item(group, field): 1292 1308 val = getattr(group, field) … … 1299 1315 for field in people_fields: 1300 1316 people = people_map[group.pk][field.pk] 1301 if show_as_emails: people = ["%s@mit.edu" % p for p in people] 1317 if nf_need_name: 1318 def fmt(p): 1319 first, last = name_map[p] 1320 ctx = {'user': p, 'first': first, 'last': last} 1321 return nf_fmt % ctx 1322 people = [fmt(p) for p in people] 1323 else: 1324 people = [nf_fmt % {'user': p} for p in people] 1302 1325 group_data.append(", ".join(people)) 1303 1326
Note: See TracChangeset
for help on using the changeset viewer.