Пример #1
0
def _viewsgn( conn, keys=None, paths=[], hthdrs={}, q={} ) :
    """
    GET  /<db>/_design/<design-doc>/_view/<view-name>,
         if keys is None
    POST /<db>/_design/<design-doc>/_view/<view-name>,
         if keys is a list of view keys to select
    query object `q` for GET,
        descending=<bool>   endkey=<key>        endkey_docid=<id>
        group=<bool>        group_level=<num>   include_docs=<bool>
        key=<key>           limit=<num>         inclusive_end=<bool>
        reduce=<bool>       skip=<num>          stale='ok'
        startkey=<key>      startkey_docid=<id> update_seq=<bool>
    Note that `q` object should provide .items() method with will return a
    list of key,value query parameters.
    """
    hthdrs = conn.mixinhdrs( hthdrs, hdr_acceptjs, hdr_ctypejs )
    # Convert query into JSON-utf8
    q_ = dict([ ( k, rest.data2json(v) ) for k, v in q.items() ])
    if 'startkey_docid' in q :
        q_['startkey_docid'] = q['startkey_docid']
    if 'endkey_docid' in q :
        q_['endkey_docid'] = q['endkey_docid']
    #---
    if keys == None :
        s, h, d = conn.get( paths, hthdrs, None, _query=q_.items() )
    else :
        body = rest.data2json({ 'keys' : keys })
        s, h, d = conn.post( paths, hthdrs, body, _query=q_.items() )
    if s == OK :
        return s, h, d
    else :
        return (None, None, None)
Пример #2
0
def _updatesgn( conn, doc, paths=[], hthdrs={} ) :
    """PUT /<db>/_design/<doc>
    """
    if '_id' not in doc :
        err = '`_id` to be supplied while updating the design doc'
        raise CouchPyError( err )
    body = rest.data2json( doc )
    hthdrs = conn.mixinhdrs( hthdrs, hdr_acceptjs, hdr_ctypejs )
    s, h, d = conn.put( paths, hthdrs, body )
    if s == CREATED and d['ok'] == True :
        return s, h, d
    else :
        return (None, None, None)