示例#1
0
def _remove_person_from_group(person, group):
    """ Call datastores after removing a person from a group. """
    from karaage.datastores import remove_person_from_group
    from karaage.datastores import remove_person_from_project
    from karaage.datastores import remove_person_from_institute
    from karaage.datastores import remove_person_from_software
    from karaage.datastores import remove_account_from_group
    from karaage.datastores import remove_account_from_project
    from karaage.datastores import remove_account_from_institute
    from karaage.datastores import remove_account_from_software

    a_list = list(person.account_set.filter(date_deleted__isnull=True))
    remove_person_from_group(person, group)
    for account in a_list:
        remove_account_from_group(account, group)
    for project in group.project_set.all():
        remove_person_from_project(person, project)
        for account in a_list:
            remove_account_from_project(account, project)
    for institute in group.institute_set.all():
        remove_person_from_institute(person, institute)
        for account in a_list:
            remove_account_from_institute(account, institute)
    for software in group.software_set.all():
        remove_person_from_software(person, software)
        for account in a_list:
            remove_account_from_software(account, software)
示例#2
0
    def delete(self, *args, **kwargs):
        # ensure nothing connects to this project
        query = Account.objects.filter(default_project=self)
        query.update(default_project=None)

        # Get list of accounts.
        # We do this here to ensure nothing gets deleted when
        # we call the super method.
        old_group_pk = self._tracker.previous("group_id")
        if old_group_pk is not None:
            old_group = Group.objects.get(pk=old_group_pk)
            query = Account.objects.filter(person__groups=old_group)
            query = query.filter(date_deleted__isnull=True)
            accounts = list(query)
        else:
            accounts = []

        # delete the object
        log.delete(self, 'Deleted')
        super(Project, self).delete(*args, **kwargs)

        # update datastore associations
        for account in accounts:
            from karaage.datastores import remove_account_from_project
            remove_account_from_project(account, self)

        # update the datastore
        from karaage.datastores import delete_project
        delete_project(self)
示例#3
0
    def delete(self, *args, **kwargs):
        # ensure nothing connects to this project
        query = Account.objects.filter(default_project=self)
        query.update(default_project=None)

        # Get list of accounts.
        # We do this here to ensure nothing gets deleted when
        # we call the super method.
        old_group_pk = self._tracker.previous("group_id")
        if old_group_pk is not None:
            old_group = Group.objects.get(pk=old_group_pk)
            query = Account.objects.filter(person__groups=old_group)
            query = query.filter(date_deleted__isnull=True)
            accounts = list(query)
        else:
            accounts = []

        # delete the object
        log.delete(self, 'Deleted')
        super(Project, self).delete(*args, **kwargs)

        # update datastore associations
        for account in accounts:
            from karaage.datastores import remove_account_from_project
            remove_account_from_project(account, self)

        # update the datastore
        from karaage.datastores import delete_project
        delete_project(self)
示例#4
0
文件: models.py 项目: russell/karaage
    def delete(self, *args, **kwargs):
        # ensure nothing connects to this project
        query = Account.objects.filter(default_project=self)
        query.update(default_project=None)

        # delete the object
        super(Project, self).delete(*args, **kwargs)

        # update datastore associations
        old_group = self._group
        if old_group is not None:
            from karaage.datastores import remove_person_from_project
            for person in Person.objects.filter(groups=old_group):
                remove_person_from_project(person, self)
            from karaage.datastores import remove_account_from_project
            for account in Account.objects.filter(person__groups=old_group, date_deleted__isnull=True):
                remove_account_from_project(account, self)

        # update the datastore
        from karaage.datastores import delete_project
        delete_project(self)
示例#5
0
文件: models.py 项目: russell/karaage
    def save(self, *args, **kwargs):
        # set group if not already set
        if self.group_id is None:
            name = self.pid
            self.group,_ = Group.objects.get_or_create(name=name)

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

        # update the datastore
        from karaage.datastores import save_project
        save_project(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_project
                for person in Person.objects.filter(groups=old_group):
                    remove_person_from_project(person, self)
                from karaage.datastores import remove_account_from_project
                for account in Account.objects.filter(person__groups=old_group, date_deleted__isnull=True):
                    remove_account_from_project(account, self)
            if new_group is not None:
                from karaage.datastores import add_person_to_project
                for person in Person.objects.filter(groups=new_group):
                    add_person_to_project(person, self)
                from karaage.datastores import add_account_to_project
                for account in Account.objects.filter(person__groups=new_group, date_deleted__isnull=True):
                    add_account_to_project(account, self)

        # log message
        log(None, self, 2, 'Saved project')

        # save the current state
        self._group = self.group