Ejemplo n.º 1
0
def format_element(bfo):
    """
    Displays the latest posts on a blog and it also offers
    a link to see all the posts of the corresponding blog
    """

    this_recid = bfo.control_field('001')
    current_language = bfo.lang
    blog_posts_recids = get_posts(this_recid, newest_first=True)
    out = ""
    if blog_posts_recids:
        # let's print just the 3 latest posts
        latest_blog_posts_recids = blog_posts_recids[:3]
        try:
            out += "<h4>%s</h4>" % cfg_messages["in_issue"][current_language]
        except: # in english by default
            out += "<h4>%s</h4>" % cfg_messages["in_issue"]['en']

        for post_recid in latest_blog_posts_recids:
            out += print_record(post_recid, format='hb')
            out += "<br />"

        all_posts = ""
        all_blog_posts_recids = blog_posts_recids[3:]
        for post_recid in all_blog_posts_recids:
            all_posts += print_record(post_recid, format='hb')
            all_posts += "<br />"

        out += """
            <script type="text/javascript">
            function displayAllPosts(){
                var all_posts = document.getElementById('all_posts');
                var see_all_link = document.getElementById('see_all_link');
                if (all_posts.style.display == 'none'){
                    all_posts.style.display = '';
                    see_all_link.innerHTML = "Show less posts"
                } else {
                    all_posts.style.display = 'none';
                    see_all_link.innerHTML = "Show all posts"
                }
            }
            </script>
            """

        out += '<span id="all_posts" style="">' + all_posts + '</span>'
        out += '<a class="moreinfo" id="see_all_link" \
                href="javascript:void(0)" onclick="displayAllPosts()""></a>'
        out += '<script type="text/javascript">displayAllPosts()</script>'

    return out
Ejemplo n.º 2
0
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