コード例 #1
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def get_by_email(email):
        """
        Get chino user object by email, null if it not exist
        NB: the mail attribute requires indexing!
        """

        if chino_data.CHINO_DEBUG:
            return User._create_debug_user()

        _chino = models.get_chino_client()

        res = _chino.searches.users(settings.CHINO_USERS_SCHEMA,
                                    result_type="FULL_CONTENT",
                                    filters=[{
                                        "field": "email",
                                        "type": "eq",
                                        "value": email
                                    }])

        if res.paging.count == 1:
            return res.users[0]

        # for cu in get_all_chino_users(_chino):
        #     if cu.attributes.email == email:
        #         return cu

        return None
コード例 #2
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def get_by_username(username):
        """
        Get chino user object by email, null if it not exist
        """

        if chino_data.CHINO_DEBUG:
            return User._create_debug_user()

        _chino = models.get_chino_client()

        res = _chino.searches.users(settings.CHINO_USERS_SCHEMA,
                                    result_type="FULL_CONTENT",
                                    filters=[{
                                        "field": "username",
                                        "type": "eq",
                                        "value": username
                                    }])

        if res.paging.count == 1:
            return res.users[0]

        # for cu in get_all_chino_users(_chino):
        #     if cu.username == username:
        #         return cu

        return None
コード例 #3
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def fetch(django_related):
        """
        Makes a chino call and returns a ChinoUser filled with all

        """
        _chino = models.get_chino_client()

        chino_related = _chino.documents.detail(django_related.chino_id)

        user = Related._copy_remote(django_related, chino_related)

        return user
コード例 #4
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def update(self, django_related):
        """
        Syncs the given instance of Related, associated with the given
        django_related, to chino
        """

        _chino = models.get_chino_client()

        data = {
            'content': self._get_attrs(),
        }

        # TODO
        _chino.documents.update(django_related.chino_id, **data)

        return
コード例 #5
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def fetch(django_user, indepth=True):
        """
        Makes a chino call and returns a ChinoUser filled with all

        """

        if chino_data.CHINO_DEBUG:
            return User._create_debug_user()

        _chino = models.get_chino_client()

        chino_user = _chino.users.detail(django_user.chino_id)

        user = User._copy_remote(django_user, chino_user, indepth=indepth)

        return user
コード例 #6
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def username_available(username):
        """
        Checks whether the given username is taken or is available
        """

        if chino_data.CHINO_DEBUG:
            return User._create_debug_user()

        _chino = models.get_chino_client()
        exists = _chino.searches.users(settings.CHINO_USERS_SCHEMA,
                                       result_type="USERNAME_EXISTS",
                                       filters=[{
                                           "field": "username",
                                           "type": "eq",
                                           "value": username
                                       }])
        return not exists
コード例 #7
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def check_password(username, password):

        if chino_data.CHINO_DEBUG:
            # Just don't do anything
            return True

        # TODO: There will soon be a search/filter feature

        _chino = models.get_chino_client()

        try:
            _chino.users.login(username, password)
        except CallError:
            # Unable to authenticate..
            return False

        return True
コード例 #8
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def set_password(self, django_user, password):

        if chino_data.CHINO_DEBUG:
            # Just don't do anything
            return

        _chino = models.get_chino_client()

        # TODO: There will soon be a patch feature

        data = {
            'password': password,
        }

        _chino.users.partial_update(django_user.chino_id, **data)

        return
コード例 #9
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def create(self, django_related_to):
        """
        Creates the given related in the chino backend. Returns the created
        Related instance
        """

        _chino = models.get_chino_client()

        attrs = self._get_attrs()

        chino_related = _chino.documents.create(settings.CHINO_RELATEDS_SCHEMA,
                                                attrs)

        rel = models.Related(patient=django_related_to,
                             chino_id=chino_related.document_id)
        rel.save()

        return rel
コード例 #10
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def fetch_many(django_users, indepth=False):
        _chino = models.get_chino_client()

        chino_ids2user = dict((dj.chino_id, dj) for dj in django_users)
        chino_ids = [_id for _id in chino_ids2user.iterkeys()]

        chino_users = _chino.searches.users(settings.CHINO_USERS_SCHEMA,
                                            result_type="FULL_CONTENT",
                                            filters=[{
                                                "field": "_id",
                                                "type": "in",
                                                "value": chino_ids
                                            }])

        return [
            User._copy_remote(chino_ids2user[cu.user_id], cu, indepth=indepth)
            for cu in chino_users.users
        ]
コード例 #11
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def email_available(email):
        """
        Checks whether the given email is taken or is available
        NB: the mail attribute requires indexing!
        """

        if chino_data.CHINO_DEBUG:
            # Just don't do anything
            return True

        _chino = models.get_chino_client()

        exists = _chino.searches.users(settings.CHINO_USERS_SCHEMA,
                                       result_type="EXISTS",
                                       filters=[{
                                           "field": "email",
                                           "type": "eq",
                                           "value": email
                                       }])
        return not exists
コード例 #12
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def update(self, django_user):
        """
        Syncs the given instance of User, associated with the given
        django_user, to chino
        """

        if chino_data.CHINO_DEBUG:
            # Just don't do anything
            return

        _chino = models.get_chino_client()

        data = {
            'username': self.username,
            'attributes': self._get_attrs(),
        }

        chino_user = _chino.users.update(django_user.chino_id, **data)

        return
コード例 #13
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def create(self, password):
        """
        Creates the given user in the chino backend. Returns the created
        ChinoUser instance
        """

        if chino_data.CHINO_DEBUG:
            user = models.ChinoUser(chino_id=chino_data.get_random_chino_id())
            user.save()
            return user

        _chino = models.get_chino_client()

        attrs = self._get_attrs()

        chino_user = _chino.users.create(settings.CHINO_USERS_SCHEMA,
                                         username=self.username,
                                         password=password,
                                         attributes=attrs)

        user = models.ChinoUser(chino_id=chino_user.user_id)
        user.save()

        return user
コード例 #14
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def fetch_many(django_relateds, each=None):
        # TODO: Fix me: I need improvements: A search query over chino
        # DB instead of filtering afterwards would be probably the
        # best solution

        _chino = models.get_chino_client()

        chino_ids = dict((dj.chino_id, dj) for dj in django_relateds)

        res = []
        for cr in _chino.documents.list(settings.CHINO_RELATEDS_SCHEMA,
                                        full_document=True).documents:
            if cr.document_id in chino_ids:
                dj_rel = chino_ids[cr.document_id]

                related = Related._copy_remote(dj_rel, cr)

                if each: each(dj_rel, related)

                res.append(related)
                pass
            pass

        return res
コード例 #15
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
def list_users():
    _chino = models.get_chino_client()

    for u in get_all_chino_users(_chino):
        print u.username, u.user_id, u.attributes.first_name, u.attributes.last_name
コード例 #16
0
ファイル: chino_model.py プロジェクト: dosdos/chino-django
    def delete(django_related):
        _chino = models.get_chino_client()

        _chino.documents.delete(django_related.chino_id, force=True)

        return