Пример #1
0
    def format_data(self, keys_only, docs, keys, forceUnique, current_rt=None):
        sentIDs = []
        prefix = '{"documents":[\n'
        num_sent = 0
        doc_count = 0
        if docs is not None:
            for row in docs:
                doc_count += 1
                alreadySent = (row["id"] in sentIDs)
                if not alreadySent or not forceUnique:
                    sentIDs.append(row["id"])
                    if keys_only:
                        return_data = {"doc_ID": row["id"]}
                    else:
                        # Get the resource data and update with the node timestamp data
                        # That the view has in value['timestamp']
                        resourceData = {}
                        resourceData = row["doc"]
                        return_data = {
                            "doc_ID": row["id"],
                            "resource_data_description": resourceData
                        }
                    yield prefix + json.dumps(return_data)
                    num_sent += 1
                    prefix = ",\n"
                else:
                    log.debug(
                        "{0} skipping: alreadySent {1} / forceUnique {2}".
                        format(doc_count, repr(alreadySent), forceUnique))

        if doc_count == 0:
            yield prefix

        maxResults = self._get_view_total(keys=keys,
                                          resumptionToken=current_rt)

        rt = " "
        if self.enable_flow_control:
            if current_rt != None and "offset" in current_rt and current_rt[
                    "offset"] is not None:
                offset = current_rt["offset"]
            else:
                offset = 0

            if offset + doc_count < maxResults:
                rt = ''' "resumption_token":"{0}", '''.format(
                    resumption_token.get_offset_token(self.service_id,
                                                      offset=offset +
                                                      doc_count,
                                                      keys=keys))

        yield '\n],' + rt + '"resultCount":' + str(maxResults) + '}'
Пример #2
0
    def format_data(self,keys_only,docs, keys, forceUnique, current_rt=None):
        sentIDs = []
        prefix = '{"documents":[\n'
        num_sent = 0
        doc_count = 0
        update_resumption_max_results = current_rt and "maxResults" in current_rt and current_rt["maxResults"] != None
        if docs is not None:
            for row in docs:
                doc_count += 1
                alreadySent = (row["id"] in sentIDs)
                if not alreadySent or not forceUnique:
                    sentIDs.append(row["id"])
                    if keys_only:
                        return_data = {"doc_ID":row["id"]}
                    else:
                        # Get the resource data and update with the node timestamp data
                        # That the view has in value['timestamp']
                        resourceData = {}
                        resourceData = row["doc"]
                        return_data = {"doc_ID":row["id"], "resource_data_description":resourceData}
                    yield prefix + json.dumps(return_data)
                    num_sent += 1
                    prefix = ",\n"
                else:
                    log.debug("{0} skipping: alreadySent {1} / forceUnique {2}".format(doc_count, repr(alreadySent), forceUnique))
                    if update_resumption_max_results:
                        current_rt["maxResults"] = current_rt["maxResults"] - 1
        
        if doc_count == 0:
            yield prefix
        
        maxResults = self._get_view_total(keys=keys,resumptionToken=current_rt)
        
        rt = " "
        if self.enable_flow_control:
            if current_rt != None and "offset" in current_rt and current_rt["offset"] is not None:
                offset = current_rt["offset"]
            else:
                offset = 0
                
            if offset+doc_count < maxResults:
                rt = ''' "resumption_token":"{0}", '''.format(resumption_token.get_offset_token(self.service_id, offset=offset+doc_count, keys=keys, maxResults=maxResults))

        
        db  = couchdb.Server(appConfig['couchdb.url'])[appConfig['couchdb.db.resourcedata']]
        yield '\n],'+rt+'"resultCount":'+str(maxResults) +',"viewUpToDate":'+h.isViewUpdated(db,'_design/learningregistry-slice')+'}'
Пример #3
0
    def format_data(self,keys_only,docs, keys, forceUnique, current_rt=None):
        sentIDs = []
        prefix = '{"replyStart":"'+str(datetime.today())+'", "keyCount":'+str(len(keys)) +', "documents":[\n'
        num_sent = 0
        doc_count = 0
        if docs is not None:
            for row in docs:
                doc_count += 1
                alreadySent = (row["id"] in sentIDs)
                if not alreadySent or not forceUnique:
                    sentIDs.append(row["id"])
                    if keys_only:
                        return_data = {"doc_ID":row["id"]}
                    else:
                        # Get the resource data and update with the node timestamp data
                        # That the view has in value['timestamp']
                        resourceData = {}
                        resourceData = row["doc"]
                        return_data = {"doc_ID":row["id"], "resource_data_description":resourceData}
                    yield prefix + json.dumps(return_data)
                    num_sent += 1
                    prefix = ",\n"
                else:
                    log.debug("{0} skipping: alreadySent {1} / forceUnique {2}".format(doc_count, repr(alreadySent), forceUnique))
        
        if doc_count == 0:
            yield prefix
        
        maxResults = self._get_view_total(keys=keys,resumptionToken=current_rt)
        
        rt = " "
        if self.enable_flow_control:
            if current_rt != None and "offset" in current_rt and current_rt["offset"] is not None:
                offset = current_rt["offset"]
            else:
                offset = 0
                
            if offset+doc_count < maxResults:
                rt = ''' "resumption_token":"{0}", '''.format(resumption_token.get_offset_token(self.service_id, offset=offset+doc_count, keys=keys))

        

        yield '\n],'+rt+'"resultCount":'+str(maxResults) +', "replyEnd":"'+str(datetime.today())+'"}'