(poll_id, analyst, page=1, mult=10)
return ret
Given a Poll ID (unix timestamp), parse all associated content blocks and
    generate preview data for the CRITs TLOs that can be imported into CRITs

    :param poll_id: ID of the desired TAXII poll (unix timestamp)
    :type poll_id: string
    :param analyst: Userid of the analyst requesting the preview
    :type analyst: string
    :param page: The desired page number
    :type page: int
    :param mult: The desired number of blocks/page
    :type mult: int
    :returns: dict with keys:
              "successes" (int) - Count of successful preview objects
              "failures" (list) - Failure messages
              "blocks" (list) - Content blocks, their metadata, and preview objects
              "start" (string) - Exclusive begin component of the timerange that was polled
              "end" (string) - Inclusive end component of the timerange that was polled
              "poll_time" (:class:`datetime.datetime`) - Datetime the feed was polled
              "taxii_msg_id" (string) - TAXII Message ID of the poll
              "source" (string) - Source from which the content came
              "feed" (string) - Name of the TAXII feed/collection that was polled
                                or name of the file that was uploaded
              "analyst" (string) - Userid of the anaylst that initiated the poll
Given a Poll ID (unix timestamp), parse all associated content blocks and
    generate preview data for the CRITs TLOs that can be imported into CRITs
Given a Poll ID ( unix timestamp ) parse all associated content blocks and generate preview data for the CRITs TLOs that can be imported into CRITs
def generate_import_preview(poll_id, analyst, page=1, mult=10):
    """
    Given a Poll ID (unix timestamp), parse all associated content blocks and
    generate preview data for the CRITs TLOs that can be imported into CRITs

    :param poll_id: ID of the desired TAXII poll (unix timestamp)
    :type poll_id: string
    :param analyst: Userid of the analyst requesting the preview
    :type analyst: string
    :param page: The desired page number
    :type page: int
    :param mult: The desired number of blocks/page
    :type mult: int
    :returns: dict with keys:
              "successes" (int) - Count of successful preview objects
              "failures" (list) - Failure messages
              "blocks" (list) - Content blocks, their metadata, and preview objects
              "start" (string) - Exclusive begin component of the timerange that was polled
              "end" (string) - Inclusive end component of the timerange that was polled
              "poll_time" (:class:`datetime.datetime`) - Datetime the feed was polled
              "taxii_msg_id" (string) - TAXII Message ID of the poll
              "source" (string) - Source from which the content came
              "feed" (string) - Name of the TAXII feed/collection that was polled
                                or name of the file that was uploaded
              "analyst" (string) - Userid of the anaylst that initiated the poll
    """
    tsvc = get_config('taxii_service')
    hdr_events = tsvc['header_events']
    obs_as_ind = tsvc['obs_as_ind']
    mult = int(mult)
    page = int(page)
    skip = mult * (page - 1)
    p_time = datetime.utcfromtimestamp(float(poll_id))
    block_count = taxii.TaxiiContent.objects(poll_time=p_time).count()
    pages = (block_count / mult) + (1 if block_count % mult else 0)
    while skip > block_count: # prevent invalid skip value
        page -= 1
        skip = mult * (page - 1)
    blocks = taxii.TaxiiContent.objects(poll_time=p_time).limit(mult).skip(skip)
    if not blocks:
        ret = {
          'failures': ['No data exists for Timestamp %s' % p_time],
          'msg': '',
        }
        return ret

    ret = {
            'successes': 0,
            'failures': [],
            'blocks': [],
            'block_count': block_count,
            'timerange': blocks[0].timerange,
            'poll_id': poll_id,
            'poll_time': blocks[0].poll_time,
            'taxii_msg_id': blocks[0].taxii_msg_id,
            'source': blocks[0].hostname,
            'feed': blocks[0].feed,
            'analyst': blocks[0].analyst,
            'page': page,
            'pages': pages,
            'page_range': range(1, pages + 1),
            'mult': mult,
          }

    for num, block in enumerate(blocks):
        tlos = {}
        failures = []

        for e in block.errors:
            err = e.split(': ')
            failures.append((err[1], err[0]))

        if block.content:
            objs = import_standards_doc(block.content, analyst, None, None,
                                        hdr_events, obs_as_ind,
                                        preview_only=True)

            if not objs['success']:
                failures.append((objs['reason'], 'STIX Package'))

            for k in objs['failed']:
                failures.append(k)

            for sid in objs['imported']:
                ret['successes'] += 1
                tlo_meta = objs['imported'][sid]
                tlos.setdefault(tlo_meta[0], []).append((tlo_meta[1],
                                                         tlo_meta[2]))

        ret['blocks'].append({'id': block.id,
                              'num': num + skip + 1,
                              'block_label': block.block_label,
                              'tlos': tlos,
                              'failures': failures,
                              'selected': block.selected})
    return ret
def generate_import_preview ( poll_id , analyst , page = 1 , mult = 10 ) : tsvc = get_config ( 'taxii_service' ) hdr_events = tsvc [ 'header_events' ] obs_as_ind = tsvc [ 'obs_as_ind' ] mult = int ( mult ) page = int ( page ) skip = mult * ( page - 1 ) p_time = datetime . utcfromtimestamp ( float ( poll_id ) ) block_count = taxii . TaxiiContent . objects ( poll_time = p_time ) . count ( ) pages = ( block_count / mult ) + ( 1 if block_count % mult else 0 ) while skip > block_count : # prevent invalid skip value page -= 1 skip = mult * ( page - 1 ) blocks = taxii . TaxiiContent . objects ( poll_time = p_time ) . limit ( mult ) . skip ( skip ) if not blocks : ret = { 'failures' : [ 'No data exists for Timestamp %s' % p_time ] , 'msg' : '' , } return ret ret = { 'successes' : 0 , 'failures' : [ ] , 'blocks' : [ ] , 'block_count' : block_count , 'timerange' : blocks [ 0 ] . timerange , 'poll_id' : poll_id , 'poll_time' : blocks [ 0 ] . poll_time , 'taxii_msg_id' : blocks [ 0 ] . taxii_msg_id , 'source' : blocks [ 0 ] . hostname , 'feed' : blocks [ 0 ] . feed , 'analyst' : blocks [ 0 ] . analyst , 'page' : page , 'pages' : pages , 'page_range' : range ( 1 , pages + 1 ) , 'mult' : mult , } for num , block in enumerate ( blocks ) : tlos = { } failures = [ ] for e in block . errors : err = e . split ( ': ' ) failures . append ( ( err [ 1 ] , err [ 0 ] ) ) if block . content : objs = import_standards_doc ( block . content , analyst , None , None , hdr_events , obs_as_ind , preview_only = True ) if not objs [ 'success' ] : failures . append ( ( objs [ 'reason' ] , 'STIX Package' ) ) for k in objs [ 'failed' ] : failures . append ( k ) for sid in objs [ 'imported' ] : ret [ 'successes' ] += 1 tlo_meta = objs [ 'imported' ] [ sid ] tlos . setdefault ( tlo_meta [ 0 ] , [ ] ) . append ( ( tlo_meta [ 1 ] , tlo_meta [ 2 ] ) ) ret [ 'blocks' ] . append ( { 'id' : block . id , 'num' : num + skip + 1 , 'block_label' : block . block_label , 'tlos' : tlos , 'failures' : failures , 'selected' : block . selected } ) return ret