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 _add_person_to_group(person, group): """ Call datastores after adding a person to a group. """ from karaage.datastores import add_accounts_to_group from karaage.datastores import add_accounts_to_project from karaage.datastores import add_accounts_to_institute a_list = person.account_set add_accounts_to_group(a_list, group) for project in group.project_set.all(): add_accounts_to_project(a_list, project) for institute in group.institute_set.all(): add_accounts_to_institute(a_list, institute)
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 save(self, *args, **kwargs): created = self.pk is None super(InstituteQuota, self).save(*args, **kwargs) if created: log.add(self.institute, 'Quota %s: Created' % self.machine_category) for field in self._tracker.changed(): log.change( self.institute, 'Quota %s: Changed %s to %s' % (self.machine_category, field, getattr(self, field))) from karaage.datastores import machine_category_save_institute machine_category_save_institute(self.institute) if created: from karaage.datastores import add_accounts_to_institute query = Account.objects.filter(person__groups=self.institute.group) add_accounts_to_institute(query, self.institute)
def save(self, *args, **kwargs): created = self.pk is None super(InstituteQuota, self).save(*args, **kwargs) if created: log.add( self.institute, 'Quota %s: Created' % self.machine_category) for field in self._tracker.changed(): log.change( self.institute, 'Quota %s: Changed %s to %s' % (self.machine_category, field, getattr(self, field))) from karaage.datastores import machine_category_save_institute machine_category_save_institute(self.institute) if created: from karaage.datastores import add_accounts_to_institute query = Account.objects.filter(person__groups=self.institute.group) add_accounts_to_institute(query, self.institute)