def _add_person_to_group(person, group): """ Call datastores after adding a person to a group. """ from karaage.datastores import add_person_to_group from karaage.datastores import add_person_to_project from karaage.datastores import add_person_to_institute from karaage.datastores import add_person_to_software from karaage.datastores import add_account_to_group from karaage.datastores import add_account_to_project from karaage.datastores import add_account_to_institute from karaage.datastores import add_account_to_software a_list = list(person.account_set.filter(date_deleted__isnull=True)) add_person_to_group(person, group) for account in a_list: add_account_to_group(account, group) for project in group.project_set.all(): add_person_to_project(person, project) for account in a_list: add_account_to_project(account, project) for institute in group.institute_set.all(): add_person_to_institute(person, institute) for account in a_list: add_account_to_institute(account, institute) for software in group.software_set.all(): add_person_to_software(person, software) for account in a_list: add_account_to_software(account, software)
def save(self, *args, **kwargs): # save the object super(Person, self).save(*args, **kwargs) # update the datastore from karaage.datastores import save_person save_person(self) # update account datastores from karaage.datastores import save_account for ua in self.account_set.filter(date_deleted__isnull=True): save_account(ua) # has username changed? old_username = self._username new_username = self.username if old_username != new_username: from karaage.datastores import set_person_username set_person_username(self, old_username, new_username) # has locked status changed? old_login_enabled = self._login_enabled new_login_enabled = self.login_enabled if old_login_enabled != new_login_enabled: if new_login_enabled: for ua in self.account_set.filter(date_deleted__isnull=True): ua.unlock() log(None, self, 2, 'Unlocked person') else: for ua in self.account_set.filter(date_deleted__isnull=True): ua.lock() log(None, self, 2, 'Locked person') # has the institute changed? old_institute = self._institute new_institute = self.institute if old_institute != new_institute: if old_institute is not None: from karaage.datastores import remove_person_from_institute remove_person_from_institute(self, old_institute) from karaage.datastores import remove_account_from_institute for account in self.account_set.filter(date_deleted__isnull=True): remove_account_from_institute(account, old_institute) if new_institute is not None: from karaage.datastores import add_person_to_institute add_person_to_institute(self, new_institute) from karaage.datastores import add_account_to_institute for account in self.account_set.filter(date_deleted__isnull=True): add_account_to_institute(account, new_institute) # log message log(None, self, 2, 'Saved person') # save current state self._username = self.username self._login_enabled = self.login_enabled self._institute = self.institute
def save(self, *args, **kwargs): # set group if not already set if self.group_id is None: name = str(self.name.lower().replace(' ', '')) self.group,_ = Group.objects.get_or_create(name=name) # save the object super(Institute, self).save(*args, **kwargs) # update the datastore from karaage.datastores import save_institute save_institute(self) # has group changed? old_group = self._group new_group = self.group if old_group != new_group: if old_group is not None: from karaage.datastores import remove_person_from_institute for person in Person.objects.filter(groups=old_group): remove_person_from_institute(person, self) from karaage.datastores import remove_account_from_institute for account in Account.objects.filter(person__groups=old_group, date_deleted__isnull=True): remove_account_from_institute(account, self) if new_group is not None: from karaage.datastores import add_person_to_institute for person in Person.objects.filter(groups=new_group): add_person_to_institute(person, self) from karaage.datastores import add_account_to_institute for account in Account.objects.filter(person__groups=new_group, date_deleted__isnull=True): add_account_to_institute(account, self) # log message log(None, self, 2, 'Saved institute') # save the current state self._group = self.group