def transient(self, data): pk = str(data.get('id')) data['links'] = { 'self': url_for('collections_api.view', id=pk), 'ui': collection_url(pk) } data['writeable'] = request.authz.can_write(pk) return data
def ingest_complete(collection, role_id=None): """Operations supposed to be performed when an ingest process completes.""" from aleph.logic.collections import collection_url # noqa role = Role.by_id(role_id) if role is not None and not collection.managed: # notify the user that their import is completed. notify_role_template(role, collection.label, 'email/ingest.html', collection=collection, url=collection_url(collection.id))
def update_permission(role, collection, read, write): """Update a roles permission to access a given collection.""" pre = Permission.by_collection_role(collection, role) post = Permission.grant(collection, role, read, write) db.session.commit() notify_role_template(role, collection.label, 'email/permission.html', url=collection_url(collection.id), pre=pre, post=post, collection=collection) return post
def format_results(alert, results): output = [] for result in results.get('hits', []): document = unpack_result(result) # generate document URL: document['url'] = document_url(document['id'], dq=alert.query_text) collection = Collection.by_id(document.pop('collection_id')) if not collection: continue document['collection'] = { 'label': collection.label, 'url': collection_url(collection.id) } # preview snippets: result['snippets'] = [] for field, snippets in result.get('highlight', {}).items(): result['snippets'].extend(snippets) output.append(document) return output
def transient(self, data): id_ = str(data.get('id')) data['$uri'] = url_for('collections_api.view', id=id_) data['$ui'] = collection_url(id_) data['$writeable'] = request.authz.can_write(id_) return data
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