示例#1
0
 def _bfe_element(bfo, **kwargs):
     # convert to utf-8 for legacy app
     kwargs = dict((k, v.encode('utf-8') if isinstance(v, unicode) else v)
                   for k, v in kwargs.iteritems())
     format_element = get_format_element(name)
     (out, dummy) = eval_format_element(format_element,
                                        bfo,
                                        kwargs)
     # returns unicode for jinja2
     return out.decode('utf-8')
def format_element(bfo, pubnotestyle="eu", pubnotemark="html", pubnotepre=" ", pubnotesuf=" ", pubnotesep=", ",
                        arxivlinks="yes", arxivcategory="yes", arxivprepubnote="<br />", arxivsufpubnote="<br />", arxivprenopub="<br />", arxivsufnopub="<br />",
                        reportpre="", reportsuf="", reportlimit="1", reportsep='', reportext=''):
    """Aggregates pubnote, arxive, and %% CITATION %% display"""
    out       = ''
    pubnote   = ''
    pubnote_w = ''
    arxiv     = ''
    arxiv_w   = ''
    doi       = ''
    doi_w     = ''
    repno     = ''
    repno_w   = ''
    pcnt_pre  = arxivprenopub + "%%CITATION = "
    pcnt_suf  = ';%%'

    # Get the pubnote, if any
    pubnote = eval_format_element(pubnoteFE, bfo, {'style': pubnotestyle, 'markup': pubnotemark, 'separator': pubnotesep })[0]
    pubnote_w = wrap(pubnote, pubnotepre, pubnotesuf)

    # Get the arxiv number, surrounding it differently if there is or isn't a pubnote
    arxiv = eval_format_element(arxivFE, bfo, {'links': arxivlinks, 'category': arxivcategory })[0]
    if pubnote:
        arxiv_w = wrap(arxiv, arxivprepubnote, arxivsufpubnote)
    else:
        arxiv_w = wrap(arxiv, arxivprenopub, arxivsufnopub)

    doi = eval_format_element(doiFE, bfo)[0]
    doi_w = wrap(doi, pubnotepre + "doi:", pubnotesuf)

    # Get the report number, if there's no pubnote or arxiv number or doi
    if pubnote or arxiv or doi:
        out = pubnote_w + doi_w + arxiv_w
    else:
        repno   = bfe_report_numbers.get_report_numbers_formatted(bfo, reportsep, reportlimit, reportext)
        repno_w = wrap(repno, reportpre, reportsuf)
        out     = repno_w

    # Get the %%CITATION line last
    out += get_cite_line(arxiv, doi, pubnote, repno, bfo, pcnt_pre, pcnt_suf)
    return out
 def call_function(self, function_name, parameters=None):
     '''
     Call an external element which is a Python file, using BibFormat
     @param function_name: the name of the function to call
     @param parameters: a dictionary of the parameters to pass as key=value pairs
     @return: a string value, which is the result of the function call
     '''
     if parameters is None:
         parameters = {}
     bfo = BibFormatObject(self.recID)
     format_element = get_format_element(function_name)
     (value, errors) = eval_format_element(format_element, bfo, parameters)
     #to do: check errors from function call
     return value
示例#4
0
 def call_function(self, function_name, parameters=None):
     '''
     Call an external element which is a Python file, using BibFormat
     @param function_name: the name of the function to call
     @param parameters: a dictionary of the parameters to pass as key=value pairs
     @return: a string value, which is the result of the function call
     '''
     if parameters is None:
         parameters = {}
     bfo = BibFormatObject(self.recID)
     format_element = get_format_element(function_name)
     (value, errors) = eval_format_element(format_element, bfo, parameters)
     #to do: check errors from function call
     return value
def format_element(bfo, pubnotestyle="eu", pubnotemark="html", pubnotepre="&nbsp;", pubnotesuf="&nbsp;", pubnotesep=", ", 
                        arxivlinks="yes", arxivcategory="yes", arxivprepubnote="<br />", arxivsufpubnote="<br />", arxivprenopub="<br />", arxivsufnopub="<br />",
                        reportpre="", reportsuf="", reportlimit="1", reportsep='', reportext=''):
    """Aggregates pubnote, arxive, and %% CITATION %% display"""
    out       = ''
    pubnote   = ''
    pubnote_w = ''
    arxiv     = ''
    arxiv_w   = ''
    repno     = ''
    repno_w   = ''
    pcnt_pre  = arxivprenopub + "%%CITATION = "
    pcnt_suf  = ';%%'

    # Get the pubnote, if any
    pubnote = eval_format_element(pubnoteFE, bfo, {'style': pubnotestyle, 'markup': pubnotemark, 'separator': pubnotesep })[0]
    pubnote_w = wrap(pubnote, pubnotepre, pubnotesuf)

    # Get the arxiv number, surrounding it differently if there is or isn't a pubnote
    arxiv = eval_format_element(arxivFE, bfo, {'links': arxivlinks, 'category': arxivcategory })[0]
    if pubnote:
        arxiv_w = wrap(arxiv, arxivprepubnote, arxivsufpubnote)
    else:
        arxiv_w = wrap(arxiv, arxivprenopub, arxivsufnopub)

    # Get the report number, if there's no pubnote or arxiv number
    if pubnote or arxiv:
        out = pubnote_w + arxiv_w
    else:
        repno   = bfe_report_numbers.get_report_numbers_formatted(bfo, reportsep, reportlimit, reportext)
        repno_w = wrap(repno, reportpre, reportsuf)
        out     = repno_w

    # Get the %%CITATION line last
    out += get_cite_line(arxiv, pubnote, repno, bfo, pcnt_pre, pcnt_suf)
    return out