Example #1
0
    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
Example #2
0
    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
Example #3
0
    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
Example #4
0
    def save(self, *args, **kwargs):
        # save the object
        super(Account, self).save(*args, **kwargs)

        # check if machine_category changed
        moved = False
        old_machine_category = self._machine_category
        new_machine_category = self.machine_category
        if old_machine_category != new_machine_category:
            from karaage.datastores import delete_account
            self.machine_category = old_machine_category
            delete_account(self)
            log(None, self.machine_category, 2,
                'Removed account %s from machine_category' % self)

            self.machine_category = new_machine_category
            moved = True
            log(None, self.machine_category, 2,
                'Added account %s to machine_category' % self)
            log(None, self.person, 2,
                'Changed machine_category of %s' % self)

        # check if it was renamed
        old_username = self._username
        new_username = self.username
        if old_username != new_username:
            if self.date_deleted is None and not moved:
                from karaage.datastores import set_account_username
                set_account_username(self, old_username, new_username)
            log(None, self.machine_category, 2,
                'Changed username of account %s from %s to %s' %
                (self, old_username, new_username))
            log(None, self.person, 2,
                'Changed username of %s from %s to %s' %
                (self, old_username, new_username))

        # check if deleted status changed
        old_date_deleted = self._date_deleted
        new_date_deleted = self.date_deleted
        if old_date_deleted != new_date_deleted:
            if new_date_deleted is not None:
                # account is deactivated
                from karaage.datastores import delete_account
                delete_account(self)
                log(None, self.machine_category, 3,
                    'Deactivated account of %s' % self)
                log(None, self.person, 3,
                    'Deactivated account of %s' % self)
                # deleted
            else:
                # account is reactivated
                log(None, self.machine_category, 3,
                    'Reactivated account of %s' % self)
                log(None, self.person, 3,
                    'Reactivated account of %s' % self)

        # has locked status changed?
        old_login_enabled = self._login_enabled
        new_login_enabled = self.login_enabled
        if old_login_enabled != new_login_enabled:
            if self.login_enabled:
                log(None, self.machine_category, 2,
                    'Unlocked account %s' % self)
                log(None, self.person, 2,
                    'Unlocked account %s' % self)
            else:
                log(None, self.machine_category, 2,
                    'Locked account %s' % self)
                log(None, self.person, 2,
                    'Locked account %s' % self)

        # makes sense to lock non-existant account
        if new_date_deleted is not None:
            self.login_enabled = False

        # update the datastore
        if self.date_deleted is None:
            from karaage.datastores import save_account
            save_account(self)

        # log message
        log(None, self.machine_category, 2,
            'Saved account %s' % self)
        log(None, self.person, 2,
            'Saved account %s' % self)

        # save current state
        self._username = self.username
        self._machine_category = self.machine_category
        self._date_deleted = self.date_deleted
        self._login_enabled = self.login_enabled
Example #5
0
    def save(self, *args, **kwargs):
        created = self.pk is None

        # save the object
        super(Account, self).save(*args, **kwargs)

        if created:
            log.add(
                self.person,
                'Account %s: Created' % self)
        for field in self._tracker.changed():
            if field != "password":
                log.change(
                    self.person,
                    'Account %s: Changed %s to %s'
                    % (self, field, getattr(self, field)))

        # check if it was renamed
        if self._tracker.has_changed('username'):
            old_username = self._tracker.previous('username')
            if old_username is not None:
                new_username = self.username
                if self.date_deleted is None:
                    from karaage.datastores import set_account_username
                    set_account_username(self, old_username, new_username)
                log.change(
                    self.person,
                    'Account %s: Changed username from %s to %s' %
                    (self, old_username, new_username))

        # check if deleted status changed
        if self._tracker.has_changed('date_deleted'):
            if self.date_deleted is not None:
                # account is deactivated
                from karaage.datastores import delete_account
                delete_account(self)
                log.delete(
                    self.person,
                    'Account %s: Deactivated account' % self)
                # deleted
            else:
                # account is reactivated
                log.add(
                    self.person,
                    'Account %s: Activated' % self)

        # makes sense to lock non-existant account
        if self.date_deleted is not None:
            self.login_enabled = False

        # update the datastore
        if self.date_deleted is None:
            from karaage.datastores import save_account
            save_account(self)

            if self._password is not None:
                from karaage.datastores import set_account_password
                set_account_password(self, self._password)
                log.change(
                    self.person,
                    'Account %s: Changed Password' % self)
                self._password = None