Changeset a7d30ef


Ignore:
Timestamp:
Apr 10, 2012, 4:00:41 PM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage
Children:
1898cc8
Parents:
04a46ed
git-author:
Alex Dehnert <adehnert@…> (04/10/12 16:00:41)
git-committer:
Alex Dehnert <adehnert@…> (04/10/12 16:00:41)
Message:

Script to dump groups with space (ASA Trac #95)

Add support to groups/format_groups.py to dump email addresses of groups with
various kinds of assigned space (W20 office, W20 locker, etc.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/format_groups.py

    r31da85f ra7d30ef  
    1111    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
    1212
     13from django.db import connection
    1314from django.db.models import Q
    1415from django.utils import html
    1516
    1617import groups.models
     18import space.models
    1719
     20def space_Q(merged_acl=None, building=None, ):
     21    Qspace = Q()
     22    if merged_acl is not None: Qspace = Q(space__merged_acl=merged_acl)
     23    if building: Qspace = Qspace & Q(space__number__startswith=building+'-')
     24    return Q(spaceassignment__in=space.models.SpaceAssignment.current.filter(Qspace))
    1825
    1926Qsa = Q(group_status__slug__in=('active', 'suspended', ))
     27
    2028functions = {
    2129    'finboard' : {
     
    4351        'predicate' : Q(group_status__slug__in=['active', 'suspended', 'applying', 'nge'], group_class__gets_publicity=True, ),
    4452    },
     53    'w20-locker' : {
     54        'format' : '%(officer_email)s;%(name)s',
     55        'predicate' : Qsa & space_Q(merged_acl=True, building='W20'),
     56    },
     57    'w20-office' : {
     58        'format' : '%(officer_email)s;%(name)s',
     59        'predicate' : Qsa & space_Q(merged_acl=False, building='W20'),
     60    },
     61    'all-office' : {
     62        'format' : '%(officer_email)s;%(name)s',
     63        'predicate' : Qsa & space_Q(merged_acl=False),
     64    },
     65    'all-space' : {
     66        'format' : '%(officer_email)s;%(name)s',
     67        'predicate' : Qsa & space_Q(),
     68    },
    4569}
    4670
     
    4973    format = spec['format']
    5074    predicate = spec['predicate']
    51     gs = groups.models.Group.objects.filter(predicate)
     75    gs = groups.models.Group.objects.filter(predicate).distinct()
    5276    static_args = {'script': 'groups/format_groups.py', 'mode':mode, }
    5377    if 'prefix' in spec:
     
    6185    if 'suffix' in spec:
    6286        print spec['suffix'] % static_args
     87    #for q in connection.queries: print q
    6388
    6489if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.