Changeset 89be44c
- Timestamp:
- Aug 5, 2011, 3:42:44 AM (15 years ago)
- Branches:
- master, space-access, stable, stage, test-hooks
- Children:
- 7444bbe
- Parents:
- a8d80c2
- git-author:
- Alex Dehnert <adehnert@…> (08/05/11 03:42:44)
- git-committer:
- Alex Dehnert <adehnert@…> (08/05/11 03:42:44)
- Location:
- asadb/groups
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
asadb/groups/admin.py
rd241a05 r89be44c 25 25 'slug', 26 26 'max_count', 27 'require_student', 27 28 ) 28 29 list_display_links = ('id', 'display_name', 'slug', ) -
asadb/groups/models.py
ra8d80c2 r89be44c 61 61 description = models.TextField() 62 62 max_count = models.IntegerField(default=UNLIMITED, help_text='Maximum number of holders of this role. Use %d for no limit.' % UNLIMITED) 63 require_student = models.BooleanField(default=False) 63 64 64 65 def __str__(self, ): … … 101 102 102 103 104 class AthenaMoiraAccount_ActiveManager(models.Manager): 105 def get_query_set(self, ): 106 return super(AthenaMoiraAccount_ActiveManager, self).get_query_set().filter(del_date=None) 107 103 108 class AthenaMoiraAccount(models.Model): 104 109 username = models.CharField(max_length=8) … … 111 116 del_date = models.DateField(help_text="Date when this person was removed from the dump.", blank=True, null=True, ) 112 117 mod_date = models.DateField(help_text="Date when this person's record was last changed.", blank=True, null=True, ) 118 119 objects = models.Manager() 120 active_accounts = AthenaMoiraAccount_ActiveManager() 121 122 def is_student(self, ): 123 # XXX: Is this... right? 124 return self.account_class == 'G' or self.account_class.isdigit() 125 113 126 def __str__(self, ): 114 127 if self.mutable: -
asadb/groups/views.py
ree679c6 r89be44c 163 163 164 164 new_people = {} 165 moira_accounts = {} 165 166 for i in range(max_new): 166 167 key = "extra.%d" % (i, ) 167 if key in request.POST: 168 # TODO: validate as real usernames 169 new_people[i] = request.POST[key] 168 if key in request.POST and request.POST[key] != "": 169 username = request.POST[key] 170 try: 171 moira_accounts[username] = groups.models.AthenaMoiraAccount.active_accounts.get(username=username) 172 new_people[i] = username 173 except groups.models.AthenaMoiraAccount.DoesNotExist: 174 msgs.append('Athena account "%s" appears not to exist. Changes involving them have been ignored.' % (username, )) 175 for person in people: 176 try: 177 moira_accounts[person] = groups.models.AthenaMoiraAccount.active_accounts.get(username=person) 178 except groups.models.AthenaMoiraAccount.DoesNotExist: 179 msgs.append('Athena account "%s" appears not to exist. They can not be added to new roles. You should remove them from any roles they hold, if you have not already.' % (person, )) 170 180 for role in roles: 171 181 key = "holders.%s" % (role.slug, ) … … 180 190 for person in people: 181 191 if person in new_holders: 182 # TODO: validate student status of appropriate officers183 192 if (person, role) in officers_map: 193 if role.require_student and not moira_accounts[person].is_student(): 194 msgs.append('Only students can have the %s role, and %s does not appear to be a student. You should replace this person ASAP.' % (role, person, )) 184 195 #changes.append(("Kept", "yellow", person, role)) 185 196 kept += 1 186 197 else: 187 holder = groups.models.OfficeHolder(person=person, role=role, group=group,) 188 holder.save() 189 changes.append(("Added", "green", person, role)) 198 if person not in moira_accounts: 199 msgs.append('Could not add nonexistent Athena account "%s" as %s.' % (person, role, )) 200 elif role.require_student and not moira_accounts[person].is_student(): 201 msgs.append('Only students can have the %s role, and %s does not appear to be a student.' % (role, person, )) 202 else: 203 holder = groups.models.OfficeHolder(person=person, role=role, group=group,) 204 holder.save() 205 changes.append(("Added", "green", person, role)) 190 206 else: 191 207 if (person, role) in officers_map: … … 199 215 if i in new_people: 200 216 person = new_people[i] 201 holder = groups.models.OfficeHolder(person=person, role=role, group=group,) 202 holder.save() 203 changes.append(("Added", "green", person, role)) 217 if role.require_student and not moira_accounts[person].is_student(): 218 msgs.append('Only students can have the %s role, and %s does not appear to be a student.' % (role, person, )) 219 else: 220 holder = groups.models.OfficeHolder(person=person, role=role, group=group,) 221 holder.save() 222 changes.append(("Added", "green", person, role)) 204 223 205 224 # reload the data
Note: See TracChangeset
for help on using the changeset viewer.