Ignore:
Timestamp:
Jan 30, 2013, 3:05:48 AM (13 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage
Children:
8aea837
Parents:
492251a
git-author:
Alex Dehnert <adehnert@…> (01/30/13 03:02:57)
git-committer:
Alex Dehnert <adehnert@…> (01/30/13 03:05:48)
Message:

Update the space emails with non-DB-managed info

  • Remove from CAC's email changes to spaces that aren't handled through the DB (We still include the group summary header, which is not ideal. :/ )
  • Don't send CAC's email if no relevant changes have occurred
  • Add a warning to the per-group emails when they change a non-DB-managed space's access.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/space/diffs.py

    r492251a r59506d6  
    88    cur_file = os.path.abspath(__file__)
    99    django_dir = os.path.abspath(os.path.join(os.path.dirname(cur_file), '..'))
     10    django_dir_parent = os.path.abspath(os.path.join(os.path.dirname(cur_file), '../..'))
    1011    sys.path.append(django_dir)
     12    sys.path.append(django_dir_parent)
    1113    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
    1214
    1315from django.core.mail import EmailMessage
     16from django.core.urlresolvers import reverse
    1417from django.db import connection
    1518from django.db.models import Q
     
    100103
    101104    def list_office_changes(self, ):
    102         cac_lines = []
     105        systems_lines = {
     106            'cac-card': [],
     107            'none': [],
     108        }
    103109        group_lines = []
    104         def append_change(mit_id, verb, name):
    105             cac_lines.append("%s:\t%s:\t%s" % (mit_id, verb, name))
    106             group_lines.append("%s:\t%s" % (verb, name))
    107110        for space_pk, space_data in self.offices.items():
     111            lock_type = all_spaces[space_pk].lock_type
     112            system_lines = systems_lines[lock_type.db_update]
     113            def append_change(mit_id, verb, name):
     114                system_lines.append("%s:\t%s:\t%s" % (mit_id, verb, name))
     115                group_lines.append("%s:\t%s" % (verb, name))
     116
    108117            line = "Changes in %s:" % (all_spaces[space_pk].number, )
    109             cac_lines.append(line)
     118            system_lines.append(line)
    110119            group_lines.append(line)
     120
     121            if lock_type.db_update == 'none':
     122                tmpl =  'Warning: You submitted changes effecting this space, but this space is ' + \
     123                        'a "%s" space, and is not managed through the ASA DB. See ' + \
     124                        'https://asa.mit.edu/%s for details on how to update spaces of this type.'
     125                line = tmpl % (lock_type.name, reverse('space-lock-type'), )
     126                group_lines.append(line)
     127
    111128            for mit_id, (old_names, new_names) in space_data.items():
    112129                if mit_id is None: mit_id = "ID unknown"
     
    125142                        else:
    126143                            append_change(mit_id, "Add", name)
    127             cac_lines.append("")
     144            system_lines.append("")
    128145            group_lines.append("")
    129146
    130         cac_msg = "\n".join(cac_lines)
     147        systems_msg = dict([
     148            (system, '\n'.join(lines), ) for (system, lines) in systems_lines.items()
     149        ])
    131150        group_msg = "\n".join(group_lines)
    132         return cac_msg, group_msg
     151        return systems_msg, group_msg
    133152
    134153    def add_locker_signatories(self, space_access, time):
     
    281300    cac_locker_msgs = []
    282301
    283     process_spaces =  space.models.Space.objects.all()
     302    process_spaces =  space.models.Space.objects.all().select_related('lock_type')
    284303    for the_space in process_spaces:
    285304        new_cac_msgs = space_specific_access(the_space, group_data, old_time, new_time)
     
    288307
    289308    changed_groups = []
     309    cac_chars = 0
    290310    for group_pk, group_info in group_data.items():
    291311        group_info.add_office_signatories(old_time, new_time)
    292         cac_changes, group_office_changes = group_info.list_office_changes()
     312        systems_changes, group_office_changes = group_info.list_office_changes()
    293313        if group_info.changes:
    294             changed_groups.append((group_info.group, cac_changes, group_office_changes, group_info.locker_messages, ))
     314            cac_chars += len(systems_changes['cac-card'])
     315            changed_groups.append((group_info.group, systems_changes['cac-card'], group_office_changes, group_info.locker_messages, ))
    295316
    296317    asa_rcpts = ['asa-space@mit.edu', 'asa-db@mit.edu', ]
    297     if changed_groups:
     318    if cac_chars > 0 or cac_locker_msgs:
    298319        util.emails.email_from_template(
    299320            tmpl='space/cac-change-email.txt',
Note: See TracChangeset for help on using the changeset viewer.