Changeset 356174b
- Timestamp:
- Apr 29, 2015, 9:16:12 PM (11 years ago)
- Branches:
- master, stable
- Children:
- 093448c
- Parents:
- 82e595e
- git-author:
- Alex Dehnert <adehnert@…> (04/29/15 21:16:12)
- git-committer:
- Alex Dehnert <adehnert@…> (04/29/15 21:16:12)
- File:
-
- 1 edited
-
asadb/groups/export_finboard_groups.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
asadb/groups/export_finboard_groups.py
r82e595e r356174b 24 24 25 25 if __name__ == '__main__': 26 groups = groups.models.Group.objects.filter(group_status__is_active=True) 27 groups = groups.filter(group_funding__slug='undergrad') 28 groups = groups.filter(officeholder__role__slug__in=ROLES) 29 groups.prefetch_related('officeholder_set', 'officeholder_set__officerrole') 30 groups = groups.distinct() 26 gs = groups.models.Group.objects.filter(group_status__is_active=True) 27 gs = gs.filter(group_funding__slug='undergrad') 31 28 32 group_dicts = [] 33 for group in groups: 34 # do the processing in python because of the prefetch_related 35 officers = list(group.officeholder_set.all()) 29 officers = groups.models.OfficeHolder.current_holders 30 officers = officers.filter(group__in=gs, role__slug__in=ROLES) 31 officers = officers.select_related('role__slug', 'group') 32 33 group_dicts = {} 34 for group in gs: 36 35 group_dict = { 37 36 'id': group.id, … … 40 39 } 41 40 for role in ROLES: 42 group_dict[role] = [officer.person for officer in officers 43 if officer.role.slug == role] 44 group_dicts.append(group_dict) 41 group_dict[role] = [] 42 group_dicts[group.id] = group_dict 43 44 for officer in officers: 45 group_dicts[officer.group.id][officer.role.slug].append(officer.person) 45 46 46 47 out = codecs.getwriter('utf-8')(sys.stdout) 47 48 json.dump({ 48 'groups': group_dicts ,49 'groups': group_dicts.values(), 49 50 'date': datetime.datetime.now().isoformat(), 50 }, out )51 }, out, indent=2)
Note: See TracChangeset
for help on using the changeset viewer.