Changeset 00079cf


Ignore:
Timestamp:
Feb 26, 2012, 3:55:58 AM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage
Children:
99747bd
Parents:
41f8b1e
git-author:
Alex Dehnert <adehnert@…> (02/26/12 03:55:58)
git-committer:
Alex Dehnert <adehnert@…> (02/26/12 03:55:58)
Message:

Stuff with group admins

  • Create a new group-admin role, which can manage a group's database entry (Trac: #78)
  • Script to import old signatories on a temporary basis, and only for groups that haven't really updated their group entry
Location:
asadb/groups
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/import_signatories.py

    r0653daa r00079cf  
    7474
    7575@transaction.commit_on_success
    76 def perform_sync(stats, dj_map, wh_map, ):
     76def perform_sync(stats, dj_map, wh_map, roles=None, dj_groups=None, ):
    7777    # Statistics
    7878    stats['loops'] = 0
     
    8383    stats['added'] = 0
    8484    stats['missing_rg'] = 0
     85    stats['missing_role'] = 0
    8586
    8687    today = datetime.date.today()
    87     roles = load_roles()
    88     dj_groups = load_groups()
     88    if roles is None:
     89        roles = load_roles()
     90    if dj_groups is None:
     91        dj_groups = load_groups()
    8992    for key in set(dj_map.keys()).union(wh_map.keys()):
    9093        stats['loops'] += 1
     
    130133                        stats['added'] += 1
    131134                    else:
    132                         print "Missing role or group: person=%s, role=%s, group=%d, start=%s, expiry=%s" % (
    133                             person, role_slug, group_id, start, expiry,
    134                         )
    135                         stats['missing_rg'] += 1
     135                        if role_slug not in roles:
     136                            stats['missing_role'] += 1
     137                        else:
     138                            print "Missing role or group: person=%s, role=%s, group=%d, start=%s, expiry=%s" % (
     139                                person, role_slug, group_id, start, expiry,
     140                            )
     141                            stats['missing_rg'] += 1
     142
    136143
    137144if __name__ == '__main__':
    138     stats = {}
     145    stats = {
     146        'group_ign': 0,
     147    }
     148
     149    mode = 'all'
     150    roles = None # default
     151    if len(sys.argv) > 1:
     152        if sys.argv[1] == 'squash':
     153            mode = 'squash'
     154        elif sys.argv[1] == 'all':
     155            pass
     156        else:
     157            raise NotImplementedError
     158    if mode == 'squash':
     159        roles = load_roles()
     160        repl = roles['temp-admin']
     161        for slug, role in roles.items():
     162            if slug in ('president', 'treasurer', 'financial', ):
     163                roles[slug] = repl
     164            else:
     165                del roles[slug]
    139166
    140167    print "Phase 1: %s: Loading Django officer information" % (datetime.datetime.now(), )
     
    142169    print "Phase 1: %s: Complete: Loading Django officer information" % (datetime.datetime.now(), )
    143170
    144     print "Phase 2: %s: Loading warehouse officer information" % (datetime.datetime.now(), )
     171    print "Phase 2: %s: Loading Django group information" % (datetime.datetime.now(), )
     172    dj_groups = load_groups()
     173    if mode == 'squash':
     174        for pk, group in dj_groups.items():
     175            if len(group.officers()) > 1:
     176                stats['group_ign'] += 1
     177                del dj_groups[pk]
     178            else:
     179                print "Keeping ", group
     180    print "Phase 2: %s: Complete: Loading Django group information" % (datetime.datetime.now(), )
     181
     182    print "Phase 3: %s: Loading warehouse officer information" % (datetime.datetime.now(), )
    145183    wh_map = load_warehouse(stats)
    146     print "Phase 2: %s: Complete: Loading warehouse officer information" % (datetime.datetime.now(), )
    147 
    148     print "Phase 3: %s: Performing sync" % (datetime.datetime.now(), )
    149     perform_sync(stats, dj_map, wh_map, )
    150     print "Phase 3: %s: Complete: Performing sync" % (datetime.datetime.now(), )
     184    print "Phase 3: %s: Complete: Loading warehouse officer information" % (datetime.datetime.now(), )
     185
     186    print "Phase 4: %s: Performing sync" % (datetime.datetime.now(), )
     187    perform_sync(stats, dj_map, wh_map, roles, dj_groups, )
     188    print "Phase 4: %s: Complete: Performing sync" % (datetime.datetime.now(), )
    151189
    152190    print """
     
    155193    Django current:         %(dj_total_current)6d
    156194    Django distinct:        %(dj_distinct_current)6d
     195    Django ignored groups:  %(group_ign)6d
    157196
    158197    Warehouse p/r/g tuples: %(wh_size)6d
     
    164203    People expired:         %(expired)6d
    165204    People missing from WH: %(missing_wh)6d
     205    People in missing group:%(missing_rg)6d
     206    People for missing role:%(missing_role)6d
    166207    People added:           %(added)6d
    167208    """ % stats
Note: See TracChangeset for help on using the changeset viewer.