Example #1
0
def format_element(bfo):
    """
    Formats posts header using the blog's name and
    the date in which the post was created
    """

    this_recid = bfo.control_field('001')

    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'

    try:
        creation_date = bfo.fields('269__c')[0]
    except:
        creation_date = ""

    out = '<div id="top"><div id="topbanner">&nbsp;</div>'
    out += '<div id="mainmenu"><table width="100%">'
    out += '<tr><td class="left" style = "font-size: 1em;">Go to blog: <a href="%s/record/%s?%s">%s</a>' % \
            (CFG_SITE_URL, blog_recid, bfo.lang, blog_title)
    out += '<td class="right">%s</td>' % creation_date
    out += '</td></tr></table></div></div>'
    out += '<div id="mainphoto"></div>'

    return out
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
def calculate_reading_similarity_list(recid, type="pageviews"):
    """Calculate reading similarity data to use in reading similarity
       boxes (``people who downloaded/viewed this file/page have also
       downloaded/viewed'').  Return list of (recid1, score1),
       (recid2,score2), ... for all recidN that were consulted by the
       same people who have also consulted RECID.  The reading
       similarity TYPE can be either `pageviews' or `downloads',
       depending whether we want to obtain page view similarity or
       download similarity.
    """
    if CFG_CERN_SITE:
        return [] # CERN hack 2009-11-23 to ease the load
    if type == "downloads":
        tablename = "rnkDOWNLOADS"
    else: # default
        tablename = "rnkPAGEVIEWS"

    # firstly compute the set of client hosts who consulted recid:
    client_host_list = run_sql("SELECT DISTINCT(client_host)" + \
                               " FROM " + tablename + \
                               " WHERE id_bibrec=%s " + \
                               " AND client_host IS NOT NULL",
                               (recid,))

    # BF: let's display blogs that were read by people who
    # also read the current recid parent blog
    from invenio.webblog_utils import get_parent_blog
    parent_blog = get_parent_blog(recid)
    res = []
    if parent_blog:
        if client_host_list != ():
            client_host_list = str(database_tuples_to_single_list(client_host_list))
            client_host_list = client_host_list.replace("L", "")
            client_host_list = client_host_list.replace("[", "")
            client_host_list = client_host_list.replace("]", "")
    
            res = run_sql("SELECT CAST(b.value AS UNSIGNED), COUNT(DISTINCT(client_host)) AS c" \
                      "  FROM rnkPAGEVIEWS v, bibrec_bib76x bb, bib76x b WHERE client_host IN (" + client_host_list + ")" + \
                      "   AND v.id_bibrec != %s" \
                      "   AND v.id_bibrec = bb.id_bibrec" \
                      "   AND bb.id_bibxxx = b.id" \
                      "   AND b.tag = '760__w'" \
                      "   AND b.value != %s" \
                      " GROUP BY b.value ORDER BY c",
                      (recid, parent_blog))

        # secondly look up all recids that were consulted by these client hosts,
        # and order them by the number of different client hosts reading them:
#        res = run_sql("SELECT id_bibrec,COUNT(DISTINCT(client_host)) AS c" \
#                      "  FROM " + tablename + \
#                      " WHERE client_host IN (" + client_host_list + ")" + \
#                      "   AND id_bibrec != %s" \
#                      " GROUP BY id_bibrec ORDER BY c DESC LIMIT 10",
#                      (recid,))

    #BF: let's group the records by blog collection
#    results = {}
#    res = list(res)
#    if get_fieldvalues(recid, '980__a')[0] == 'BLOG':
#        blog_descendants = get_blog_descendants(recid)
#        for row in res:
#            recid = row[0]
#            # recid is a post, comment or page from a different BLOG
#            if recid not in blog_descendants:
#                # let's get the blog to which belongs each record
#                parent_blog = get_parent_blog(recid)
#                if parent_blog not in results:
#                    results.update([(parent_blog, row[1])])
#                else:
#                    results.update([(parent_blog, results[parent_blog] + 1)])
#
#        res = results.items()

    return res
Example #4
0
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>'

    return out