Example #1
0
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)
Example #2
0
    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