diff --git a/modules/bibformat/lib/elements/bfe_meta.py b/modules/bibformat/lib/elements/bfe_meta.py index b73c618f0..11e32618f 100644 --- a/modules/bibformat/lib/elements/bfe_meta.py +++ b/modules/bibformat/lib/elements/bfe_meta.py @@ -1,93 +1,109 @@ # -*- coding: utf-8 -*- ## ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """BibFormat element - """ __revision__ = "$Id$" from invenio.bibformat_utils import parse_tag from invenio.htmlutils import create_html_tag from invenio.bibindex_engine import get_field_tags -def format_element(bfo, name, tag_name='', tag = '', respect_file_visiblity=False, escape=4): +def format_element(bfo, name, tag_name='', tag = '', respect_file_visiblity=False, author_only=True, escape=4): """Prints a custom field in a way suitable to be used in HTML META tags. In particular conforms to Google Scholar harvesting protocol as defined http://scholar.google.com/intl/en/scholar/inclusion.html @param tag_name: the name, from tag table, of the field to be exported looks initially for names prefixed by "meta-" then looks for exact name, then falls through to "tag" @param tag: the MARC tag to be exported (only if not defined by tag_name) @param name: name to be displayed in the meta headers, labelling this value @param respect_file_visiblity: check the 8564_z if we are allowed to show a file + @param author_only: as google scholar, the author field is for authors only, + not editor nor director """ # for files case, make different rule if respect_file_visiblity: values = [] visiblities = bfo.fields('8564_x', escape) files = bfo.fields('8564_u', escape) for i, file in enumerate(files): # show only public try: if visiblities[i] == 'PUBLIC': values.append(file) except KeyError: continue else: tags = [] if tag_name: # First check for special meta named tags tags = get_field_tags("meta-" + tag_name) if not tags: #then check for regular tags tags = get_field_tags(tag_name) if not tags and tag: # fall back to explicit marc tag tags = [tag] if not tags: return '' - - values = [bfo.fields(marctag,escape=escape) for marctag in tags] + + if author_only: + # author special case : + # no editor or director + values = [] + for marctag in tags: + if marctag == '700__a': + # get full data + authors_info = bfo.fields('700',escape=escape) + for author_info in authors_info: + if not author_info.has_key('e'): + values.append(author_info['a']) + else: + values.append(bfo.fields(marctag,escape=escape)) + else: + values = [bfo.fields(marctag,escape=escape) for marctag in tags] out = [] for value in values: if isinstance(value, list): for val in value: if isinstance(val, dict): out.extend(val.values()) else: out.append(val) elif isinstance(value, dict): out.extend(value.values()) else: out.append(value) out = dict(zip(out, len(out)*[''])).keys() return '\n'.join([create_html_tag('meta', name=name, content=value) for value in out]) def escape_values(bfo): """ Called by BibFormat in order to check if output of this element should be escaped. """ return 0