get the account

    Arguments:
        query_mes {[type]} -- [description]

    Keyword Arguments:
        collection {[type]} -- [description] (default: {DATABASE})

    Returns:
        [type] -- [description]
16069
def QA_fetch_strategy(message={}, db=DATABASE):
    
    collection = DATABASE.strategy
    return [res for res in collection.find(message, {"_id": 0})]
279007
def get_account_details(self):
        
        headers = self._manager.get_account_headers()
        acct_prefix = "x-account-"
        meta_prefix = ACCOUNT_META_PREFIX.lower()
        ret = {}
        for hkey, hval in list(headers.items()):
            lowkey = hkey.lower()
            if lowkey.startswith(acct_prefix):
                if not lowkey.startswith(meta_prefix):
                    cleaned = hkey.replace(acct_prefix, "").replace("-", "_")
                    try:
                        # Most values are ints
                        ret[cleaned] = int(hval)
                    except ValueError:
                        ret[cleaned] = hval
        return ret
247130
def db(self, db_alias, shard_key=None):
        
        if shard_key is None:
            shard_key = ''

        db_key = db_alias + '__' + str(shard_key)
        if db_key not in self.__db_list:
            self.__db_list[db_key] = DbQueryService(self, self.__default_headers, {"db_alias": db_alias, "dbAlias": db_alias, "shard_find_key": shard_key, "shardKey": shard_key})
        return self.__db_list[db_key]
400299
def accounts(self):
        
        d = {}

        if False and not self._account_password:
            from ambry.dbexceptions import ConfigurationError
            raise ConfigurationError(
                "Can't access accounts without setting an account password"
                " either in the accounts.password config, or in the AMBRY_ACCOUNT_PASSWORD"
                " env var.")

        for act in self.database.session.query(Account).all():
            if self._account_password:
                act.secret_password = self._account_password
            e = act.dict
            a_id = e['account_id']
            d[a_id] = e

        return d
