本文整理汇总了Python中invenio.bibformat_engine.BibFormatObject.fields方法的典型用法代码示例。如果您正苦于以下问题:Python BibFormatObject.fields方法的具体用法?Python BibFormatObject.fields怎么用?Python BibFormatObject.fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invenio.bibformat_engine.BibFormatObject
的用法示例。
在下文中一共展示了BibFormatObject.fields方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format_element
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def format_element(bfo):
"""
Creates a navigation for comments.
"""
# get variables
this_recid = bfo.control_field('001')
try:
this_content = bfo.fields('520__a')[0]
except:
return ""
try:
this_author = bfo.fields('100__a')[0]
except:
return ""
this_limit_content = get_contextual_content(this_content,
[],
max_lines=2)[0]
menu_recids = []
current_language = bfo.lang
post_recid = get_parent_post(this_recid)
menu_recids = get_comments(post_recid, newest_first=True)
try:
menu_out = '<h4>%s</h4>' % cfg_messages["in_issue"][current_language]
except:
menu_out = '<h4>%s</h4>' % cfg_messages["in_issue"]['en']
for recid in menu_recids:
if str(this_recid) == str(recid):
menu_out += '<div class="active"><div class="litem"><b>%s</b>: %s [...]</div></div>' % (this_author, this_limit_content)
else:
temp_rec = BibFormatObject(recid)
content = temp_rec.fields('520__a')[0]
limit_content = get_contextual_content(content,
[],
max_lines=1)[0]
try:
author = temp_rec.fields('100__a')[0]
except:
author = 'Anonymous'
menu_out += '<div class="litem"><a href="%s/record/%s%s"><b>%s</b>: %s [...]</a></div>' % (CFG_SITE_URL,
recid,
(bfo.lang=="fr") and "?ln=fr" or "?ln=en",
author, limit_content)
return menu_out
示例2: get_widget_html
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def get_widget_html(language, max_photos, collections, separator, ln):
"""
Returns the content of the widget
"""
latest_photo_ids = perform_request_search(c=collections,
rg=max_photos,
of='id')
images_urls = []
for recid in latest_photo_ids[:max_photos]:
try:
photo_record = BibFormatObject(recid)
except:
# todo: Exception, no photo in this selection
continue
if language == "fr":
try:
title = photo_record.fields('246_1a', escape=1)[0]
except KeyError:
title = ""
else:
try:
title = photo_record.fields('245__a', escape=1)[0]
except KeyError:
# todo: exception, picture with no title
title = ""
if CFG_CERN_SITE and photo_record.fields('8567_'):
# Get from 8567_
dfs_images = photo_record.fields('8567_')
for image_block in dfs_images:
if image_block.get("y", '') == "Icon":
if image_block.get("u", '').startswith("http://"):
images_urls.append((recid, image_block["u"], title))
break # Just one image per record
else:
# Get from 8564_
images = photo_record.fields('8564_')
for image_block in images:
if image_block.get("x", '').lower() == "icon":
if image_block.get("q", '').startswith("http://"):
images_urls.append((recid, image_block["q"], title))
break # Just one image per record
# Build output
html_out = separator.join(['<a href="%s/record/%i?ln=%s"><img class="phr" width="100" height="67" src="%s"/>%s</a>' % (CFG_SITE_URL, recid, ln, photo_url, title) for (recid, photo_url, title) in images_urls])
return html_out
示例3: format_element
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def format_element(bfo):
"""
Formats comments header using the post's name and
the date in which the comment was added
"""
this_recid = bfo.control_field('001')
post_recid = get_parent_post(this_recid)
post_rec = BibFormatObject(post_recid)
try:
post_title = post_rec.fields('245__a')[0]
except:
post_title = 'Untitled'
try:
addition_date = bfo.fields('269__c')[0]
except:
addition_date = ""
out = '<div id="top"><div id="topbanner"> </div>'
out += '<div id="mainmenu"><table width="100%">'
out += '<tr><td class="left" style = "font-size: 1em;">Go to post: <a href="%s/record/%s?%s">%s</a>' % \
(CFG_SITE_URL, post_recid, bfo.lang, post_title)
out += '<td class="right">%s</td>' % addition_date
out += '</td></tr></table></div></div>'
out += '<div id="mainphoto"></div>'
return out
示例4: _get_report_numbers
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def _get_report_numbers(record_id):
from invenio.bibformat_engine import BibFormatObject
bfo = BibFormatObject(record_id)
fields = bfo.fields('037__')
report_numbers = []
for field in fields:
if 'a' in field:
report_numbers.append(field['a'])
return report_numbers
示例5: format_element
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def format_element(bfo):
"""
Creates a navigation for articles in the same issue and category.
"""
# get variables
this_recid = bfo.control_field('001')
menu_recids = []
current_language = bfo.lang
this_title = ""
try:
this_title = bfo.fields('245__a')[0]
except:
return ""
blog_recid = get_parent_blog(this_recid)
blog_rec = BibFormatObject(blog_recid)
try:
blog_title = blog_rec.fields('245__a')[0]
except:
blog_title = 'Untitled'
menu_recids = get_posts(blog_recid, newest_first=True)
try:
menu_out = '<h4>%s</h4>' % cfg_messages["in_issue"][current_language]
except: # in english by default
menu_out = '<h4>%s</h4>' % cfg_messages["in_issue"]['en']
for recid in menu_recids:
if str(this_recid) == str(recid):
menu_out += '<div class="active"><div class="litem">%s</div></div>' % this_title
else:
temp_rec = BibFormatObject(recid)
try:
title = temp_rec.fields('245__a')[0]
except:
title = 'Untitled'
menu_out += '<div class="litem"><a href="%s/record/%s%s">%s</a></div>' % (CFG_SITE_URL,
recid,
(bfo.lang=="fr") and "?ln=fr" or "",
title)
return menu_out
示例6: schemaorg_type
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def schemaorg_type(recid=None, bfo=None):
if recid:
from invenio.bibformat_engine import BibFormatObject
bfo = BibFormatObject(recid)
if bfo:
from invenio.openaire_deposit_config import CFG_OPENAIRE_SCHEMAORG_MAP
collections = bfo.fields('980__')
for c in collections:
a = c.get('a', None)
b = c.get('b', None)
res = CFG_OPENAIRE_SCHEMAORG_MAP.get(b if b else a, None)
if res:
return res
return 'http://schema.org/CreativeWork'
示例7: get_doi_from_record
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def get_doi_from_record(recid):
"""
Given a record ID we fetch it from the DB and return
the first DOI found as specified by the config variable
CFG_APSHARVEST_RECORD_DOI_TAG.
@param recid: record id record containing a DOI
@type recid: string/int
@return: first DOI found in record
@rtype: string
"""
record = BibFormatObject(int(recid))
possible_dois = record.fields(CFG_APSHARVEST_RECORD_DOI_TAG[:-1])
for doi in possible_dois:
if '2' in doi and doi.get('2', "") == "DOI":
# Valid DOI present, add it
try:
return doi['a']
except KeyError:
continue
示例8: format_element
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
#.........这里部分代码省略.........
# Get the id list
ordered_articles = get_journal_articles(journal_name,
this_issue_number,
category_name,
newest_first=new_articles_first.lower() == 'yes')
new_articles_only = False
if ordered_articles.keys() and max(ordered_articles.keys()) < 0:
# If there are only new articles, don't bother marking them as
# new
new_articles_only = True
order_numbers = ordered_articles.keys()
order_numbers.sort()
img_css_class = "featuredImageScale"
for order_number in order_numbers:
for article_id in ordered_articles[order_number]:
# A record is considered as new if its position is
# negative and there are some non-new articles
article_is_new = (order_number < 0 and not new_articles_only)
temp_rec = BibFormatObject(article_id)
title = ''
if ln == "fr":
title = temp_rec.field('246_1a')
if title == '':
title = temp_rec.field('245__a')
else:
title = temp_rec.field('245__a')
if title == '':
title = temp_rec.field('246_1a')
# Get CSS class (if relevant)
notes = temp_rec.fields('595__a')
css_classes = [temp_rec.kb(subject_to_css_class_kb, note, None) \
for note in notes]
css_classes = [css_class for css_class in css_classes \
if css_class is not None]
if article_is_new:
css_classes.append('new')
# Maybe we want to force image to appear?
display_image_on_index = False
if 'display_image_on_index' in notes:
display_image_on_index = True
# Build generic link to this article
article_link = make_journal_url(bfo.user_info['uri'], {'recid':str(article_id),
'ln': bfo.lang})
# Build the "more" link
more_link = '''<a class="readMore" title="link to the article" href="%s"> >> </a>
''' % (article_link)
# If we should display an image along with the text,
# prepare it here
img = ''
if (number_of_articles_with_image > 0 and \
not article_is_new) or display_image_on_index:
img = _get_feature_image(temp_rec, ln)
if img != "":
# Now we will try to identify image size in order
# to resize it in the HTML for a nicer rendering
# of the HTML alert in email clients (Outlook wants
# both height and width)
示例9: format_element
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def format_element(bfo, limit, separator='; ',
extension='[...]',
print_links = "yes",
print_affiliations='no',
affiliation_prefix = ' (',
affiliation_suffix = ')',
print_affiliation_first='no',
interactive="no",
highlight="no",
affiliations_separator=" ; ",
name_last_first = "yes",
collaboration = "yes",
id_links = "no",
markup = "html",
link_extension = "no",
suffix = ''
):
"""
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 print_affiliation_first if 'yes', affiliation is printed before the author
@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'
@param affiliations_separator separates affiliation groups
@param name_last_first if yes (default) print last, first otherwise first last
@param collaboration if yes (default) uses collaboration name in place of long author list, if available
@param id_links if yes (default = no) prints link based on INSPIRE IDs if available - only used if print_links = yes
@param markup html (default) or latex controls small markup differences
@param link_extension if 'yes' link the extension to the detailed
record page
"""
from urllib import quote
from cgi import escape
import re
from invenio.messages import gettext_set_language
from invenio.config import CFG_BASE_URL, CFG_SITE_RECORD
from invenio.bibformat_engine import BibFormatObject
_ = gettext_set_language(bfo.lang) # load the right message language
#regex for parsing last and first names and initials
re_last_first = re.compile('^(?P<last>[^,]+)\s*,\s*(?P<first_names>[^\,]*)(?P<extension>\,?.*)$')
re_initials = re.compile(r'(?P<initial>\w)(\w+|\.)\s*')
re_coll = re.compile(r'\s*collaborations?', re.IGNORECASE)
bibrec_id = bfo.control_field("001")
authors = []
lastauthor = ''
# HepData and only-INSPIRE data records inherit the list of authors from the original paper
if (bfo.field("520__9") == "HEPDATA") or (bfo.field("520__9") == "INSPIRE"):
parent_recid = bfo.field("786__w")
bfo_parent = BibFormatObject(int(parent_recid))
authors = []
authors_1 = bfo_parent.fields('100__', repeatable_subfields_p=True)
authors_2 = bfo_parent.fields('700__', repeatable_subfields_p=True)
# other datasources should have a list of authors
else:
authors = []
authors_1 = bfo.fields('100__', repeatable_subfields_p=True)
authors_2 = bfo.fields('700__', repeatable_subfields_p=True)
authors.extend(authors_1)
authors.extend(authors_2)
# If there are no author check for corporate author in 110__a field
if len(authors) == 0:
authors = bfo.fields('110__', repeatable_subfields_p=True)
# For corporate authors we don't want to reverse names order
name_last_first = 'yes'
# And we don't want to create links
print_links = 'no'
# Keep real num of authors. fix + affiliations_separator.join(author['u']) + \
nb_authors = len(authors)
# Limit num of authors, so that we do not process
# the authors that will not be shown. This can only
# be done in non-interactive mode, as interactive mode
# allows to show all of them.
if limit.isdigit() and nb_authors > int(limit) \
and interactive != "yes":
if bfo.field('710g'): # check for colln note
authors = authors[:1]
else:
authors = authors[:int(limit)]
# Process authors to add link, affiliation and highlight
for author in authors:
#.........这里部分代码省略.........
示例10: format_element
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def format_element(bfo, latest_issue_only='yes', newest_articles_only='yes',
link_category_headers='yes', display_categories='', hide_when_only_new_records="no"):
"""
Display the index to the newest articles (of the latest issue, or of the displayed issue)
@param latest_issue_only: if 'yes', always display articles of the latest issue, even if viewing a past issue
@param newest_articles_only: only display new articles, not those that also appeared in previous issues
@param link_category_headers: if yes, category headers link to index page of that category
@param display_categories: comma-separated list of categories to display. If none, display all
@param hide_when_only_new_records: if 'yes' display new articles only if old articles exist in this issue
"""
args = parse_url_string(bfo.user_info['uri'])
journal_name = args["journal_name"]
ln = args["ln"]
_ = gettext_set_language(ln)
if latest_issue_only.lower() == 'yes':
issue_number = get_current_issue(bfo.lang, journal_name)
else:
issue_number = args["issue"]
# Try to get HTML from cache
if args['verbose'] == 0:
cached_html = _get_whatsNew_from_cache(journal_name, issue_number, ln)
if cached_html:
return cached_html
# No cache? Build from scratch
# 1. Get the articles
journal_categories = get_journal_categories(journal_name,
issue_number)
if display_categories:
display_categories = display_categories.lower().split(',')
journal_categories = [category for category in journal_categories \
if category.lower() in display_categories]
whats_new_articles = {}
for category in journal_categories:
whats_new_articles[category] = get_journal_articles(journal_name,
issue_number,
category,
newest_only=newest_articles_only.lower() == 'yes')
# Do we want to display new articles only if they have been added
# to an issue that contains non-new records?
if hide_when_only_new_records.lower() == "yes":
# First gather all articles in this issue
all_whats_new_articles = {}
for category in journal_categories:
all_whats_new_articles[category] = get_journal_articles(journal_name,
issue_number,
category,
newest_first=True,
newest_only=False)
# Then check if we have some articles at position > -1
has_old_articles = False
for articles in all_whats_new_articles.values():
if len([order for order in articles.keys() if order > -1]) > 0:
has_old_articles = True
break
if not has_old_articles:
# We don't have old articles? Thend don't consider any
for category in journal_categories:
whats_new_articles[category] = {}
# 2. Build the HTML
html_out = u''
html_out += _get_breaking_news(ln, journal_name)
for category in journal_categories:
articles_in_category = whats_new_articles[category]
html_articles_in_category = u""
# Generate the list of articles in this category
order_numbers = articles_in_category.keys()
order_numbers.sort()
for order in order_numbers:
articles = articles_in_category[order]
for recid in articles:
link = make_journal_url(bfo.user_info['uri'], {'journal_name': journal_name,
'issue_number': issue_number.split('/')[0],
'issue_year': issue_number.split('/')[1],
'category': category,
'recid': recid,
'ln': bfo.lang})
temp_rec = BibFormatObject(recid)
if ln == 'fr':
try:
title = temp_rec.fields('246_1a')[0]
except:
continue
else:
try:
title = temp_rec.field('245__a')
except:
continue
try:
html_articles_in_category += u'<li><a href="%s">%s</a></li>' % \
(link, title.decode('utf-8'))
except:
pass
if html_articles_in_category:
#.........这里部分代码省略.........
示例11: format_element
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def format_element(bfo, new_articles_first='yes',
subject_to_css_class_kb="WebJournalSubject2CSSClass",
display_all_category_articles='no', display_category_title='no'):
"""
List all articles one after the other, on the same page.
Similar to bfe_webjournal_articles_overview, but displays full articles.
Note that you cannot use both bfe_webjournal_articles_overview and
bfe_webjournal_articles: you have to choose one of them, as they
use the same cache location (It would also not make sense to use
both...).
@param new_articles_first: if 'yes', display new articles before other articles
@param subject_to_css_class_kb: knowledge base that maps 595__a to a CSS class
@param display_all_category_articles: if yes, display all articles, whatever category is selected
@param display_category_title: if yes, display category title (useful if display_all_category_articles is enabled)
@see: bfe_webjournal_articles_overview.py
"""
args = parse_url_string(bfo.user_info['uri'])
journal_name = args["journal_name"]
this_issue_number = args["issue"]
category_name = args["category"]
verbose = args["verbose"]
ln = bfo.lang
_ = gettext_set_language(ln)
# Try to get the page from cache. Only if issue is older or equal
# to latest release.
latest_released_issue = get_current_issue(ln, journal_name)
if verbose == 0 and not issue_is_later_than(this_issue_number,
latest_released_issue):
cached_html = get_index_page_from_cache(journal_name, category_name,
this_issue_number, ln)
if cached_html:
return cached_html
# Shall we display current category, or all?
categories = [category_name]
if display_all_category_articles.lower() == 'yes':
categories = get_journal_categories(journal_name,
this_issue_number)
out = ''
for category_name in categories:
if display_category_title.lower() == 'yes':
out += '<h2>' + _(category_name) + '</h2>'
out += '<table border="0" cellpadding="0" cellspacing="0">'
# Get the id list
ordered_articles = get_journal_articles(journal_name,
this_issue_number,
category_name,
newest_first=new_articles_first.lower() == 'yes')
new_articles_only = False
if ordered_articles.keys() and max(ordered_articles.keys()) < 0:
# If there are only new articles, don't bother marking them as
# new
new_articles_only = True
order_numbers = ordered_articles.keys()
order_numbers.sort()
for order_number in order_numbers:
for article_id in ordered_articles[order_number]:
# A record is considered as new if its position is
# negative and there are some non-new articles
article_is_new = (order_number < 0 and not new_articles_only)
temp_rec = BibFormatObject(article_id)
title = ''
if ln == "fr":
title = temp_rec.field('246_1a')
if title == '':
title = temp_rec.field('245__a')
else:
title = temp_rec.field('245__a')
if title == '':
title = temp_rec.field('246_1a')
# Get CSS class (if relevant)
notes = temp_rec.fields('595__a')
css_classes = [temp_rec.kb(subject_to_css_class_kb, note, None) \
for note in notes]
css_classes = [css_class for css_class in css_classes \
if css_class is not None]
if article_is_new:
css_classes.append('new')
# Finally create the output. Two different outputs
# depending on if we have text to display or not
text = []
if ln == "fr":
text = temp_rec.fields('590__b')
if not text or \
(len(text) == 1 and \
(text[0].strip() in ['', '<br />', '<!--HTML--><br />'])):
text = temp_rec.fields('520__b')
#.........这里部分代码省略.........
示例12: format
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def format(bfo, new_articles_first='yes',
subject_to_css_class_kb="WebJournalSubject2CSSClass",
display_all_category_articles='no'):
"""
Creates a navigation for articles in the same issue and category.
@param new_articles_first: if 'yes', display new articles before other articles
@param subject_to_css_class_kb: knowledge base that maps 595__a to a CSS class
@param display_all_category_articles: if yes, display all articles, whatever category is selected
"""
# get variables
args = parse_url_string(bfo.user_info['uri'])
this_recid = bfo.control_field('001')
this_issue_number = args["issue"]
category_name = args["category"]
journal_name = args["journal_name"]
ln = args["ln"]
_ = gettext_set_language(ln)
this_title = ""
if ln == "fr":
if bfo.fields('246_1a'):
this_title = bfo.fields('246_1a')[0]
elif bfo.fields('245__a'):
this_title = bfo.fields('245__a')[0]
else:
if bfo.fields('245__a'):
this_title = bfo.fields('245__a')[0]
elif bfo.fields('246_1a'):
this_title = bfo.fields('246_1a')[0]
journal_categories = [category_name]
if display_all_category_articles.lower() == 'yes':
# Let's retrieve all categories. Ok, we are not supposed to do
# that with that element, but if journal editor wants...
journal_categories = get_journal_categories(journal_name,
this_issue_number)
menu_out = ''
for category in journal_categories:
ordered_articles = get_journal_articles(journal_name,
this_issue_number,
category,
newest_first=new_articles_first.lower() == 'yes')
new_articles_only = False
if ordered_articles.keys() and max(ordered_articles.keys()) < 0:
# If there are only new articles, don't bother marking them as
# new
new_articles_only = True
menu_out += '<div class="subNavigationMenu">'
order_numbers = ordered_articles.keys()
order_numbers.sort()
for order_number in order_numbers:
for article_id in ordered_articles[order_number]:
# A record is considered as new if its position is
# negative and there are some non-new articles
article_is_new = (order_number < 0 and not new_articles_only)
if str(article_id) == this_recid:
# Mark as active
# Get CSS class (if relevant)
notes = bfo.fields('595__a')
css_classes = [bfo.kb(subject_to_css_class_kb, note, None) \
for note in notes]
css_classes = [css_class for css_class in css_classes \
if css_class is not None]
if article_is_new:
css_classes.append('new')
menu_out += '''<div class="active">
<div class="subNavigationMenuItem %s">%s</div></div>''' % \
(' '.join(css_classes),
this_title)
else:
temp_rec = BibFormatObject(article_id)
title = ''
if ln == "fr":
title = temp_rec.field('246_1a')
if title == '':
title = temp_rec.field('245__a')
else:
title = temp_rec.field('245__a')
if title == '':
title = temp_rec.field('246_1a')
# Get CSS class (if relevant)
notes = temp_rec.fields('595__a')
css_classes = [temp_rec.kb(subject_to_css_class_kb, note, None) \
for note in notes]
css_classes = [css_class for css_class in css_classes \
if css_class is not None]
if article_is_new:
css_classes.append('new')
#.........这里部分代码省略.........
示例13: format_element
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def format_element(bfo):
"""
Displays the description of how users should cite
any content of the archive. The citation includes:
For blogs: "title".
(record_creation_date). record_url
Retrieved from the original "original_url"
For blog posts: author. "title". Blog: "blog_title".
(record_creation_date). record_url
Retrieved from the original "original_url"
For comments: author. Blog post: "post_title".
(record_creation_date). record_url
Retrieved from the original "original_url"
"""
coll = bfo.fields('980__a')[0]
recid = bfo.control_field('001')
# let's get the fields we want to show
if coll in ["BLOGPOST", "COMMENT"]:
author = bfo.fields('100__a')[0]
try:
original_creation_date = bfo.fields('269__c')[0]
except:
original_creation_date = ""
try:
title = bfo.fields('245__a')[0]
except:
title = "Untitled"
try:
original_url = bfo.fields('520__u')[0]
except:
raise Exception("URL not found")
# creation date of a record
record_creation_date = get_creation_date(recid)
# url in the archive
record_url = CFG_SITE_URL + "/record/" + recid
if coll == "BLOGPOST":
# we will also show the blog's title of
# the corresponding blog post
blog_recid = get_parent_blog(recid)
blog_bfo = BibFormatObject(blog_recid)
try:
blog_title = blog_bfo.fields('245__a')[0]
except:
blog_title = 'Untitled'
description = """<table style="border:1px solid black;"><tr><td>\
<span><b>%s</b>. '%s'. Blog: '%s'. </br> \
(%s). <i>'%s'</i> </br> \
Retrieved from the original <i>'%s'</i><span></td></tr></table>""" \
% (author, title, blog_title, record_creation_date, record_url, original_url)
elif coll == "COMMENT":
# we will also show the post's title of
# the corresponding comment
post_recid = get_parent_post(recid)
post_bfo = BibFormatObject(post_recid)
try:
post_title = post_bfo.fields('245__a')[0]
except:
post_title = 'Untitled'
description = """<table style="border:1px solid black;"><tr><td>\
<span><b>%s. </b>Blog post: '%s'.</br> \
(%s). <i>'%s'</i> </br> \
Retrieved from the original <i>'%s'</i><span></td></tr></table>""" \
% (author, post_title, record_creation_date, record_url, original_url)
else: # coll == "BLOG"
description = """<table style="border:1px solid black;"><tr><td>\
<span>'%s' </br> \
(%s). <i>'%s'</i> </br> \
Retrieved from the original <i>'%s'</i><span></td></tr></table>""" \
% (title, record_creation_date, record_url, original_url)
out = """
<script type="text/javascript">
function displayCitationDescription(){
var description = document.getElementById('description');
var citation_link = document.getElementById('citation_link');
if (description.style.display == 'none'){
description.style.display = '';
citation_link.innerHTML = "Hide citation description"
} else {
description.style.display = 'none';
citation_link.innerHTML = "How to cite this"
}
}
</script>
"""
out += '<span id="description" style="">' + description + '</span>'
out += '<a class="moreinfo" id="citation_link" \
href="javascript:void(0)" onclick="displayCitationDescription()""></a>'
out += '<script type="text/javascript">displayCitationDescription()</script>'
#.........这里部分代码省略.........
示例14: format_marcxml_file
# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import fields [as 别名]
def format_marcxml_file(marcxml, is_file=False):
'''
Parse the given marcxml file to retreive the metadata needed by the
forward of the document to ArXiv.org
@param marcxml: marxml file that contains metadata from Invenio
@return: (dictionnary) couple of key value needed for the push
'''
#init the return tuple
marcxml_values = { 'id' : '',
'title' : '',
'summary' : '',
'contributors' : [],
'journal_refs' : [],
'report_nos' : [],
'comment' : '',
'doi' : '' }
# check if the marcxml is not empty
if marcxml == '':
marcxml_values['error'] = "MARCXML string is empty !"
return marcxml_values
#get the tag id and code from tag table
main_report_number = CFG_MARC_REPORT_NUMBER
add_report_number = CFG_MARC_ADDITIONAL_REPORT_NUMBER
main_title = CFG_MARC_TITLE
main_summary = CFG_MARC_ABSTRACT
main_author = CFG_MARC_AUTHOR_NAME
main_author_affiliation = CFG_MARC_AUTHOR_AFFILIATION
add_author = CFG_MARC_CONTRIBUTOR_NAME
add_author_affiliation = CFG_MARC_CONTRIBUTOR_AFFILIATION
main_comment = CFG_MARC_COMMENT
doi = CFG_MARC_DOI
journal_ref_code = CFG_MARC_JOURNAL_REF_CODE
journal_ref_title = CFG_MARC_JOURNAL_REF_TITLE
journal_ref_page = CFG_MARC_JOURNAL_REF_PAGE
journal_ref_year = CFG_MARC_JOURNAL_REF_YEAR
#init tmp values
contributor = {'name' : '', 'email' : '', 'affiliation' : []}
try:
bfo = BibFormatObject(recID=None, xml_record=marcxml)
except:
marcxml_values['error'] = "Unable to open marcxml file !"
return marcxml_values
marcxml_values = { 'id' : bfo.field(main_report_number),
'title' : bfo.field(main_title),
'summary' : bfo.field(main_summary),
'report_nos' : bfo.fields(add_report_number),
'contributors' : [],
'journal_refs' : [],
'comment' : bfo.field(main_comment),
'doi' : bfo.field(doi)}
authors = bfo.fields(main_author[:-1], repeatable_subfields_p=True)
for author in authors:
name = author.get(main_author[-1], [''])[0]
affiliation = author.get(main_author_affiliation[-1], [])
author = {'name': name, 'email': '', 'affiliation': affiliation}
marcxml_values['contributors'].append(author)
authors = bfo.fields(add_author[:-1], repeatable_subfields_p=True)
for author in authors:
name = author.get(add_author[-1], [''])[0]
affiliation = author.get(add_author_affiliation[-1], [])
author = {'name': name, 'email': '', 'affiliation': affiliation}
marcxml_values['contributors'].append(author)
journals = bfo.fields(journal_ref_title[:-1])
for journal in journals:
journal_title = journal.get(journal_ref_title[-1], '')
journal_page = journal.get(journal_ref_page[-1], '')
journal_code = journal.get(journal_ref_code[-1], '')
journal_year = journal.get(journal_ref_year[-1], '')
journal = "%s: %s (%s) pp. %s" % (journal_title, journal_code, journal_year, journal_page)
marcxml_values['journal_refs'].append(journal)
return marcxml_values