示例#1
0
def index(collection_id):
    collection = get_db_collection(collection_id)
    record_audit(Audit.ACT_COLLECTION, id=collection.id)
    parser = QueryParser(request.args, request.authz)
    q = Match.group_by_collection(collection.id, authz=request.authz)
    result = DatabaseQueryResult(request, q, parser=parser)
    return MatchCollectionsSerializer.jsonify_result(result)
示例#2
0
文件: xref_api.py 项目: pudo/aleph
def index(collection_id):
    collection = get_db_collection(collection_id)
    record_audit(Audit.ACT_COLLECTION, id=collection.id)
    parser = QueryParser(request.args, request.authz)
    q = Match.group_by_collection(collection.id, authz=request.authz)
    result = DatabaseQueryResult(request, q, parser=parser)
    return MatchCollectionsSerializer.jsonify_result(result)
示例#3
0
def index(id):
    collection = get_db_collection(id)
    parser = QueryParser(request.args, request.authz, limit=10)
    q = Match.group_by_collection(collection.id, authz=request.authz)
    result = DatabaseQueryResult(request, q,
                                 parser=parser,
                                 schema=MatchCollectionsSchema)
    return jsonify(result)
示例#4
0
def summary(id):
    collection = obj_or_404(Collection.by_id(id))
    require(request.authz.can_read(collection.id))
    parser = QueryParser(request.args, request.authz, limit=10)
    q = Match.group_by_collection(collection.id, authz=request.authz)
    result = DatabaseQueryResult(request,
                                 q,
                                 parser=parser,
                                 schema=MatchCollectionsSchema)
    return jsonify(result)
示例#5
0
文件: xref_api.py 项目: we1l1n/aleph
def index(collection_id):
    """
    ---
    get:
      summary: Fetch cross-reference summary
      description: >-
        Fetch cross-reference matches grouped by collection, for entities in
        the collection with id `collection_id`
      parameters:
      - in: path
        name: collection_id
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                allOf:
                - $ref: '#/components/schemas/QueryResponse'
                properties:
                  results:
                    type: array
                    items:
                      $ref: '#/components/schemas/XrefCollection'
      tags:
      - Xref
      - Collection
    """
    collection = get_db_collection(collection_id)
    parser = QueryParser(request.args, request.authz)
    q = Match.group_by_collection(collection.id, authz=request.authz)
    result = DatabaseQueryResult(request, q, parser=parser)
    return MatchCollectionsSerializer.jsonify_result(result)
示例#6
0
def generate_excel(collection, authz, links=True, one_sheet=False):

    limit = 1000

    output = StringIO.StringIO()
    workbook = xlsxwriter.Workbook(output)
    workbook.link_format = workbook.add_format({
        'font_color': 'blue',
        'underline': True
    })
    workbook.header_format = workbook.add_format({
        'font_color': 'white',
        'fg_color': '#982022',
        'bold': True
    })

    # Write the summary worksheet (Collection names and count)
    sheet = workbook.add_worksheet('Summary')
    sheet.set_zoom(125)
    title = 'Cross-referencing: %s' % collection.label
    sheet.merge_range(0, 0, 0, 2, title, workbook.header_format)
    sheet.write(1, 0, 'Collection', workbook.header_format)
    sheet.write(1, 1, 'Matches', workbook.header_format)
    if not one_sheet:
        sheet.write(1, 2, 'Details', workbook.header_format)
    sheet.set_column(2, 2, 20)
    sheet.freeze_panes(1, 0)

    # Query for all the collections with matches
    collections = Match.group_by_collection(collection.id, authz=authz)
    max_label = 70
    offset = 2  # Number of header rows
    for row, result in enumerate(collections, 2):
        if links:
            url = collection_url(result.collection.id)
            sheet.write_url(row, 0, url, workbook.link_format,
                            result.collection.label)
        else:
            sheet.write_string(row, 0, result.collection.label)
        max_label = max(max_label, len(result.collection.label))
        sheet.set_column(0, 0, float(max_label))
        sheet.write_number(row, 1, result.matches)

        if not one_sheet:
            matches_sheet_name = make_excel_safe_name(result.collection)
            matches_sheet = workbook.add_worksheet(matches_sheet_name)
            url = "internal:'%s'!B3" % matches_sheet_name
            sheet.write_url(row, 2, url, workbook.link_format, 'See matches')

        try:
            matches_sheet
        except NameError:
            matches_sheet = workbook.add_worksheet("All matches")

        matches_sheet = generate_matches_sheet(workbook,
                                               matches_sheet,
                                               collection,
                                               result.collection,
                                               authz,
                                               links=links,
                                               one_sheet=one_sheet,
                                               offset=offset,
                                               limit=limit)

        if one_sheet:
            if result.matches > limit:
                offset = offset + limit
            else:
                offset = offset + result.matches

    workbook.close()
    output.seek(0)
    return output