def references(self): """Reference export for single record in datatables format. :returns: list List of lists where every item represents a datatables row. A row consists of [reference_number, reference, num_citations] """ out = [] references = self.record.get('references') if references: refs_to_get_from_es = [ ref['recid'] for ref in references if ref.get('recid') ] query = IQ(' OR '.join('recid:' + str(ref) for ref in refs_to_get_from_es)) records_from_es = current_search_client.search( index='records-hep', doc_type='hep', body={"query": query.to_dict()}, size=9999, _source=[ 'control_number', 'citation_count', 'titles', 'earliest_date', 'authors', 'collaboration', 'corporate_author', 'publication_info' ] )['hits']['hits'] refs_from_es = { str(ref['_source']['control_number']): ref['_source'] for ref in records_from_es } for reference in references: row = [] recid = reference.get('recid') ref_record = refs_from_es.get(str(recid)) if recid else None if recid and ref_record: ref_record = Record(ref_record) if ref_record: row.append(render_template_to_string( "inspirehep_theme/references.html", record=ref_record, reference=reference )) row.append(ref_record.get('citation_count', '')) out.append(row) else: row.append(render_template_to_string( "inspirehep_theme/references.html", reference=reference)) row.append('') out.append(row) return out
def render_conferences(recid, conferences): """Render a list of conferences to HTML.""" out = [] for conference in conferences: if conference['control_number'] == recid: conferences.total.value = conferences.total.value - 1 continue row = [] conference_html = u'<a href="/conferences/{recid}">{title}</a>'.format( recid=conference.control_number, title=conference.titles[0].title ) row.append(conference_html) row.append(conference['addresses'][0]['original_address']) row.append('') row.append((render_template_to_string( "inspirehep_theme/conferences_in_series_date.html", record=conference.to_dict()))) out.append(row) return out, conferences.total.value
def render_conferences(recid, conferences): """Render a list of conferences to HTML.""" out = [] for conference in conferences: if conference['control_number'] == recid: conferences.total = conferences.total - 1 continue row = [] conference_html = '<a href="/conferences/{recid}">{title}</a>'.format( recid=conference.control_number, title=conference.titles[0].title ) row.append(conference_html) row.append(conference['address'][0]['original_address']) row.append('') row.append((render_template_to_string( "inspirehep_theme/conferences_in_series_date.html", record=conference.to_dict()))) out.append(row) return out, conferences.total
def get_and_format_citations(record): result = [] citations = LiteratureSearch().query( 'match', references__recid=record['control_number'], ).params( _source=[ 'citation_count', 'control_number', 'earliest_date', 'titles', ] ).execute().hits for citation in citations: citation_from_es = LiteratureSearch().get_source(citation.meta.id) row = [] row.append( render_template_to_string( 'inspirehep_theme/citations.html', record=citation_from_es, ) ) try: citation_count = citation.citation_count except AttributeError: citation_count = 0 row.append(citation_count) result.append(row) return result
def get_and_format_citations(record): """.. deprecated:: 2018-08-23""" result = [] citations = LiteratureSearch().query( 'match', references__recid=record['control_number'], ).params( _source=[ 'citation_count', 'control_number', 'earliest_date', 'titles', ] ).execute().hits for citation in citations: citation_from_es = LiteratureSearch().get_source(citation.meta.id) row = [] row.append( render_template_to_string( 'inspirehep_theme/citations.html', record=citation_from_es, ) ) try: citation_count = citation.citation_count except AttributeError: citation_count = 0 row.append(citation_count) result.append(row) return result
def citations(self): """Return citation export for single record.""" out = [] row = [] # Get citations record_citations = LiteratureSearch().query_from_iq( 'refersto:' + str(self.record['control_number'])).params(_source=[ 'control_number', 'citation_count', 'titles', 'earliest_date' ]).execute().hits for citation in record_citations: citation_from_es = LiteratureSearch().get_source(citation.meta.id) row.append( render_template_to_string("inspirehep_theme/citations.html", record=citation_from_es)) try: citation_count = citation.citation_count except AttributeError: citation_count = 0 row.append(citation_count) out.append(row) row = [] return out
def citations(self): """Return citation export for single record.""" out = [] row = [] # Get citations record_citations = LiteratureSearch().query_from_iq( 'refersto:' + str(self.record['control_number']) ).params( _source=[ 'control_number', 'citation_count', 'titles', 'earliest_date' ] ).execute().hits for citation in record_citations: citation_from_es = LiteratureSearch().get_source(citation.meta.id) row.append(render_template_to_string( "inspirehep_theme/citations.html", record=citation_from_es)) try: citation_count = citation.citation_count except AttributeError: citation_count = 0 row.append(citation_count) out.append(row) row = [] return out
def jobs_similar(id): out = '' es_query = RecordsSearch(index='records-jobs', doc_type='jobs') es_query = es_query.query( { "more_like_this": { "docs": [ { "_id": id } ], "min_term_freq": 0, "min_doc_freq": 0, } } )[0:2] similar_jobs = es_query.execute() for job in similar_jobs: out = out + (render_template_to_string( "inspirehep_theme/similar_jobs.html", record=job)) return out
def references(self): """Reference export for single record in datatables format. :returns: list List of lists where every item represents a datatables row. A row consists of [reference_number, reference, num_citations] """ out = [] references = self.record.get('references') if references: reference_recids = [ str(ref['recid']) for ref in references if ref.get('recid') ] resolved_references = get_es_records( 'lit', reference_recids, _source=[ 'control_number', 'citation_count', 'titles', 'earliest_date', 'authors', 'collaboration', 'corporate_author', 'publication_info' ] ) # Create mapping to keep reference order recid_to_reference = { ref['control_number']: ref for ref in resolved_references } for reference in references: row = [] ref_record = recid_to_reference.get( reference.get('recid'), {} ) if 'reference' in reference: reference.update(reference['reference']) del reference['reference'] if 'publication_info' in reference: reference['publication_info'] = force_list( reference['publication_info'] ) row.append(render_template_to_string( "inspirehep_theme/references.html", record=ref_record, reference=reference )) row.append(ref_record.get('citation_count', '')) out.append(row) return out
def references(self): """Reference export for single record in datatables format. :returns: list List of lists where every item represents a datatables row. A row consists of [reference_number, reference, num_citations] """ out = [] references = self.record.get('references') if references: reference_recids = [ str(ref['recid']) for ref in references if ref.get('recid') ] resolved_references = get_es_records( 'lit', reference_recids, _source=[ 'control_number', 'citation_count', 'titles', 'earliest_date', 'authors', 'collaboration', 'corporate_author', 'publication_info' ] ) # Create mapping to keep reference order recid_to_reference = { ref['control_number']: ref for ref in resolved_references } for reference in references: row = [] ref_record = recid_to_reference.get( reference.get('recid'), {} ) if 'reference' in reference: reference.update(reference['reference']) del reference['reference'] if 'publication_info' in reference: reference['publication_info'] = force_force_list( reference['publication_info'] ) row.append(render_template_to_string( "inspirehep_theme/references.html", record=ref_record, reference=reference )) row.append(ref_record.get('citation_count', '')) out.append(row) return out
def get_and_format_references(record): """Format references. .. deprecated:: 2018-06-07 """ out = [] references = record.get('references') if references: reference_recids = [ str(ref['recid']) for ref in references if ref.get('recid') ] resolved_references = get_es_records( 'lit', reference_recids, _source=[ 'authors', 'citation_count', 'collaboration', 'control_number', 'corporate_author', 'earliest_date', 'publication_info', 'titles', ] ) # Create mapping to keep reference order recid_to_reference = { ref['control_number']: ref for ref in resolved_references } for reference in references: row = [] ref_record = recid_to_reference.get( reference.get('recid'), {} ) if 'reference' in reference: reference.update(reference['reference']) del reference['reference'] if 'publication_info' in reference: reference['publication_info'] = force_list( reference['publication_info'] ) row.append(render_template_to_string( 'inspirehep_theme/references.html', record=ref_record, reference=reference )) row.append(ref_record.get('citation_count', '')) out.append(row) return out
def get_and_format_references(record): """Format references. .. deprecated:: 2018-06-07 """ out = [] references = record.get('references') if references: reference_recids = [ str(ref['recid']) for ref in references if ref.get('recid') ] resolved_references = get_es_records('lit', reference_recids, _source=[ 'authors', 'citation_count', 'collaboration', 'control_number', 'corporate_author', 'earliest_date', 'publication_info', 'titles', ]) # Create mapping to keep reference order recid_to_reference = { ref['control_number']: ref for ref in resolved_references } for reference in references: row = [] ref_record = recid_to_reference.get(reference.get('recid'), {}) if 'reference' in reference: reference.update(reference['reference']) del reference['reference'] if 'publication_info' in reference: reference['publication_info'] = force_list( reference['publication_info']) row.append( render_template_to_string('inspirehep_theme/references.html', record=ref_record, reference=reference)) row.append(ref_record.get('citation_count', '')) out.append(row) return out
def citations(self): """Return citation export for single record.""" out = [] row = [] # Get citations es_query = IQ('refersto:' + self.record['control_number']) record_citations = es.search( index='records-hep', doc_type='hep', body={"query": es_query.to_dict()}, size=10, _source=[ 'control_number', 'citation_count', 'titles', 'earliest_date' ] )['hits']['hits'] for citation in record_citations: citation_from_es = es.get_source(index='records-hep', id=citation['_id'], doc_type='hep', ignore=404) row.append(render_template_to_string( "inspirehep_theme/citations.html", record=citation_from_es)) row.append(citation.get('citation_count', '')) out.append(row) row = [] return out
def email_link(value): """Return single email rendered (mailto).""" return render_template_to_string('inspirehep_theme/format/record/field_templates/email.tpl', content=value)
def email_link(value): """Return single email rendered (mailto).""" return render_template_to_string( 'inspirehep_theme/format/record/field_templates/email.tpl', content=value)