|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +## |
| 3 | +## This file is part of INSPIRE. |
| 4 | +## Copyright (C) 2015 CERN. |
| 5 | +## |
| 6 | +## INSPIRE is free software; you can redistribute it and/or |
| 7 | +## modify it under the terms of the GNU General Public License as |
| 8 | +## published by the Free Software Foundation; either version 2 of the |
| 9 | +## License, or (at your option) any later version. |
| 10 | +## |
| 11 | +## INSPIRE is distributed in the hope that it will be useful, but |
| 12 | +## WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | +## General Public License for more details. |
| 15 | +## |
| 16 | +## You should have received a copy of the GNU General Public License |
| 17 | +## along with INSPIRE; if not, write to the Free Software Foundation, Inc., |
| 18 | +## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
| 19 | + |
| 20 | +"""Return the list of the latest 1000 created profiles""" |
| 21 | + |
| 22 | +from cgi import escape |
| 23 | + |
| 24 | +from invenio.config import CFG_SITE_URL |
| 25 | +from invenio.webpage import page |
| 26 | +from invenio.urlutils import wash_url_argument |
| 27 | +from invenio.search_engine import perform_request_search, get_record |
| 28 | +from invenio.bibrecord import record_get_field_instances, field_get_subfield_instances |
| 29 | + |
| 30 | +def index(req, p=""): |
| 31 | + """ |
| 32 | + Return an id-ordered list of citation log entries of at most 10000 |
| 33 | + rows. |
| 34 | + """ |
| 35 | + if not p: |
| 36 | + p = "" |
| 37 | + |
| 38 | + def get_author_name(record): |
| 39 | + for field in record_get_field_instances(record, '100'): |
| 40 | + subfields = dict(field_get_subfield_instances(field)) |
| 41 | + if 'a' in subfields: |
| 42 | + return subfields['a'] |
| 43 | + return '' |
| 44 | + |
| 45 | + def get_bai(record): |
| 46 | + for field in record_get_field_instances(record, '035'): |
| 47 | + subfields = dict(field_get_subfield_instances(field)) |
| 48 | + if subfields.get('9').upper() == 'BAI': |
| 49 | + return subfields.get('a', '') |
| 50 | + return '' |
| 51 | + |
| 52 | + body = ['<form>Search query: <input name="p" value="%s" type="text" /><input type="submit" /></form><ol>' % escape(p, True)] |
| 53 | + |
| 54 | + recids = perform_request_search(req=req, p=p, cc="HepNames", sf="exactfirstauthor", so="a") |
| 55 | + for recid in recids: |
| 56 | + record = get_record(recid) |
| 57 | + author_name = get_author_name(record) |
| 58 | + bai = get_bai(record) |
| 59 | + body.append('<li><a href="%(siteurl)s/record/%(recid)s">%(author_name)s</a> -> <a href="%(siteurl)s/author/profile/%(bai)s">%(bai)s</a></li>' % { |
| 60 | + 'siteurl': escape(CFG_SITE_URL, True), |
| 61 | + 'recid': recid, |
| 62 | + 'author_name': escape(author_name, True), |
| 63 | + 'bai': escape(bai, True)}) |
| 64 | + body.append("</ol>") |
| 65 | + body = '\n'.join(body) |
| 66 | + |
| 67 | + return page(req=req, body=body, title="HepNames and BAIs for %s" % escape(p, True)) |
0 commit comments