617313
def get_sub_accounts_of_account(self, account_id, recursive=None):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - account_id
        """ID"""
        path["account_id"] = account_id

        # OPTIONAL - recursive
        """If true, the entire account tree underneath
        this account will be returned (though still paginated). If false, only
        direct sub-accounts of this account will be returned. Defaults to false."""
        if recursive is not None:
            params["recursive"] = recursive

        self.logger.debug("GET /api/v1/accounts/{account_id}/sub_accounts with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("GET", "/api/v1/accounts/{account_id}/sub_accounts".format(**path), data=data, params=params, all_pages=True)
1058947
def get_one(cls, db, *args, **kwargs):
        
        data = db[cls.collection].find_one(*args, **kwargs)
        if data:
            return cls.wrap_incoming(data, db)
        else:
            return None
262182
def get(self, account_id):
        
        response = self.client._make_request('/accounts/{0}'.format(account_id))
        return response.json()
370452
def get_collection(self, session, query, api_key):
        
        model = self._fetch_model(api_key)
        include = self._parse_include(query.get('include', '').split(','))
        fields = self._parse_fields(query)
        included = {}
        sorts = query.get('sort', '').split(',')
        order_by = []

        collection = session.query(model)

        for attr in sorts:
            if attr == '':
                break

            attr_name, is_asc = [attr[1:], False]\
                if attr[0] == '-'\
                else [attr, True]

            if attr_name not in model.__mapper__.all_orm_descriptors.keys()\
                    or not hasattr(model, attr_name)\
                    or attr_name in model.__mapper__.relationships.keys():
                return NotSortableError(model, attr_name)

            attr = getattr(model, attr_name)
            if not hasattr(attr, 'asc'):
                # pragma: no cover
                return NotSortableError(model, attr_name)

            check_permission(model, attr_name, Permissions.VIEW)

            order_by.append(attr.asc() if is_asc else attr.desc())

        if len(order_by) > 0:
            collection = collection.order_by(*order_by)

        pos = -1
        start, end = self._parse_page(query)

        response = JSONAPIResponse()
        response.data['data'] = []

        for instance in collection:
            try:
                check_permission(instance, None, Permissions.VIEW)
            except PermissionDeniedError:
                continue

            pos += 1
            if end is not None and (pos < start or pos > end):
                continue

            built = self._render_full_resource(instance, include, fields)
            included.update(built.pop('included'))
            response.data['data'].append(built)

        response.data['included'] = list(included.values())
        return response
763071
def get_query_kwargs(es_defs):
    
    rtn_dict = {}
    if es_defs:
        if es_defs.get("kds_esSpecialUnion"):
            rtn_dict['special_union'] = \
                    es_defs["kds_esSpecialUnion"][0]
        if es_defs.get("kds_esQueryFilter"):
            rtn_dict['filters'] = \
                    es_defs["kds_esQueryFilter"][0]
    return rtn_dict
479816
def _get_collection(self, collection_name):
        
        try:
            return self._database[collection_name]
        except InvalidName as ex:
            raise DataSourceError("Cannot access MongoDB collection %s!"
                                  % collection_name) from ex
        except Exception as ex:
            raise DataSourceError("Unexpected error when accessing MongoDB"
                                  "collection %s!"
                                  % collection_name) from ex
865779
def get(cls, user_id, db_session=None):
        
        db_session = get_db_session(db_session)
        return db_session.query(cls.model).get(user_id)
855067
def get(self):
        """"""
        _, accounts = BaseAccount.search()

        if ROLE_ADMIN not in session['user'].roles:
            accounts = list(filter(lambda acct: acct.account_id in session['accounts'], accounts))

        if accounts:
            return self.make_response({
                'message': None,
                'accounts': [x.to_json(is_admin=ROLE_ADMIN in session['user'].roles or False) for x in accounts]
            })
        else:
            return self.make_response({
                'message': 'Unable to find any accounts',
                'accounts': None
            }, HTTP.NOT_FOUND)
1358517
def get(self, *args, **kwargs):
        
        clone = self.filter(*args, **kwargs)
        num = len(clone)
        if num == 1:
            return clone._result_cache[0]
        if not num:
            raise self.model.DoesNotExist(
                "%s matching query does not exist. "
                "Lookup parameters were %s" %
                #(self.model._meta.object_name, kwargs))
                (self.model.__class__.__name__, kwargs))
        raise self.model.MultipleObjectsReturned(
            "get() returned more than one %s -- it returned %s! "
            "Lookup parameters were %s" %
            #(self.model._meta.object_name, num, kwargs))
            (self.model.__class__.__name__, num, kwargs))
830410
def raw_query_mongo_db(kwargs, database_name, collection_name):
    # for key in kwargs:
    #    print "arg: %s: %s" % (key, kwargs[key])
    """"""
    l = []
    response_dict = {}

    try:
        mongodb_client_url = getattr(settings, 'MONGODB_CLIENT',
                                 'mongodb://localhost:27017/')
        mc = MongoClient(mongodb_client_url,document_class=OrderedDict)
        db = mc[database_name]
        transactions = db[collection_name]
        mysearchresult = transactions.find(kwargs)
        mysearchcount = mysearchresult.count()
        if mysearchcount > 0:
            response_dict['code'] = 200
            for d in mysearchresult:
                l.append(d)
            response_dict['results'] = l
    except:
        # print "Error reading from Mongo"
        # print str(sys.exc_info())
        response_dict['code'] = 400

        response_dict['type'] = "Error"
        response_dict['message'] = str(sys.exc_info())
    return response_dict
69909
def find(self, *args, **kwargs):
    " "
    return Query(*args, db=self, schema=self.schema)
144446
def accounts(self):
        
        if self._accounts is None:
            self._accounts = AccountList(self)
        return self._accounts
631277
def get_queryset(self):
        
        if router.is_sf_database(self.db):
            q = models_sql_query.SalesforceQuery(self.model, where=compiler.SalesforceWhereNode)
            return query.SalesforceQuerySet(self.model, query=q, using=self.db)
        return super(SalesforceManager, self).get_queryset()