def save(self, *args, **kwargs): created = self.pk is None # save the object super(Institute, self).save(*args, **kwargs) if created: log.add(self, 'Created') for field in self._tracker.changed(): log.change(self, 'Changed %s to %s' % (field, getattr(self, field))) # update the datastore from karaage.datastores import machine_category_save_institute machine_category_save_institute(self) # has group changed? if self._tracker.has_changed("group_id"): old_group_pk = self._tracker.previous("group_id") new_group = self.group if old_group_pk is not None: old_group = Group.objects.get(pk=old_group_pk) from karaage.datastores import remove_accounts_from_institute query = Account.objects.filter(person__groups=old_group) remove_accounts_from_institute(query, self) if new_group is not None: from karaage.datastores import add_accounts_to_institute query = Account.objects.filter(person__groups=new_group) add_accounts_to_institute(query, self)
def delete(self, *args, **kwargs): log.delete(self.institute, 'Quota %s: Deleted' % self.machine_category) from karaage.datastores import remove_accounts_from_institute query = Account.objects.filter(person__groups=self.institute.group) remove_accounts_from_institute(query, self.institute) super(InstituteQuota, self).delete(*args, **kwargs) from karaage.datastores import machine_category_delete_institute machine_category_delete_institute(self.institute, self.machine_category)
def _remove_person_from_group(person, group): """ Call datastores after removing a person from a group. """ from karaage.datastores import remove_accounts_from_group from karaage.datastores import remove_accounts_from_project from karaage.datastores import remove_accounts_from_institute a_list = person.account_set remove_accounts_from_group(a_list, group) for project in group.project_set.all(): remove_accounts_from_project(a_list, project) for institute in group.institute_set.all(): remove_accounts_from_institute(a_list, institute)
def delete(self, *args, **kwargs): log.delete( self.institute, 'Quota %s: Deleted' % self.machine_category) from karaage.datastores import remove_accounts_from_institute query = Account.objects.filter(person__groups=self.institute.group) remove_accounts_from_institute(query, self.institute) super(InstituteQuota, self).delete(*args, **kwargs) from karaage.datastores import machine_category_delete_institute machine_category_delete_institute( self.institute, self.machine_category)
def save(self, *args, **kwargs): created = self.pk is None # save the object super(Person, self).save(*args, **kwargs) if created: log.add(self, 'Created') for field in self._tracker.changed(): if field != "password": log.change( self, 'Changed %s to %s' % (field, getattr(self, field))) # update datastores from karaage.datastores import save_account for ua in self.account_set.filter(date_deleted__isnull=True): save_account(ua) # has locked status changed? if self._tracker.has_changed("login_enabled"): if self.login_enabled: for ua in self.account_set.filter(date_deleted__isnull=True): ua.unlock() else: for ua in self.account_set.filter(date_deleted__isnull=True): ua.lock() # has the institute changed? if self._tracker.has_changed("institute_id"): from karaage.institutes.models import Institute old_institute_pk = self._tracker.previous("institute_id") new_institute = self.institute if old_institute_pk is not None: old_institute = Institute.objects.get(pk=old_institute_pk) from karaage.datastores import remove_accounts_from_institute query = self.account_set remove_accounts_from_institute(query, old_institute) if new_institute is not None: from karaage.datastores import add_accounts_to_institute query = self.account_set add_accounts_to_institute(query, new_institute) if self._raw_password is not None: for ua in self.account_set.filter(date_deleted__isnull=True): ua.set_password(self._raw_password) ua.save() log.change(self, 'Changed Password') self._raw_password = None
def delete(self, *args, **kwargs): # delete the object log.delete(self, 'Deleted') super(Institute, self).delete(*args, **kwargs) # update datastore associations old_group_pk = self._tracker.previous("group_id") if old_group_pk is not None: old_group = Group.objects.get(pk=old_group_pk) from karaage.datastores import remove_accounts_from_institute query = Account.objects.filter(person__groups=old_group) remove_accounts_from_institute(query, self) # update the datastore from karaage.datastores import machine_category_delete_institute machine_category_delete_institute(self)