コード例 #1
0
    def test_format_2_passes_manually(self):
        result, needs_2nd_pass = bibformat_engine.format_record(
            recID=None, of="test6", xml_record=self.xml_text_2)
        self.assertEqual(result, "<bfe_test_6 />\n")
        self.assertEqual(needs_2nd_pass, True)

        out = bibformat_engine.format_record_2nd_pass(recID=None,
                                                      template=result)
        self.assertEqual(out, "helloworld\n")
コード例 #2
0
    def test_format_2_passes_manually(self):
        result, needs_2nd_pass = bibformat_engine.format_record(
                                                recID=None,
                                                of="test6",
                                                xml_record=self.xml_text_2)
        self.assertEqual(result, "<bfe_test_6 />\n")
        self.assertEqual(needs_2nd_pass, True)

        out = bibformat_engine.format_record_2nd_pass(recID=None,
                                                      template=result)
        self.assertEqual(out, "helloworld\n")
コード例 #3
0
ファイル: bibformat.py プロジェクト: BessemAamira/invenio
def format_record(recID, of, ln=CFG_SITE_LANG, verbose=0, search_pattern=None,
                  xml_record=None, user_info=None, on_the_fly=False,
                  save_missing=True, force_2nd_pass=False):
    """
    Returns the formatted record with id 'recID' and format 'of'

    If corresponding record does not exist for given output format,
    returns ''

    ln specifies which language is used for translations.

    verbose can be increased to display debug output.

    xml_record can be specified to ignore the recID and use the given xml
    instead.

    on_the_fly means we always generate the format, ignoring the cache.

    save_missing can be used to specify to never cache a format after it has
    been generated. By default, we have a list of cached formats and the result
    of these formats is saved in the database.

    force_2nd_pass forces the 2nd pass which is basically a second formatting.
    This is used in case a bibformat element generates new BibFormat tags
    and thus we do not detect them automatically.
    (the normal way is to use nocache="1" in a template to have it treated
     in the 2nd pass instead)

    @param recID: the id of the record to fetch
    @param of: the output format code
    @return: formatted record as String, or '' if it does not exist
    """
    out, needs_2nd_pass = bibformat_engine.format_record_1st_pass(
                                        recID=recID,
                                        of=of,
                                        ln=ln,
                                        verbose=verbose,
                                        search_pattern=search_pattern,
                                        xml_record=xml_record,
                                        user_info=user_info,
                                        on_the_fly=on_the_fly,
                                        save_missing=save_missing)
    if needs_2nd_pass or force_2nd_pass:
        out = bibformat_engine.format_record_2nd_pass(
                                    recID=recID,
                                    of=of,
                                    template=out,
                                    ln=ln,
                                    verbose=verbose,
                                    search_pattern=search_pattern,
                                    xml_record=xml_record,
                                    user_info=user_info)

    return out
コード例 #4
0
    def test_format_translations_with_2nd_pass_en(self):
        result, needs_2nd_pass = bibformat_engine.format_record(
                                                recID=None,
                                                of="test8",
                                                xml_record=self.xml_text_2,
                                                ln='en')
        self.assertEqual(result.strip(), '<lang>\n  <en>Title en</en>\n  <fr>Titre fr</fr>\n</lang>\n<bfe_test_6 />\n<input type="button" value="_(Record)_"/>')
        self.assertEqual(needs_2nd_pass, True)

        out = bibformat_engine.format_record_2nd_pass(recID=None,
                                                      template=result,
                                                      ln='en')
        self.assertEqual(out, 'Title en\nhelloworld\n<input type="button" value="Record"/>')
コード例 #5
0
    def test_format_translations_with_2nd_pass_en(self):
        result, needs_2nd_pass = bibformat_engine.format_record(
            recID=None, of="test8", xml_record=self.xml_text_2, ln='en')
        self.assertEqual(
            result.strip(),
            '<lang>\n  <en>Title en</en>\n  <fr>Titre fr</fr>\n</lang>\n<bfe_test_6 />\n<input type="button" value="_(Record)_"/>'
        )
        self.assertEqual(needs_2nd_pass, True)

        out = bibformat_engine.format_record_2nd_pass(recID=None,
                                                      template=result,
                                                      ln='en')
        self.assertEqual(
            out, 'Title en\nhelloworld\n<input type="button" value="Record"/>')
コード例 #6
0
def format_record(recID,
                  of,
                  ln=CFG_SITE_LANG,
                  verbose=0,
                  search_pattern=None,
                  xml_record=None,
                  user_info=None,
                  on_the_fly=False,
                  save_missing=True,
                  force_2nd_pass=False):
    """
    Returns the formatted record with id 'recID' and format 'of'

    If corresponding record does not exist for given output format,
    returns ''

    ln specifies which language is used for translations.

    verbose can be increased to display debug output.

    xml_record can be specified to ignore the recID and use the given xml
    instead.

    on_the_fly means we always generate the format, ignoring the cache.

    save_missing can be used to specify to never cache a format after it has
    been generated. By default, we have a list of cached formats and the result
    of these formats is saved in the database.

    force_2nd_pass forces the 2nd pass which is basically a second formatting.
    This is used in case a bibformat element generates new BibFormat tags
    and thus we do not detect them automatically.
    (the normal way is to use nocache="1" in a template to have it treated
     in the 2nd pass instead)

    @param recID: the id of the record to fetch
    @param of: the output format code
    @return: formatted record as String, or '' if it does not exist
    """
    out, needs_2nd_pass = bibformat_engine.format_record_1st_pass(
        recID=recID,
        of=of,
        ln=ln,
        verbose=verbose,
        search_pattern=search_pattern,
        xml_record=xml_record,
        user_info=user_info,
        on_the_fly=on_the_fly,
        save_missing=save_missing)
    if needs_2nd_pass or force_2nd_pass:
        out = bibformat_engine.format_record_2nd_pass(
            recID=recID,
            of=of,
            template=out,
            ln=ln,
            verbose=verbose,
            search_pattern=search_pattern,
            xml_record=xml_record,
            user_info=user_info)

    return out