Changeset ecf87c8 for asadb/space/diffs.py
- Timestamp:
- Jun 5, 2013, 5:53:11 AM (13 years ago)
- Branches:
- master, stable, stage
- Children:
- 17c118f
- Parents:
- 242566d (diff), 72a3d90 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Alex Dehnert <adehnert@…> (06/05/13 05:53:05)
- git-committer:
- Alex Dehnert <adehnert@…> (06/05/13 05:53:11)
- File:
-
- 1 edited
-
asadb/space/diffs.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
asadb/space/diffs.py
rc8f4eea r27e09a9 8 8 cur_file = os.path.abspath(__file__) 9 9 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), '../..')) 10 11 sys.path.append(django_dir) 12 sys.path.append(django_dir_parent) 11 13 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 12 14 13 15 from django.core.mail import EmailMessage 16 from django.core.urlresolvers import reverse 14 17 from django.db import connection 15 18 from django.db.models import Q … … 100 103 101 104 def list_office_changes(self, ): 102 cac_lines = [] 105 systems_lines = { 106 'cac-card': [], 107 'none': [], 108 } 103 109 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))107 110 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 108 117 line = "Changes in %s:" % (all_spaces[space_pk].number, ) 109 cac_lines.append(line)118 system_lines.append(line) 110 119 group_lines.append(line) 120 121 if lock_type.db_update == 'none': 122 tmpl = 'Warning: You submitted changes affecting 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 111 128 for mit_id, (old_names, new_names) in space_data.items(): 112 129 if mit_id is None: mit_id = "ID unknown" … … 125 142 else: 126 143 append_change(mit_id, "Add", name) 127 cac_lines.append("")144 system_lines.append("") 128 145 group_lines.append("") 129 146 130 cac_msg = "\n".join(cac_lines) 147 systems_msg = dict([ 148 (system, '\n'.join(lines), ) for (system, lines) in systems_lines.items() 149 ]) 131 150 group_msg = "\n".join(group_lines) 132 return cac_msg, group_msg151 return systems_msg, group_msg 133 152 134 153 def add_locker_signatories(self, space_access, time): … … 177 196 178 197 def safe_add_change_real(change_by_name, change): 198 """Add a new change to our dict of pending changes. 199 200 If a different change has already been added for this person (eg, "Remove" 201 instead of "Keep", or with a different list of groups), error. This should 202 always succeed; if it doesn't, the code is buggy. We worry about this 203 because we want to be really sure that the email that goes to just CAC is 204 compatible with the emails that go to each groups. Since we iterate over 205 the changes once per group, we want to be sure that for each group 206 iteration we're building compatible information. 207 """ 208 179 209 name = change.name 180 210 if name in change_by_name: … … 200 230 print "ID=%s (%s):\n\t%s\t(%s)\n\t%s\t(%s)\n" % (mit_id, unchanged, old_by_names, old_by_group, new_by_names, new_by_group, ), 201 231 for group_pk in joint_keys(old_by_group, new_by_group): 232 # TODO: Do we need to do an iteration for each group? This seems 233 # slightly questionable. Can we just loop over all known names? 234 202 235 old_names = old_by_group[group_pk] 203 236 new_names = new_by_group[group_pk] … … 267 300 cac_locker_msgs = [] 268 301 269 process_spaces = space.models.Space.objects.all() 302 process_spaces = space.models.Space.objects.all().select_related('lock_type') 270 303 for the_space in process_spaces: 271 304 new_cac_msgs = space_specific_access(the_space, group_data, old_time, new_time) … … 274 307 275 308 changed_groups = [] 309 cac_chars = 0 276 310 for group_pk, group_info in group_data.items(): 277 311 group_info.add_office_signatories(old_time, new_time) 278 cac_changes, group_office_changes = group_info.list_office_changes()312 systems_changes, group_office_changes = group_info.list_office_changes() 279 313 if group_info.changes: 280 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, )) 281 316 282 317 asa_rcpts = ['asa-space@mit.edu', 'asa-db@mit.edu', ] 283 if c hanged_groups:318 if cac_chars > 0 or cac_locker_msgs: 284 319 util.emails.email_from_template( 285 320 tmpl='space/cac-change-email.txt',
Note: See TracChangeset
for help on using the changeset viewer.