diff --git a/modules/bibformat/lib/elements/bfe_abstract.py b/modules/bibformat/lib/elements/bfe_abstract.py
index 09abc12b5..7f68a3d80 100644
--- a/modules/bibformat/lib/elements/bfe_abstract.py
+++ b/modules/bibformat/lib/elements/bfe_abstract.py
@@ -1,182 +1,182 @@
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 CERN.
##
## 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.
##
## 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 Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibFormat element - Prints English and French abstract.
"""
__revision__ = "$Id$"
#import cgi
from invenio import bibformat_utils
def format_element(bfo, prefix_en, prefix_fr, suffix_en, suffix_fr, limit, max_chars,
extension_en="[...] ",extension_fr="[...] ", contextual="no",
highlight='no', print_lang='en,fr', escape="3",
separator_en="
", separator_fr="
", latex_to_html='no'):
""" Prints the abstract of a record in HTML. By default prints
English and French versions.
Printed languages can be chosen with the 'print_lang' parameter.
@param prefix_en: a prefix for english abstract (printed only if english abstract exists)
@param prefix_fr: a prefix for french abstract (printed only if french abstract exists)
@param limit: the maximum number of sentences of the abstract to display (for each language)
@param max_chars: the maximum number of chars of the abstract to display (for each language)
@param extension_en: a text printed after english abstracts longer than parameter 'limit'
@param extension_fr: a text printed after french abstracts longer than parameter 'limit'
@param suffix_en: a suffix for english abstract(printed only if english abstract exists)
@param suffix_fr: a suffix for french abstract(printed only if french abstract exists)
@parmm contextual if 'yes' prints sentences the most relative to user search keyword (if limit < abstract)
@param highlight: if 'yes' highlights words from user search keyword
@param print_lang: the comma-separated list of languages to print. Now restricted to 'en' and 'fr'
@param escape: escaping method (overrides default escape parameter to not escape separators)
@param separator_en: a separator between each english abstract
@param separator_fr: a separator between each french abstract
@param latex_to_html: if 'yes', interpret as LaTeX abstract
"""
out = ''
if print_lang == 'auto':
print_lang = bfo.lang
languages = print_lang.split(',')
try:
escape_mode_int = int(escape)
except ValueError, e:
escape_mode_int = 0
abstract_en = []
abstract_fr = []
- for abstract in bfo.fields('520__'):
+ for abstract in bfo.fields('520__', escape=3):
lang = abstract.get('9', 'eng')
if lang == 'eng':
abstract_en.append(abstract.get('a', ''))
else:
abstract_fr.append(abstract.get('a', ''))
#abstract_en = bfo.fields('520__a', escape=3)
#abstract_en.extend(bfo.fields('520__b', escape=3))
abstract_en = "
".join(abstract_en)
#abstract_fr = bfo.fields('590__a', escape=3)
#abstract_fr.extend(bfo.fields('590__b', escape=3))
abstract_fr = "
".join(abstract_fr)
if contextual == 'yes' and limit != "" and \
limit.isdigit() and int(limit) > 0:
context_en = bibformat_utils.get_contextual_content(abstract_en,
bfo.search_pattern,
max_lines=int(limit))
#FIXME add something like [...] before and after
#contextual sentences when not at beginning/end of abstract
#if not abstract_en.strip().startswith(context_en[0].strip()):
# out += '[...]'
abstract_en = "
".join(context_en)
context_fr = bibformat_utils.get_contextual_content(abstract_fr,
bfo.search_pattern,
max_lines=int(limit))
abstract_fr = "
".join(context_fr)
if len(abstract_en) > 0 and 'en' in languages:
out += prefix_en
print_extension = False
if max_chars != "" and max_chars.isdigit() and \
int(max_chars) < len(abstract_en):
print_extension = True
abstract_en = abstract_en[:int(max_chars)]
if limit != "" and limit.isdigit():
s_abstract = abstract_en.split(". ") # Split around
# DOTSPACE so that we
# don't split html
# links
if int(limit) < len(s_abstract):
print_extension = True
s_abstract = s_abstract[:int(limit)]
#for sentence in s_abstract:
# out += sentence + "."
out = '. '.join(s_abstract)
# Add final dot if needed
if abstract_en.endswith('.'):
out += '.'
if print_extension:
out += " " + extension_en
else:
out += abstract_en
out += suffix_en
if len(abstract_fr) > 0 and 'fr' in languages:
out += prefix_fr
print_extension = False
if max_chars != "" and max_chars.isdigit() and \
int(max_chars) < len(abstract_fr):
print_extension = True
abstract_fr = abstract_fr[:int(max_chars)]
if limit != "" and limit.isdigit():
s_abstract = abstract_fr.split(". ") # Split around
# DOTSPACE so that we
# don't split html
# links
if int(limit) < len(s_abstract):
print_extension = True
s_abstract = s_abstract[:int(limit)]
#for sentence in s_abstract:
# out += sentence + "."
out += '. '.join(s_abstract)
# Add final dot if needed
if abstract_fr.endswith('.'):
out += '.'
if print_extension:
out += " "+extension_fr
else:
out += abstract_fr
out += suffix_fr
if highlight == 'yes':
out = bibformat_utils.highlight(out, bfo.search_pattern)
if latex_to_html == 'yes':
out = bibformat_utils.latex_to_html(out)
return out
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_abstract_export.py b/modules/bibformat/lib/elements/bfe_abstract_export.py
index e894be4a0..541ffdef5 100644
--- a/modules/bibformat/lib/elements/bfe_abstract_export.py
+++ b/modules/bibformat/lib/elements/bfe_abstract_export.py
@@ -1,153 +1,153 @@
# -*- coding: utf-8 -*-
##
## $Id: bfe_abstract.py,v 1.14 2007/07/24 10:21:28 kaplun Exp $
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 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 - Prints English and French abstract.
"""
__revision__ = "$Id: bfe_abstract.py,v 1.14 2007/07/24 10:21:28 kaplun Exp $"
#import cgi
from invenio import bibformat_utils
from urllib import quote
import re
#invalid and old import
#from invenio.bibformat_config import CFG_BIBFORMAT_HAS_MIMETEX
latex_formula_re = re.compile(r'\$(.*?)\$')
def fix_latex_formulas(text):
"""Substitute every occurency of a Latex Formula with a proper image
representing it, produce by MimeTeX."""
text=text.replace('<', '<')
text=text.replace('\$', '$')
def replace(match):
return '' % (quote(r'\small ' + match.group(1)), match.group(1))
return latex_formula_re.sub(replace, text)
def format(bfo, limit, max_chars, extension="[...] ", languages='en', latex="no"):
""" Prints the abstract of a record in HTML. By default prints English and French versions.
@param prefix_en a prefix for english abstract (printed only if english abstract exists)
@param prefix_fr a prefix for french abstract (printed only if french abstract exists)
@param limit the maximum number of sentences of the abstract to display (for each language)
@param max_chars the maximum number of chars of the abstract to display (for each language)
@param extension a text printed after abstracts longer than parameter 'limit'
@param suffix_en a suffix for english abstract(printed only if english abstract exists)
@param suffix_fr a suffix for french abstract(printed only if french abstract exists)
@parmm contextual if 'yes' prints sentences the most relative to user search keyword (if limit < abstract)
@param highlight if 'yes' highlights words from user search keyword
"""
out = ''
abstract_en = []
abstract_fr = []
- for abstract in bfo.fields('520__'):
+ for abstract in bfo.fields('520__', escape=3):
lang = abstract.get('9', 'eng')
if lang == 'eng':
abstract_en.append(abstract.get('a', ''))
else:
abstract_fr.append(abstract.get('a', ''))
#abstract_en = bfo.fields('520__a', escape=3)
#abstract_en.extend(bfo.fields('520__b', escape=3))
abstract_en = "
".join(abstract_en)
#abstract_fr = bfo.fields('590__a', escape=3)
#abstract_fr.extend(bfo.fields('590__b', escape=3))
abstract_fr = "
".join(abstract_fr)
if limit != "" and limit.isdigit() and int(limit) > 0:
context_en = bibformat_utils.get_contextual_content(abstract_en,
bfo.search_pattern,
max_lines=int(limit))
#FIXME add something like [...] before and after
#contextual sentences when not at beginning/end of abstract
#if not abstract_en.strip().startswith(context_en[0].strip()):
# out += '[...]'
abstract_en = "
".join(context_en)
context_fr = bibformat_utils.get_contextual_content(abstract_fr,
bfo.search_pattern,
max_lines=int(limit))
abstract_fr = "
".join(context_fr)
if len(abstract_en) > 0 and 'en' in languages:
print_extension = False
if max_chars != "" and max_chars.isdigit() and int(max_chars) < len(abstract_en):
print_extension = True
abstract_en = abstract_en[:int(max_chars)]
if limit != "" and limit.isdigit():
s_abstract = abstract_en.split(".")
if int(limit) < len(s_abstract):
print_extension = True
s_abstract = s_abstract[:int(limit)]
#for sentence in s_abstract:
# out += sentence + "."
out = '.'.join(s_abstract)
# Add final dot if needed
if abstract_en.endswith('.'):
out += '.'
if print_extension:
out += " " + extension
else:
out += abstract_en
if len(abstract_fr) > 0 and 'fr' in languages:
print_extension = False
if max_chars != "" and max_chars.isdigit() and \
int(max_chars) < len(abstract_fr):
print_extension = True
abstract_fr = abstract_fr[:int(max_chars)]
if limit != "" and limit.isdigit():
s_abstract = abstract_fr.split(".")
if int(limit) < len(s_abstract):
print_extension = True
s_abstract = s_abstract[:int(limit)]
#for sentence in s_abstract:
# out += sentence + "."
out = '.'.join(s_abstract)
# Add final dot if needed
if abstract_fr.endswith('.'):
out += '.'
if print_extension:
out += " "+ extension
else:
out += abstract_fr
if latex=="yes":
return fix_latex_formulas(out)
else:
return out
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_additional_report_numbers.py b/modules/bibformat/lib/elements/bfe_additional_report_numbers.py
index 85e93fb5d..130c0c311 100644
--- a/modules/bibformat/lib/elements/bfe_additional_report_numbers.py
+++ b/modules/bibformat/lib/elements/bfe_additional_report_numbers.py
@@ -1,49 +1,49 @@
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 CERN.
##
## 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.
##
## 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 Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibFormat element - Prints additional report numbers
"""
__revision__ = "$Id$"
from invenio.bibformat_elements.bfe_report_numbers import \
build_report_number_link
def format_element(bfo, limit, separator=" ", link='yes'):
"""
Prints the additional report numbers of the record
@param separator: the separator between report numbers.
@param limit: the max number of report numbers to display
@param link: if 'yes', display report number with corresponding link when possible
"""
- numbers = bfo.fields("088__a")
+ numbers = bfo.fields("088__a", escape=3)
if limit.isdigit() and int(limit) <= len(numbers):
numbers = numbers[:int(limit)]
return separator.join([build_report_number_link(report_number,
link == 'yes') \
for report_number in numbers])
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_addresses.py b/modules/bibformat/lib/elements/bfe_addresses.py
index 3044efde6..ca01b44c5 100644
--- a/modules/bibformat/lib/elements/bfe_addresses.py
+++ b/modules/bibformat/lib/elements/bfe_addresses.py
@@ -1,58 +1,58 @@
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 CERN.
##
## 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.
##
## 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 Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibFormat element - Prints list of addresses
"""
__revision__ = "$Id$"
import cgi
from urllib import quote
from invenio.config import CFG_SITE_URL
def format_element(bfo, separator="; ", print_link="yes"):
"""
Prints a list of addresses linked to this report
@param separator: the separator between addresses.
@param print_link: Links the addresses to search engine (HTML links) if 'yes'
"""
- addresses = bfo.fields('270')
+ addresses = bfo.fields('270', escape=3)
list_addresses = []
if print_link.lower() == 'yes':
for address in addresses:
list_addresses.append(''+cgi.escape(address.get('p', "")) + \
'')
list_addresses.append(cgi.escape(address.get('g', "")))
else:
for address in addresses:
list_addresses.append(cgi.escape(address.get('p', "")))
list_addresses.append(cgi.escape(address.get('g', "")))
return separator.join(list_addresses)
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_affiliation.py b/modules/bibformat/lib/elements/bfe_affiliation.py
index 3fc8f7451..a13bf0627 100644
--- a/modules/bibformat/lib/elements/bfe_affiliation.py
+++ b/modules/bibformat/lib/elements/bfe_affiliation.py
@@ -1,41 +1,41 @@
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 CERN.
##
## 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.
##
## 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 Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibFormat element - Prints affiliation
"""
__revision__ = "$Id$"
import cgi
def format_element(bfo):
"""
HTML Affiliation display
"""
- affiliations = bfo.fields('909C1u')
+ affiliations = bfo.fields('909C1u', escape=3)
if len(affiliations) > 0:
out = "
"
for affiliation in affiliations:
out += cgi.escape(affiliation) +" "
return out
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_authors.py b/modules/bibformat/lib/elements/bfe_authors.py
index 3cd737f8f..cdc46c962 100644
--- a/modules/bibformat/lib/elements/bfe_authors.py
+++ b/modules/bibformat/lib/elements/bfe_authors.py
@@ -1,255 +1,255 @@
# -*- coding: utf-8 -*-
"""BibFormat element - Prints authors"""
from cgi import escape
from urllib import quote
from invenio.config import CFG_SITE_URL
from invenio.messages import gettext_set_language
from invenio import bibformat_utils
from Infoscience.Names import InfoscienceName
def format_element(bfo, limit, separator='; ',
extension='[...]',
print_links="yes",
print_affiliations='no',
affiliation_prefix = ' (',
affiliation_suffix = ')',
interactive="no",
highlight="no"):
"""
Prints the list of authors of a record.
@param limit: the maximum number of authors to display
@param separator: the separator between authors.
@param extension: a text printed if more authors than 'limit' exist
@param print_links: if yes, prints the authors as HTML link to their publications
@param print_affiliations: if yes, make each author name followed by its affiliation
@param affiliation_prefix: prefix printed before each affiliation
@param affiliation_suffix: suffix printed after each affiliation
@param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
@param highlight: highlights authors corresponding to search query if set to 'yes'
"""
_ = gettext_set_language(bfo.lang) # load the right message language
output = []
all_authors = []
- authors_1 = bfo.fields('100__')
- authors_2 = bfo.fields('700__')
+ authors_1 = bfo.fields('100__', escape=3)
+ authors_2 = bfo.fields('700__', escape=3)
all_authors.extend(authors_1)
all_authors.extend(authors_2)
roles = {}
for author in all_authors:
if author.has_key('a') and author['a'].strip():
role = 'author'
if author.has_key('e') and author['e'].strip():
if 'ed' in author['e'].lower():
role = 'editor'
elif 'trad' in author['e'].lower():
role = 'translator'
elif 'dir' in author['e'].lower():
role = 'director'
if roles.has_key(role):
roles[role].append(author)
else:
roles[role] = [author]
if 'author' in roles.keys():
output.append(render_authors(bfo, roles['author'], limit, separator,
extension, print_links, print_affiliations,
affiliation_prefix, affiliation_suffix,
interactive, highlight, ""))
- corporates = bfo.fields('710__a')
+ corporates = bfo.fields('710__a', escape=3)
if len(corporates):
output.append(render_corporates(bfo, corporates, separator, print_links))
if 'editor' in roles.keys():
if len(roles['editor']) > 1:
prefix = _("Editors")
else:
prefix = _("Editor")
output.append(render_authors(bfo, roles['editor'], limit, separator,
extension, print_links, print_affiliations,
affiliation_prefix, affiliation_suffix,
interactive, highlight,
prefix + ": ")
)
if 'translator' in roles.keys():
output.append(render_authors(bfo, roles['translator'], limit, separator,
extension, print_links, print_affiliations,
affiliation_prefix, affiliation_suffix,
interactive, highlight,
len(roles['translator']) == 1 and _("Translators: ") or _("Translator: "))
)
if 'director' in roles.keys():
output.append(render_authors(bfo, roles['director'], limit, separator,
extension, print_links, print_affiliations,
affiliation_prefix, affiliation_suffix,
interactive, highlight,
len(roles['director']) == 1 and _("Advisor: ") or _("Advisors: "))
)
if len(output) == 0:
return ''
return '
'.join(output)
def render_authors(bfo, authors_list, limit, separator='; ', extension='[...]',
print_links="yes", print_affiliations='no',
affiliation_prefix = ' (', affiliation_suffix = ')',
interactive="no", highlight="no", prefix=""):
_ = gettext_set_language(bfo.lang)
nb_authors = len(authors_list)
for author in authors_list:
if highlight == 'yes':
author['a'] = bibformat_utils.highlight(author['a'], bfo.search_pattern)
if print_links.lower() == "yes":
author['a'] = '%s' % \
(CFG_SITE_URL, quote(author['a']), bfo.lang, escape(author['a']))
if author.has_key('u') and print_affiliations == "yes":
author['u'] = affiliation_prefix + author['u'] + affiliation_suffix
author['a'] = author.get('a', '') + author.get('u', '')
authors = []
for author in authors_list:
if author.has_key('q'):
authors.append(author['a'] + " (" + author['q'] + ")")
else:
authors.append(author['a'])
#authors = [author['a'] for author in authors_list] #James: have to put a condition to know if a q argument exist
if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
return prefix + separator.join(authors[:int(limit)]) + extension
elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
return """%s%s
%s
""" % (prefix,
separator.join(authors[:int(limit)]),
_("Show all %i authors") % nb_authors,
separator.join(authors[int(limit):]))
else:
return prefix + separator.join(authors)
def render_corporates(bfo, corporate_list, separator, print_links):
out = []
for corporate in corporate_list:
if print_links.lower() == "yes":
out.append('%s' % \
(CFG_SITE_URL, quote(corporate), bfo.lang, escape(corporate)))
else:
out.append(coporate)
return separator.join(out)
"""
authors = []
for author in all_authors:
if author.has_key('a'):
if is_part_of_something and author.has_key('e') and author['e'].strip():
# AB 2011-11-04 check for editors of the containing work, which should not appear among authors
if 'ed' in author['e'].lower():
role = 'editor'
continue
else:
authors.append(author)
else:
authors.append(author)
nb_authors = len(authors)
# Process authors to add link, highlight and format affiliation
for author in authors:
if author.has_key('a'):
if highlight == 'yes':
author['a'] = bibformat_utils.highlight(author['a'],
bfo.search_pattern)
if print_links.lower() == "yes":
author['a'] = ''+escape(author['a'])+''
if author.has_key('u'):
if print_affiliations == "yes":
author['u'] = affiliation_prefix + author['u'] + \
affiliation_suffix
# Flatten author instances
if print_affiliations == 'yes':
authors = [author.get('a', '') + author.get('u', '')
for author in authors]
else:
authors = [author.get('a', '')
for author in authors]
if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
return separator.join(authors[:int(limit)]) + extension
elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
out = '''
'''%{'show_less':_("Hide"),
'show_more':_("Show all %i authors") % nb_authors,
'extension':extension}
out += ''
out += separator.join(authors[:int(limit)])
out += '' + separator + \
separator.join(authors[int(limit):]) + ''
out += ' '
out += ' '
out += ''
return out
elif nb_authors > 0:
return separator.join(authors)
"""
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
\ No newline at end of file
diff --git a/modules/bibformat/lib/elements/bfe_authors_detailed.py b/modules/bibformat/lib/elements/bfe_authors_detailed.py
index 874471d94..42094fb62 100644
--- a/modules/bibformat/lib/elements/bfe_authors_detailed.py
+++ b/modules/bibformat/lib/elements/bfe_authors_detailed.py
@@ -1,164 +1,164 @@
# -*- coding: utf-8 -*-
##
## $Id: bfe_authors.py,v 1.16 2007/02/14 18:32:16 tibor Exp $
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 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 - Prints authors
"""
__revision__ = "$Id: bfe_authors.py,v 1.16 2007/02/14 18:32:16 tibor Exp $"
from Infoscience.Names import InfoscienceName
from urllib import quote
from invenio.config import CFG_SITE_URL
def __url_to_author(author):
if author.has_key('g') and author['g'].strip():
url = 'http://people.epfl.ch/%s' % author['g'].strip()
#else:
url = CFG_SITE_URL + '/search?f=author&p='+ quote(author['a'])
return url
def __url_to_corporate(corporate):
url = CFG_SITE_URL + '/search?f=710__a&p='+ quote(corporate)
return url
def __link(author, url):
return '%s' % (url, author)
def __span(author, author_class):
if author_class:
return '%s' % (author_class, author)
return author
def format(bfo, limit_to="", print_links="no", author_class="", separator='; '):
"""
Prints the list of authors of a record.
@param limit the maximum number of authors to display
@param separator the separator between authors.
@param extension a text printed if more authors than 'limit' exist
@param print_links if yes, prints the authors as HTML link to their publications
@param print_roles if yes, make each author name followed by its role
@param role_prefix prefix printed before each role
@param role_suffix suffix printed after each role
@param interactive if yes, enable user to show/hide authors when there are too many (html + javascript)
@param highlight highlights authors corresponding to search query if set to 'yes'
"""
print_links = (print_links == "yes")
output = []
is_part_of_something = (len(bfo.fields('773__')) > 0)
- authors = bfo.fields('700__')
+ authors = bfo.fields('700__', escape=3)
roles = {}
for author in authors:
if author.has_key('a') and author['a'].strip():
role = 'author'
if author.has_key('e') and author['e'].strip():
if 'ed' in author['e'].lower():
role = 'editor'
elif 'trad' in author['e'].lower():
role= 'translator'
elif 'dir' in author['e'].lower():
role = 'director'
if roles.has_key(role):
roles[role].append((author['a'], __url_to_author(author)))
else:
roles[role] = [(author['a'], __url_to_author(author))]
if 'author' in roles.keys():
output.append(render_authors(roles['author'], print_links, author_class))
if not is_part_of_something:
if 'editor' in roles.keys():
output.append(render_editors(roles['editor'], print_links, author_class))
if 'director' in roles.keys():
output.append(render_directors(roles['director'], print_links, author_class))
if 'translator' in roles.keys():
output.append(render_translators(roles['translator'], print_links, author_class))
- corporates = bfo.fields('710__a')
+ corporates = bfo.fields('710__a', escape=3)
if len(corporates):
output.append(render_corporates(corporates, print_links, author_class))
if len(output) == 0:
return ''
if limit_to == "author":
return output.pop()
else:
return separator.join(output)
def render_authors(authors, print_links=False, author_class="", separator=';'):
if print_links:
auts = [__span(__link(InfoscienceName(author).ieee_render(), url), author_class) for (author, url) in authors]
else:
auts = [__span(InfoscienceName(author).ieee_render(), author_class) for (author, url) in authors]
if len(auts) > 1:
return ' and '.join([', '.join(auts[0:-1]), auts[-1]])
else:
return auts[0]
def render_editors(editors, print_links=False, author_class=""):
if print_links:
eds = [__span(__link(InfoscienceName(editor).ieee_render(), url), author_class) for (editor, url) in editors]
else:
eds = [__span(InfoscienceName(editor).ieee_render(), author_class) for (editor, url) in editors]
if len(eds) > 1:
return ' and '.join([', '.join(eds[0:-1]), eds[-1]]) + ' (Eds.)'
else:
return eds[0] + ' (Ed.)'
def render_translators(translators, print_links=False, author_class=""):
if print_links:
trans = [__span(__link(InfoscienceName(translator).ieee_render(), url), author_class) for (translator, url) in translators]
else:
trans = [__span(InfoscienceName(translator).ieee_render(), author_class) for (translator, url) in translators]
if len(trans) > 1:
return ' and '.join([', '.join(trans[0:-1]), trans[-1]]) + ' (Trans.)'
else:
return trans[0] + ' (Trans.)'
def render_directors(directors, print_links=False, author_class=""):
if print_links:
dirs = [__span(__link(InfoscienceName(director).ieee_render(), url), author_class) for (director, url) in directors]
else:
dirs = [__span(InfoscienceName(director).ieee_render(), author_class) for (director, url) in directors]
if len(dirs) > 1:
return ' and '.join([', '.join(dirs[0:-1]), dirs[-1]]) + ' (Dirs.)'
else:
return dirs[0] + ' (Dir.)'
def render_corporates(corporates, print_links=False, author_class=""):
if print_links:
corps = [__span(__link(corporate, __url_to_corporate(corporate)), author_class) for corporate in corporates]
else:
corps = [__span(corporate, author_class) for corporate in corporates]
if len(corps) > 1:
return ' and '.join([', '.join(corps[0:-1]), corps[-1]])
else:
return corps[0]
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_authors_info.py b/modules/bibformat/lib/elements/bfe_authors_info.py
index 29a952889..58893be45 100644
--- a/modules/bibformat/lib/elements/bfe_authors_info.py
+++ b/modules/bibformat/lib/elements/bfe_authors_info.py
@@ -1,121 +1,121 @@
# -*- coding: utf-8 -*-
"""BibFormat element - Prints authors information
Author 1, Affiliation, [link to people], find accreditations, find publications
Accreditations:
http://accred.epfl.ch/accred/accreds.pl/viewpers?name=favre (find in accreditations)
http://accred.epfl.ch/accred/accreds.pl/viewpers?thescip=128933 (view accreditations)
"""
from cgi import escape
from urllib import quote, urlencode
from invenio.config import CFG_SITE_URL
from invenio.messages import gettext_set_language
from invenio import bibformat_utils
from Infoscience.Names import InfoscienceName
def link_accred(author, ln):
_ = gettext_set_language(ln)
sciper = author.get('g', None)
template = """
"""
if sciper:
url = 'http://accred.epfl.ch/accred/accreds.pl/viewpers?thescip=%s' % sciper
return template % (url, _("View accreditations"))
else:
name = author.get('a').split(',')[0]
url = 'http://accred.epfl.ch/accred/accreds.pl/viewpers?name=%s' % name
return template % (url, _("Lookup in accred"))
def link_people(author, ln):
_ = gettext_set_language(ln)
sciper = author.get('g', None)
template = """
"""
if sciper:
url = 'http://people.epfl.ch/%s' % sciper
return template % (url, _("People profile"))
def link_affiliations(author, ln):
affiliation = author.get('u', None)
template = '%s'
if affiliation:
params = urlencode({'p': "700__u:'%s'" % affiliation, 'ln': ln})
url = 'http://infoscience.epfl.ch/search?%s' % params
return template % (url, affiliation)
def link_publications(author, ln):
_ = gettext_set_language(ln)
name = author.get('a', None)
template = """
"""
params = urlencode({'p': name, 'f': 'author', 'ln': ln})
url = 'http://infoscience.epfl.ch/search?%s' % params
return template % (url, _("Find publications"))
def format_element(bfo):
"""
Prints the list of authors of a record.
"""
_ = gettext_set_language(bfo.lang) # load the right message language
output = []
all_authors = []
- authors_1 = bfo.fields('100__')
- authors_2 = bfo.fields('700__')
+ authors_1 = bfo.fields('100__', escape=3)
+ authors_2 = bfo.fields('700__', escape=3)
all_authors.extend(authors_1)
all_authors.extend(authors_2)
for author in all_authors:
title = '%s
' % author['a']
buttons = []
affiliation = link_affiliations(author, bfo.lang)
if affiliation:
title += '' + affiliation + ''
people = link_people(author, bfo.lang)
if people:
buttons.append(people)
buttons.append(link_accred(author, bfo.lang))
buttons.append(link_publications(author, bfo.lang))
output.append(title + '' + '\n'.join(buttons) + '
' )
return '\n'.join(['%s
' % printable for printable in output])
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_authors_short.py b/modules/bibformat/lib/elements/bfe_authors_short.py
index 3a8d9b731..957833e8a 100644
--- a/modules/bibformat/lib/elements/bfe_authors_short.py
+++ b/modules/bibformat/lib/elements/bfe_authors_short.py
@@ -1,180 +1,180 @@
"""
BibFormat element - Prints authors
"""
from urllib import quote
from Infoscience.Names import InfoscienceName
from invenio.config import CFG_SITE_URL
def __url_to_author(author):
# if author.has_key('g') and author['g'].strip():
# url = 'http://people.epfl.ch/%s' % author['g'].strip()
#else:
url = CFG_SITE_URL + '/search?f=author&p='+ quote(author['a'])
return url
def __url_to_corporate(corporate):
url = CFG_SITE_URL + '/search?f=710__a&p='+ quote(corporate)
return url
def __link(author, url):
return '%s' % (url, author)
def __span(author, author_class):
if author_class:
return '%s' % (author_class, author)
return author
def format(bfo, limit=5, extension=" et al", limit_to="", print_links="no", author_class=""):
"""
Prints the list of authors of a record.
@param limit the maximum number of authors to display
@param separator the separator between authors.
@param extension a text printed if more authors than 'limit' exist
@param print_links if yes, prints the authors as HTML link to their publications
@param print_roles if yes, make each author name followed by its role
@param role_prefix prefix printed before each role
@param role_suffix suffix printed after each role
@param interactive if yes, enable user to show/hide authors when there are too many (html + javascript)
@param highlight highlights authors corresponding to search query if set to 'yes'
"""
limit= int(limit)
print_links = (print_links == "yes")
is_part_of_something = (len(bfo.fields('773__')) > 0)
output = []
- authors = bfo.fields('700__')
+ authors = bfo.fields('700__', escape=3)
roles = {}
for author in authors:
if author.has_key('a') and author['a'].strip():
role = 'author'
if author.has_key('e') and author['e'].strip():
if 'ed' in author['e'].lower():
role = 'editor'
elif 'trad' in author['e'].lower():
role= 'translator'
elif 'dir' in author['e'].lower():
role = 'director'
if roles.has_key(role):
roles[role].append((author['a'], __url_to_author(author)))
else:
roles[role] = [(author['a'], __url_to_author(author))]
total_len = 0
if 'author' in roles.keys():
authors = roles['author']
if len(authors) > limit:
if len(authors[:limit]):
output.append(render_authors(authors[:limit], print_links, author_class))
return ', '.join(output) + extension
else:
total_len += len(authors)
output.append(render_authors(authors, print_links, author_class))
if not is_part_of_something:
if 'editor' in roles.keys():
editors = roles['editor']
if total_len + len(editors) > limit:
if len(editors[:limit - total_len]):
output.append(render_editors(editors[:limit - total_len], print_links, author_class))
return ', '.join(output) + extension
else:
total_len += len(editors)
output.append(render_editors(editors, print_links, author_class))
if 'director' in roles.keys():
directors = roles['director']
if total_len + len(directors) > limit:
if len(directors[:limit - total_len]):
output.append(render_directors(directors[:limit - total_len], print_links, author_class))
return ', '.join(output) + extension
else:
total_len += len(directors)
output.append(render_directors(directors, print_links, author_class))
if 'translator' in roles.keys():
translators = roles['translator']
if total_len + len(translators) > limit:
if len(translators[:limit - total_len]):
output.append(render_translators(translators[:limit - total_len], print_links, author_class))
return ', '.join(output) + extension
else:
total_len += len(translators)
output.append(render_translators(translators, print_links, author_class))
- corporates = bfo.fields('710__a')
+ corporates = bfo.fields('710__a', escape=3)
if len(corporates):
output.append(render_corporates(corporates, print_links, author_class))
if len(output) == 0:
return ''
if limit_to == "author":
return output[0]
else:
return ', '.join(output)
def render_authors(authors, print_links=False, author_class=""):
if print_links:
auts = [__span(__link(InfoscienceName(author).ieee_render(), url), author_class) for (author, url) in authors]
else:
auts = [__span(InfoscienceName(author).ieee_render(), author_class) for (author, url) in authors]
if len(auts) > 1:
return ' and '.join([', '.join(auts[0:-1]), auts[-1]])
else:
return auts[0]
def render_editors(editors, print_links=False, author_class=""):
if print_links:
eds = [__span(__link(InfoscienceName(editor).ieee_render(), url), author_class) for (editor, url) in editors]
else:
eds = [__span(InfoscienceName(editor).ieee_render(), author_class) for (editor, url) in editors]
if len(eds) > 1:
return ' and '.join([', '.join(eds[0:-1]), eds[-1]]) + ' (Eds.)'
else:
return eds[0] + ' (Ed.)'
def render_translators(translators, print_links=False, author_class=""):
if print_links:
trans = [__span(__link(InfoscienceName(translator).ieee_render(), url), author_class) for (translator, url) in translators]
else:
trans = [__span(InfoscienceName(translator).ieee_render(), author_class) for (translator, url) in translators]
if len(trans) > 1:
return ' and '.join([', '.join(trans[0:-1]), trans[-1]]) + ' (Trans.)'
else:
return trans[0] + ' (Trans.)'
def render_directors(directors, print_links=False, author_class=""):
if print_links:
dirs = [__span(__link(InfoscienceName(director).ieee_render(), url), author_class) for (director, url) in directors]
else:
dirs = [__span(InfoscienceName(director).ieee_render(), author_class) for (director, url) in directors]
if len(dirs) > 1:
return ' and '.join([', '.join(dirs[0:-1]), dirs[-1]]) + ' (Dirs.)'
else:
return dirs[0] + ' (Dir.)'
def render_corporates(corporates, print_links=False, author_class=""):
if print_links:
corps = [__span(__link(corporate, __url_to_corporate(corporate)), author_class) for corporate in corporates]
else:
corps = [__span(corporate, author_class) for corporate in corporates]
if len(corps) > 1:
return ' and '.join([', '.join(corps[0:-1]), corps[-1]])
else:
return corps[0]
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_award.py b/modules/bibformat/lib/elements/bfe_award.py
index 67ef406fa..798c3f44e 100644
--- a/modules/bibformat/lib/elements/bfe_award.py
+++ b/modules/bibformat/lib/elements/bfe_award.py
@@ -1,37 +1,37 @@
# -*- coding: utf-8 -*-
"""BibFormat element - Prints Award information"""
from invenio.bibknowledge import get_kb_mapping
def format(bfo):
"""
Print Award.
"""
total_output = []
- for award_field in bfo.fields('586__a'):
+ for award_field in bfo.fields('586__a', escape=3):
if award_field and award_field.strip():
if not ',' in award_field:
award_name = award_field.strip()
award_name = get_kb_mapping(kb_name='awards', key=award_name, default=award_name)
if type(award_name) == dict:
award_name = award_name['value']
total_output.append(award_name)
award_name = ','.join(award_field.split(',')[:-1])
award_year = award_field.split(',')[-1].strip()
award_name = get_kb_mapping(kb_name='awards', key=award_name, default=award_name)
if type(award_name) == dict:
award_name = award_name['value']
total_output.append('%s, %s' % (award_name, award_year))
return "
".join(total_output)
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_brief_links.py b/modules/bibformat/lib/elements/bfe_brief_links.py
index d06d6f2e4..90b853694 100644
--- a/modules/bibformat/lib/elements/bfe_brief_links.py
+++ b/modules/bibformat/lib/elements/bfe_brief_links.py
@@ -1,76 +1,76 @@
"""
BibFormat element - Prints links to detailed record, similar records and fulltext
"""
from invenio.messages import gettext_set_language
from invenio.bibformat_elements.bfe_epfl_fulltext import get_files
from invenio.access_control_engine import acc_authorize_action
def can_edit(bfo):
user_info = bfo.user_info
at_epfl = bfo.field("973__a") == 'EPFL'
thesis = bfo.field('980__a') == 'THESIS'
# EPFL Theses cannot be edited via websubmit interface.
if at_epfl and thesis:
(auth_code, auth_message) = acc_authorize_action(user_info, 'submit_thesis')
if auth_code == 0:
return True
return False
sciper = user_info.get('external_uniqueidentifier', [None])[0]
- labs = bfo.fields("909C0p")
+ labs = bfo.fields("909C0p", escape=3)
# member of labs ?
for lab in labs:
(auth_code, auth_message) = acc_authorize_action(user_info, 'submit_epfl', categ=lab)
if auth_code == 0:
return True
# author of publication ?
if sciper:
- scipers = bfo.fields('700__g')
+ scipers = bfo.fields('700__g', escape=3)
if sciper in scipers:
return True
# original submitter ?
- scipers = bfo.fields('917Z8x')
+ scipers = bfo.fields('917Z8x', escape=3)
if sciper in scipers:
return True
# admin ?
(auth_code, auth_message) = acc_authorize_action(user_info, 'submit_epfl')
if auth_code == 0:
return True
return False
def format_element(bfo):
"""
This is the format for formatting fulltext links in the mini panel.
"""
_ = gettext_set_language(bfo.lang)
links = [('/record/%s?ln=%s' % (bfo.recID, bfo.lang), _("Detailed record"))]
template = '%s'
if bfo.field("980__c") == 'HIDDEN':
return ''.join([template % link for link in links])
(main_documents, additional_documents, external_documents) = get_files(bfo)
if main_documents:
if len(main_documents) + len(additional_documents) == 1:
links.append((main_documents[0][0], _("Fulltext")))
else:
links.append(('/record/%s/files?ln=%s' % (bfo.recID, bfo.lang), _("Fulltext")))
return ''.join([template % link for link in links])
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_cited_by.py b/modules/bibformat/lib/elements/bfe_cited_by.py
index a8dea4f4e..6c07d1787 100644
--- a/modules/bibformat/lib/elements/bfe_cited_by.py
+++ b/modules/bibformat/lib/elements/bfe_cited_by.py
@@ -1,59 +1,59 @@
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 CERN.
##
## 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.
##
## 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 Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibFormat element - Prints reference to documents citing this one
"""
__revision__ = "$Id$"
import cgi
def format_element(bfo, separator='; '):
"""
Prints a list of records citing this record
@param separator: a separator between citations
"""
from urllib import quote
from invenio.config import CFG_SITE_URL
- primary_report_numbers = bfo.fields('037__a')
- additional_report_numbers = bfo.fields('088__a')
+ primary_report_numbers = bfo.fields('037__a', escape=3)
+ additional_report_numbers = bfo.fields('088__a', escape=3)
primary_citations = ['' + \
cgi.escape(report_number) + '' \
for report_number in primary_report_numbers]
additional_citations = ['' + \
cgi.escape(report_number) + '' \
for report_number in additional_report_numbers]
citations = primary_citations
citations.extend(additional_citations)
return separator.join(citations)
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_conference.py b/modules/bibformat/lib/elements/bfe_conference.py
index f95197c74..6f45e30ae 100644
--- a/modules/bibformat/lib/elements/bfe_conference.py
+++ b/modules/bibformat/lib/elements/bfe_conference.py
@@ -1,30 +1,30 @@
"""BibFormat element - Prints conference informations"""
from invenio.messages import gettext_set_language
def format(bfo, separator=', ', year="yes"):
"""
Print host (Order: Name of publisher, place of publication and date of publication).
"""
output = []
date = False
# name
if bfo.field('7112_a') and bfo.field('7112_a').strip():
- output.append(bfo.field('7112_a').strip())
+ output.append(bfo.field('7112_a', escape=3).strip())
# location
if bfo.field('7112_c') and bfo.field('7112_c').strip():
- output.append(bfo.field('7112_c').strip())
+ output.append(bfo.field('7112_c', escape=3).strip())
# date
if year == "yes" and bfo.field('7112_d') and bfo.field('7112_d').strip():
- output.append(bfo.field('7112_d'))
+ output.append(bfo.field('7112_d', escape=3))
return separator.join(output)
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
\ No newline at end of file
diff --git a/modules/bibformat/lib/elements/bfe_contact_authors.py b/modules/bibformat/lib/elements/bfe_contact_authors.py
index ac57f706c..c3c7e8988 100644
--- a/modules/bibformat/lib/elements/bfe_contact_authors.py
+++ b/modules/bibformat/lib/elements/bfe_contact_authors.py
@@ -1,28 +1,28 @@
# -*- coding: utf-8 -*-
"""BibFormat element - Prints link to EPFL authors"""
from invenio.messages import gettext_set_language
def format(bfo, ):
"""
Prints the contact informations.
Translate using given knowledge base.
TODO USE Knowledge base!!
"""
- authors = bfo.fields("700__")
+ authors = bfo.fields("700__", escape=3)
out = []
for author in authors:
name = author.get('a')
sciper = author.get('g')
if sciper:
out.append('%s' % (sciper, name))
return ''.join(['%s' % elem for elem in out])
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
\ No newline at end of file
diff --git a/modules/bibformat/lib/elements/bfe_contact_lab.py b/modules/bibformat/lib/elements/bfe_contact_lab.py
index 2df92421b..0fe2e5634 100755
--- a/modules/bibformat/lib/elements/bfe_contact_lab.py
+++ b/modules/bibformat/lib/elements/bfe_contact_lab.py
@@ -1,43 +1,43 @@
# -*- coding: utf-8 -*-
"""BibFormat element - Prints link to lab"""
from invenio.messages import gettext_set_language
def format(bfo, kb_name, kb_url):
"""
Prints the contact informations.
Translate using given knowledge base.
@param kb_name a knowledge base use to translate the lab identifier
@param kb_url a knowledge base use to translate the lab identifier
"""
- lab_identifiers = bfo.fields("909C0p")
+ lab_identifiers = bfo.fields("909C0p", escape=3)
out = []
for lab in lab_identifiers:
lab_name = bfo.kb(kb_name, lab)
lab_url = bfo.kb(kb_url, lab)
if lab_url:
out.append('%s' % (lab_url, lab_name))
else:
out.append('%s' % lab_name)
# Add the TTO if we have a patent
is_tto = False
external_ids = bfo.fields('035__a')
for field in external_ids:
if 'TTO' in field:
is_tto = True
if bfo.field('980__a') == 'PATENT' and is_tto:
out.append('Technology Transfer Office')
return ''.join(['%s' % elem for elem in out])
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_editor.py b/modules/bibformat/lib/elements/bfe_editor.py
index a2273b16c..f79ea0a20 100644
--- a/modules/bibformat/lib/elements/bfe_editor.py
+++ b/modules/bibformat/lib/elements/bfe_editor.py
@@ -1,49 +1,49 @@
# -*- coding: utf-8 -*-
##
## $Id: bfe_imprint.py,v 1.6 2007/02/14 18:32:17 tibor Exp $
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 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 - Prints editor information"""
from invenio.messages import gettext_set_language
def emphasize(text):
return '%s' % text
def format(bfo, style_status='', style_text='', separator=', '):
"""
Print host (Order: Name of publisher, place of publication and date of publication).
"""
output = []
if bfo.field('260__b') and bfo.field('260__b').strip():
- output.append(bfo.field('260__b'))
+ output.append(bfo.field('260__b', escape=3))
if bfo.field('260__a') and bfo.field('260__a').strip():
- output.append(bfo.field('260__a'))
+ output.append(bfo.field('260__a', escape=3))
# if bfo.field('260__c') and bfo.field('260__c').strip():
# output.append(bfo.field('260__c'))
return separator.join(output)
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_epfl_fulltext.py b/modules/bibformat/lib/elements/bfe_epfl_fulltext.py
index 7a59270f4..63d95ace6 100644
--- a/modules/bibformat/lib/elements/bfe_epfl_fulltext.py
+++ b/modules/bibformat/lib/elements/bfe_epfl_fulltext.py
@@ -1,303 +1,303 @@
# -*- coding: utf-8 -*-
"""
BibFormat element - Prints links to fulltext
"""
from urlparse import urlparse
from os.path import basename
import urllib
from invenio.bibdocfile import BibRecDocs, file_strip_ext
from invenio.messages import gettext_set_language
from invenio.config import CFG_SITE_URL
from invenio.access_control_engine import acc_authorize_action
traditional = [
(1024 ** 5, 'P'),
(1024 ** 4, 'T'),
(1024 ** 3, 'G'),
(1024 ** 2, 'M'),
(1024 ** 1, 'K'),
(1024 ** 0, 'B'),
]
alternative = [
(1024 ** 5, ' PiB'),
(1024 ** 4, ' TiB'),
(1024 ** 3, ' GiB'),
(1024 ** 2, ' MiB'),
(1024 ** 1, ' KiB'),
(1024 ** 0, (' byte', ' bytes')),
]
def size_to_string(bytes, system=alternative):
"""Human-readable file size."""
for factor, suffix in system:
if bytes >= factor:
break
amount = int(bytes/factor)
if isinstance(suffix, tuple):
singular, multiple = suffix
if amount == 1:
suffix = singular
else:
suffix = multiple
return str(amount) + suffix
def test():
params = {'fmt': 'order',
'nr': 3906,
'title': "Bose-Einstein condensation of microcavity polaritons",
'year': 2007,
'author': "Sarchi, Davide",
'infoscience_id': 141282,
'fulltext_name': 'EPFL_TH3906.pdf'}
return urllib.urlencode(params)
def thesis_link(bfo):
- thesis_id = bfo.field('088__a')
- thesis_title = bfo.field('245__a')
- thesis_year = bfo.field('260__c')
- thesis_author = bfo.field('700__a')
+ thesis_id = bfo.field('088__a', escape=3)
+ thesis_title = bfo.field('245__a', escape=3)
+ thesis_year = bfo.field('260__c', escape=3)
+ thesis_author = bfo.field('700__a', escape=3)
fulltext_name = 'n/a'
for url in bfo.fields("8564_u"):
(dummy, host, path, dummy, params, dummy) = urlparse(url)
filename = urllib.unquote(basename(path))
if filename.startswith('EPFL_TH'):
fulltext_name = filename
break
params = {'fmt': 'order',
'nr': thesis_id,
'title': thesis_title,
'year': thesis_year,
'author': thesis_author,
'infoscience_id': bfo.recID,}
#'fulltext_name': fulltext_name}
encoded = urllib.urlencode(params)
if bfo.lang == 'fr':
return "http://library.epfl.ch/theses/?%s" % encoded
else:
return "http://library.epfl.ch/en/theses/?%s" % encoded
def get_files(bfo):
"""
Returns the files available for the given record.
Returned structure is a tuple (parsed_urls, old_versions, additionals):
"""
_ = gettext_set_language(bfo.lang)
bibarchive = BibRecDocs(bfo.recID)
main_documents = []
additional_documents = []
external_urls = []
user_info = bfo.user_info
# before verifing access, assert that the user has a remote_ip and it is not
# an internal call
remote_ip = user_info.get('remote_ip', '')
is_thesis = bfo.field("980__a") == 'THESIS' and bfo.field("973__a") == 'EPFL'
is_published = bfo.field("973__s") == 'PUBLISHED'
# Parse URLs
urls = bfo.fields("8564_")
for complete_url in urls:
if not complete_url.has_key('u'):
continue
#remove icons
if complete_url.has_key('x') and complete_url['x'].lower() == 'icon':
continue
url = complete_url['u']
(dummy, host, path, dummy, params, dummy) = urlparse(url)
filename = urllib.unquote(basename(path))
name = file_strip_ext(filename)
format = filename[len(name):]
if format.startswith('.'):
format = format[1:]
if not url.startswith(CFG_SITE_URL) and not complete_url.get('i'): # Not a bibdoc?
descr = complete_url.get('z', 'URL')
external_urls.append((url, descr, format, 0))
else: # It's a bibdoc!
if complete_url.get('i') == 'EXTERNAL':
filename = complete_url.get('z') or basename(complete_url['u'])
if is_thesis and complete_url.get('x') == 'RESTRICTED':
if not complete_url.get('z'):
filename = _("Fulltext")
if not remote_ip:
# no real access
main_documents.append((thesis_link(bfo), filename, basename(complete_url['u']).split('.')[-1], 0))
continue
if acc_authorize_action(bfo.user_info, 'viewrestrdoc', status='RESTRICTED')[0] == 1:
# no real access
main_documents.append((thesis_link(bfo), filename, basename(complete_url['u']).split('.')[-1], 0))
continue
is_sar = 'SAR' in bfo.fields('909C0p')
if is_sar:
main_documents.append((url, _("Get the whole digitalized project"), '', 0))
continue
main_documents.append((complete_url['u'], filename,
basename(complete_url['u']).split('.')[-1], 0))
else:
# Internal
for doc in bibarchive.list_bibdocs():
size = doc.get_total_size_latest_version()
descr = doc.get_description(format)
if True in [f.fullname.startswith(filename) for f in doc.list_all_files()]:
if doc.status and doc.status.lower() == 'icon':
continue
restriction = doc.list_latest_files()[0].status
#no ip = no access, only show the public files
if not remote_ip:
if restriction not in ('LAB', 'RESTRICTED', 'PRIVATE', 'DELETED'):
if doc.get_type().lower() == 'main' :
if not descr or descr.lower() == 'n/a':
descr = name
if is_thesis:
descr = _("Fulltext")
if not url in [m_url for (m_url, m_descr, m_format, m_size) in main_documents]:
main_documents.append((url, descr, format, size))
else:
if not descr or descr.lower() == 'n/a':
descr = name
if not url in [m_url for (m_url, junk, junk, junk) in additional_documents]:
additional_documents.append((url, descr, format, size))
continue
#try:
if doc.list_latest_files()[0].is_restricted(bfo.user_info)[0] == 1:
continue
#except:
# restricted = 0
if doc.get_type().lower() == 'main' :
if not descr or descr.lower() == 'n/a':
descr = name
if is_thesis:
if restriction == 'RESTRICTED':
descr = _("EPFL intranet: Fulltext")
else:
descr = "Texte intégral / Full text"
if not url in [m_url for (m_url, m_descr, m_format, m_size) in main_documents]:
main_documents.append((url, descr, format, size))
else:
if not descr or descr.lower() == 'n/a':
descr = name
if is_thesis and restriction == 'RESTRICTED':
descr = _("EPFL intranet: %s") % descr
if not url in [m_url for (m_url, junk, junk, junk) in additional_documents]:
additional_documents.append((url, descr, format, size))
if is_thesis and not main_documents and is_published:
main_documents.append((thesis_link(bfo), _("Order free pdf"), 'pdf', 0))
return (main_documents, additional_documents, external_urls)
def format_element(bfo, style, display_fulltext="yes", display_url="no", display_replacement_text='yes'):
"""
This is the format for formatting fulltext links in the mini panel.
@param separator: the separator between urls.
@param style: CSS class of the link
@param show_icons: if 'yes', print icons for fulltexts
@param focus_on_main_file: if 'yes' and a doctype 'Main' is found,
prominently display this doctype. In that case other doctypes are
summarized with a link to the Files tab, named"Additional files".
"""
_ = gettext_set_language(bfo.lang)
out = """
"""
# Retrieve files
(main_documents, additional_documents, external_documents) = get_files(bfo)
# Prepare style
if style != "":
style = 'class="%s"' % style
tmpl = '%(filename)s (%(format)s%(size)s)'
tmpl_external = '%(description)s'
formatted = []
if display_fulltext.lower() == 'yes':
for (url, name, format, size) in main_documents:
if format.lower() == 'pdf':
class_name = 'pdf'
elif format.lower() in ['doc', 'docx']:
class_name = 'doc'
elif format.lower() in ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff', 'bmp']:
class_name = 'jpg'
elif format.lower() in ['txt', 'text', 'ps']:
class_name = 'txt'
else:
class_name = 'file'
if format and size:
formatted.append(tmpl % {'url': url, 'filename': name, 'format': format,
'size': size != 0 and ', ' + size_to_string(size) or '',
'class_name': class_name })
else:
formatted.append(tmpl_external % {'url': url, 'description': name, 'class_name': class_name })
for (url, name, format, size) in additional_documents:
if format.lower() == 'pdf':
class_name = 'pdf'
elif format.lower() in ['doc', 'docx']:
class_name = 'doc'
elif format.lower() in ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff', 'bmp']:
class_name = 'jpg'
elif format.lower() in ['txt', 'text', 'ps']:
class_name = 'txt'
else:
class_name = 'file'
if format and size:
formatted.append(tmpl % {'url': url, 'filename': name, 'format': format,
'size': size != 0 and ', ' + size_to_string(size) or '',
'class_name': class_name })
else:
formatted.append(tmpl_external % {'url': url, 'description': name, 'class_name': class_name })
doi = bfo.field('0247_a').strip()
if bfo.field("980__a") == 'THESIS' and bfo.field("973__a") == 'EPFL':
if bfo.field("973__s") != 'PUBLISHED':
formatted.append("%s" % _("Thesis submitted - Forthcoming publication"))
elif doi and doi.lower() != 'n/a':
formatted.append('%s' % (doi, _("Official version")))
if display_url.lower() == 'yes':
for (url, description, format, size) in external_documents:
if url.strip():
tmpl2 = '%(description)s: %(url)s'
formatted.append(tmpl2 % {'url': url, 'description': description })
if not len(formatted) and display_replacement_text.lower() == 'yes':
formatted.append('%s' % _("There is no available fulltext. Please contact the lab or the authors."))
if not formatted:
return ''
return out % {'style': style, 'fulltexts': '\n '.join(formatted)}
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_host.py b/modules/bibformat/lib/elements/bfe_host.py
index 15571dcf3..522030dc1 100644
--- a/modules/bibformat/lib/elements/bfe_host.py
+++ b/modules/bibformat/lib/elements/bfe_host.py
@@ -1,62 +1,62 @@
# -*- coding: utf-8 -*-
"""BibFormat element - Prints document host"""
from invenio.messages import gettext_set_language
def emphasize(text, css_class):
if css_class:
return '%s' % (css_class, text)
return text
def format(bfo, separator=', ', hostname_class="", display_label="no", display_identifiers="no", label_with_span="no"):
"""
Print host (Order: Name of publisher, place of publication and date of publication).
"""
_ = gettext_set_language(bfo.lang)
output = []
- if bfo.field('773__p') and bfo.field('773__p').strip():
- journal_name = bfo.field('773__p').strip()
+ if bfo.field('773__p') and bfo.field('773__p', escape=3).strip():
+ journal_name = bfo.field('773__p', escape=3).strip()
if display_identifiers == 'yes':
- if bfo.field('773__x'):
+ if bfo.field('773__x', escape=3):
# ISSN provided
- issn = bfo.field('773__x')
+ issn = bfo.field('773__x', escape=3)
journal_name = '%s (ISSN: %s)' % (journal_name, issn, issn)
- if bfo.field('773__z'):
+ if bfo.field('773__z', escape=3):
# ISBN provided
- journal_name = '%s (ISBN: %s)' % (journal_name, bfo.field('773__z'))
+ journal_name = '%s (ISBN: %s)' % (journal_name, bfo.field('773__z', escape=3))
status = bfo.field('973__s')
if display_label == 'yes':
if status == 'SUBMITTED':
output.append('' + _("Submitted to") + ': ' + journal_name)
elif status == 'ACCEPTED':
output.append('' + _("Accepted in") + ': ' + journal_name)
else:
output.append('' + _("Published in") + ': ' + journal_name)
else:
if status == 'SUBMITTED':
output.append((_("Submitted to")).lower() + ' ' + journal_name)
elif status == 'ACCEPTED':
output.append((_("Accepted in")).lower() + ' ' + journal_name)
else:
output.append(emphasize("in " + bfo.field('773__p').strip(), hostname_class))
if bfo.field('773__v') and bfo.field('773__v').strip():
- output.append('vol. ' + bfo.field('773__v'))
+ output.append('vol. ' + bfo.field('773__v', escape=3))
if bfo.field('773__n') and bfo.field('773__n').strip():
- output.append('num. ' + bfo.field('773__n'))
+ output.append('num. ' + bfo.field('773__n', escape=3))
if bfo.field('773__c') and bfo.field('773__c').strip():
- output.append('p. ' + bfo.field('773__c'))
+ output.append('p. ' + bfo.field('773__c', escape=3))
return separator.join(output)
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_icon.py b/modules/bibformat/lib/elements/bfe_icon.py
index 03d13cf1c..c00de7920 100644
--- a/modules/bibformat/lib/elements/bfe_icon.py
+++ b/modules/bibformat/lib/elements/bfe_icon.py
@@ -1,50 +1,50 @@
# -*- coding: utf-8 -*-
##
## $Id: bfe_fulltext.py,v 1.11 2007/07/20 12:30:27 jerome Exp $
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 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 - Prints a links to fulltext
"""
def format_element(bfo, style='record-illustration-enac'):
"""
display an icon using provided css class
@style: css class to appy
"""
img = """"""
-
+
urls = bfo.fields("8564_")
icons_urls = []
for complete_url in urls:
if not complete_url.has_key('u'):
continue
url = complete_url['u']
if not complete_url.has_key('x') or complete_url['x'].lower() != 'icon':
continue
icons_urls.append(url)
return '
'.join([img % (url, style) for url in icons_urls])
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_imprint.py b/modules/bibformat/lib/elements/bfe_imprint.py
index 3a33a6632..b063e351e 100644
--- a/modules/bibformat/lib/elements/bfe_imprint.py
+++ b/modules/bibformat/lib/elements/bfe_imprint.py
@@ -1,34 +1,34 @@
# -*- coding: utf-8 -*-
"""BibFormat element - Prints info about publisher"""
from invenio.messages import gettext_set_language
def format(bfo, separator=', ', hostname_class="", display_label="no", display_year="no", display_identifiers="no"):
"""
Print host (Order: Name of publisher, place of publication and date of publication).
"""
_ = gettext_set_language(bfo.lang)
output = ''
- year = bfo.field('260__c')
+ year = bfo.field('260__c', escape=3)
if not year:
return output
- publisher = bfo.field('260__b')
+ publisher = bfo.field('260__b', escape=3)
if publisher:
- place = bfo.field('260__a')
+ place = bfo.field('260__a', escape=3)
if place:
output = '%s: %s, %s' % (place, publisher, year)
else:
output = '%s, %s' % (publisher, year)
else:
output = '%s: %s' % (_("Publication date"), year)
return output
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_keywords.py b/modules/bibformat/lib/elements/bfe_keywords.py
index 43a2bf50a..ff0d19668 100644
--- a/modules/bibformat/lib/elements/bfe_keywords.py
+++ b/modules/bibformat/lib/elements/bfe_keywords.py
@@ -1,59 +1,59 @@
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 CERN.
##
## 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.
##
## 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 Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibFormat element - Prints keywords
"""
__revision__ = "$Id$"
import cgi
from urllib import quote
from invenio.config import CFG_SITE_URL
def format_element(bfo, keyword_prefix, keyword_suffix, separator=' ; ', link='yes'):
"""
Display keywords of the record.
@param keyword_prefix a prefix before each keyword
@param keyword_suffix a suffix after each keyword
@param separator: a separator between keywords
@param link: links the keywords if 'yes' (HTML links)
"""
- keywords = bfo.fields('6531_a')
+ keywords = bfo.fields('6531_a', escape=3)
if len(keywords) > 0:
if link == 'yes':
keywords = ['' + cgi.escape(keyword) + ''
for keyword in keywords]
else:
keywords = [cgi.escape(keyword)
for keyword in keywords]
keywords = [keyword_prefix + keyword + keyword_suffix
for keyword in keywords]
return separator.join(keywords)
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_meta.py b/modules/bibformat/lib/elements/bfe_meta.py
index 12f3585c5..c9e2a079a 100644
--- a/modules/bibformat/lib/elements/bfe_meta.py
+++ b/modules/bibformat/lib/elements/bfe_meta.py
@@ -1,125 +1,125 @@
# -*- 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, 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 = []
files = bfo.fields('8564_')
for file_dict in files:
# show only public
if file_dict.get('x'):
try:
if file_dict['x'] == 'PUBLIC':
values.append(file_dict['u'])
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 ''
# load values to be printed
values = []
for marctag in tags:
######################################
# Special cases
if marctag == '700__a' and author_only:
# authors
# no editor or director
- authors_info = bfo.fields('700',escape=escape)
+ authors_info = bfo.fields('700',escape=3)
for author_info in authors_info:
if not author_info.has_key('e'):
values.append(author_info['a'])
# doi
elif marctag == '0247_a':
# dont show anything that is not an doi
- doi_infos = bfo.fields('0247_',escape=escape)
+ doi_infos = bfo.fields('0247_',escape=3)
for doi_info in doi_infos:
if doi_info.has_key('2'):
if doi_info['2'] == 'doi':
values.append(doi_info['a'])
else:
values.append(doi_info['a'])
####
else:
- values.append(bfo.fields(marctag,escape=escape))
+ values.append(bfo.fields(marctag,escape=3))
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()
# uniquify
noDupes = []
[noDupes.append(i) for i in out if not noDupes.count(i)]
return '\n'.join([create_html_tag('meta', name=name, content=value) for value in noDupes])
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_note.py b/modules/bibformat/lib/elements/bfe_note.py
index b36eb3785..065db827b 100644
--- a/modules/bibformat/lib/elements/bfe_note.py
+++ b/modules/bibformat/lib/elements/bfe_note.py
@@ -1,25 +1,25 @@
# -*- coding: utf-8 -*-
"""BibFormat element - Prints note"""
def format(bfo):
"""
Print note.
"""
output = ''
- for note in bfo.fields('500__a'):
+ for note in bfo.fields('500__a', escape=3):
if note.strip():
output += '%s
' % note.strip()
return output
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_notes.py b/modules/bibformat/lib/elements/bfe_notes.py
index dc2bdf330..9d5ec271f 100644
--- a/modules/bibformat/lib/elements/bfe_notes.py
+++ b/modules/bibformat/lib/elements/bfe_notes.py
@@ -1,71 +1,71 @@
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 CERN.
##
## 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.
##
## 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 Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibFormat element - Prints notes
"""
__revision__ = "$Id$"
import cgi
def format_element(bfo, note_suffix, note_prefix='Note: ', separator='; '):
"""
Displays notes (various note fields)
@param note_prefix a prefix before each group of notes
@param note_suffix a suffix after each group of notes
@param separator: a separator between notes of a group
"""
notes = []
- notes_group_1 = bfo.fields('594__p')
+ notes_group_1 = bfo.fields('594__p', escape=3)
if len(notes_group_1) > 0:
notes_group_1 = separator.join(notes_group_1)
notes.append(notes_group_1)
- notes_group_2 = bfo.fields('500__a')
+ notes_group_2 = bfo.fields('500__a', escape=3)
if len(notes_group_2) > 0:
notes_group_2 = separator.join(notes_group_2)
notes.append(notes_group_2)
- notes_group_3 = bfo.fields('502__a')
- notes_group_3.extend(bfo.fields('909CCr'))
- notes_group_3.extend(bfo.fields('909CPn'))
- notes_group_3.extend(bfo.fields('711__a'))
+ notes_group_3 = bfo.fields('502__a', escape=3)
+ notes_group_3.extend(bfo.fields('909CCr', escape=3))
+ notes_group_3.extend(bfo.fields('909CPn', escape=3))
+ notes_group_3.extend(bfo.fields('711__a', escape=3))
if len(notes_group_3) > 0:
notes_group_3 = separator.join(notes_group_3)
notes.append(notes_group_3)
- notes_group_4 = bfo.fields('596__a')
+ notes_group_4 = bfo.fields('596__a', escape=3)
if len(notes_group_4) > 0:
notes_group_4 = separator.join(notes_group_4)
notes.append(notes_group_4)
if len(notes) > 0:
notes = [note_prefix + cgi.escape(x) + note_suffix
for x in notes]
return "".join(notes)
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
diff --git a/modules/bibformat/lib/elements/bfe_patent.py b/modules/bibformat/lib/elements/bfe_patent.py
index 9cb8fde5e..cba3b30e8 100644
--- a/modules/bibformat/lib/elements/bfe_patent.py
+++ b/modules/bibformat/lib/elements/bfe_patent.py
@@ -1,83 +1,83 @@
# -*- coding: utf-8 -*-
"""BibFormat element - Prints Patent Number"""
def format(bfo, short="no", add_link_to_epo=False):
"""
Print Patent information.
"""
# it may a good idea to put an information like "published or granted" like :
# if b1:
# return "Granted/Published patent"
# if a1:
# return "Pending patent"
if short != "no":
patent_to_print = ""
- patents = bfo.fields('013')
+ patents = bfo.fields('013', escape=3)
if patents:
# return only the latest
for patent in patents:
if patent.has_key('a'):
patent_to_print = patent['a']
return patent_to_print
return
url_to_espacenet = "http://worldwide.espacenet.com/searchResults?compact=false&PN=%s&ST=advanced&locale=en_EP&DB=EPODOC"
- patents = bfo.fields('013')
+ patents = bfo.fields('013', escape=3)
if bfo.lang != 'en':
patent_text = 'Numéro de brevet'
patents_text = 'Numéros de brevet'
else:
patent_text = 'Patent number'
patents_text = 'Patent numbers'
template_output_patent_nr = '%s: '
output = []
# get number with data linked
patents_nr = []
patent_priority_dates = []
outer_list = '