当前位置: 首页>>代码示例>>Python>>正文


Python BibFormatObject.kb方法代码示例

本文整理汇总了Python中invenio.bibformat_engine.BibFormatObject.kb方法的典型用法代码示例。如果您正苦于以下问题:Python BibFormatObject.kb方法的具体用法?Python BibFormatObject.kb怎么用?Python BibFormatObject.kb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在invenio.bibformat_engine.BibFormatObject的用法示例。


在下文中一共展示了BibFormatObject.kb方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format_element

# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import kb [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')
#.........这里部分代码省略.........
开发者ID:AlbertoPeon,项目名称:invenio,代码行数:103,代码来源:bfe_webjournal_articles.py

示例2: format_element

# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import kb [as 别名]
def format_element(bfo, number_of_featured_articles="1",
           number_of_articles_with_image="3", new_articles_first='yes',
           image_px_width="300", small_image_px_width="200",
           subject_to_css_class_kb="WebJournalSubject2CSSClass",
           link_image_to_article='yes', image_alignment='left'):
    """
    Creates an overview of all the articles of a certain category in one
    specific issue.

    Note the following:
    <ul>
    <li>The element consider only the latest issue: when viewing
    archives of your journal, readers will see the newest articles of
    the latest issue, not the ones of the issue they are looking
    at</li>

    <li>This is not an index of the articles of the latest issue: it
    display only <b>new</b> articles, that is articles that have never
    appeared in a previous issue</li>

    <li>This element produces a table-based layout, in order to have a
    more or less readable HTML alert when sent some Email clients
    (Outlook 2007)</li>

    <li>When producing the HTML output of images, this element tries to
    insert the width and height attributes to the img tag: this is
    necessary in order to produce nice HTML alerts. This dimension
    therefore overrides any dimension defined in the CSS. The Python
    Image Library (PIL) should be installed for this element to
    recognize the size of images.</li>
    </ul>

    @param number_of_featured_articles: the max number of records with emphasized title
    @param number_of_articles_with_image: the max number of records for which their image is displayed
    @param new_articles_first: if 'yes', display new articles before other articles
    @param image_px_width: (integer) width of first image featured on this page
    @param small_image_px_width: (integer) width of small images featured on this page
    @param subject_to_css_class_kb: knowledge base that maps 595__a to a CSS class
    @param link_image_to_article: if 'yes', link image (if any) to article
    @param image_alignment: 'left', 'center' or 'right'. To help rendering in Outlook.
    """
    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)

    if image_px_width.isdigit():
        image_px_width = int(image_px_width)
    else:
        image_px_width = None
    if small_image_px_width.isdigit():
        small_image_px_width = int(small_image_px_width)
    else:
        small_image_px_width = None

    # We want to put emphasis on the n first articles (which are not
    # new)
    if number_of_featured_articles.isdigit():
        number_of_featured_articles = int(number_of_featured_articles)
    else:
        number_of_featured_articles = 0

    # Only n first articles will display images
    if number_of_articles_with_image.isdigit():
        number_of_articles_with_image = int(number_of_articles_with_image)
    else:
        number_of_articles_with_image = 0

    # Help image alignement without CSS, to have better rendering in Outlook
    img_align = ''
    if image_alignment:
        img_align = 'align="%s"' % image_alignment

    # 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

    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()
#.........这里部分代码省略.........
开发者ID:AlbertoPeon,项目名称:invenio,代码行数:103,代码来源:bfe_webjournal_articles_overview.py

示例3: format

# 需要导入模块: from invenio.bibformat_engine import BibFormatObject [as 别名]
# 或者: from invenio.bibformat_engine.BibFormatObject import kb [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')

#.........这里部分代码省略.........
开发者ID:lbjay,项目名称:cds-invenio,代码行数:103,代码来源:bfe_webjournal_sub_navigation.py


注:本文中的invenio.bibformat_engine.BibFormatObject.kb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。