예제 #1
0
파일: abstract.py 프로젝트: lozpdata/ORGI
    def get_or_add_user(self, user, **kwargs):
        """
        Adds a new user to the organization, and if it's the first user makes
        the user an admin and the owner. Uses the `get_or_create` method to
        create or return the existing user.

        `user` should be a user instance, e.g. `auth.User`.

        Returns the same tuple as the `get_or_create` method, the
        `OrganizationUser` and a boolean value indicating whether the
        OrganizationUser was created or not.
        """
        is_admin = kwargs.pop("is_admin", False)
        users_count = self.users.all().count()
        if users_count == 0:
            is_admin = True

        org_user, created = self._org_user_model.objects.get_or_create(
            organization=self, user=user, defaults={"is_admin": is_admin})
        if users_count == 0:
            self._org_owner_model.objects.create(organization=self,
                                                 organization_user=org_user)
        if created:
            # User added signal
            user_added.send(sender=self, user=user)
        return org_user, created
예제 #2
0
    def get_or_add_user(self, user, **kwargs):
        """
        Adds a new user to the organization, and if it's the first user makes
        the user an admin and the owner. Uses the `get_or_create` method to
        create or return the existing user.

        `user` should be a user instance, e.g. `auth.User`.

        Returns the same tuple as the `get_or_create` method, the
        `OrganizationUser` and a boolean value indicating whether the
        OrganizationUser was created or not.
        """
        is_admin = kwargs.pop('is_admin', False)
        users_count = self.users.all().count()
        if users_count == 0:
            is_admin = True

        org_user, created = self._org_user_model.objects\
                                .get_or_create(organization=self,
                                               user=user,
                                               defaults={'is_admin': is_admin})
        if users_count == 0:
            self._org_owner_model.objects\
                .create(organization=self, organization_user=org_user)
        if created:
            # User added signal
            user_added.send(sender=self, user=user)
        return org_user, created
예제 #3
0
파일: abstract.py 프로젝트: lozpdata/ORGI
    def add_user(self, user, is_admin=False):
        """
        Adds a new user and if the first user makes the user an admin and
        the owner.
        """
        users_count = self.users.all().count()
        if users_count == 0:
            is_admin = True
        # TODO get specific org user?
        org_user = self._org_user_model.objects.create(user=user,
                                                       organization=self,
                                                       is_admin=is_admin)
        if users_count == 0:
            # TODO get specific org user?
            self._org_owner_model.objects.create(organization=self,
                                                 organization_user=org_user)

        # User added signal
        user_added.send(sender=self, user=user)
        return org_user
예제 #4
0
    def add_user(self, user, is_admin=False):
        """
        Adds a new user and if the first user makes the user an admin and
        the owner.
        """
        users_count = self.users.all().count()
        if users_count == 0:
            is_admin = True
        # TODO get specific org user?
        org_user = self._org_user_model.objects.create(user=user,
                                                       organization=self,
                                                       is_admin=is_admin)
        if users_count == 0:
            # TODO get specific org user?
            self._org_owner_model.objects.create(organization=self,
                                                 organization_user=org_user)

        # User added signal
        user_added.send(sender=self, user=user)
        return org_user