Beispiel #1
0
def filter_out_based_on_date_range(recids, fromdate="", untildate="", set_spec=None):
    """ Filter out recids based on date range."""
    if fromdate:
        fromdate = normalize_date(fromdate, "T00:00:00Z")
    else:
        fromdate = get_earliest_datestamp()
    fromdate = utc_to_localtime(fromdate)

    if untildate:
        untildate = normalize_date(untildate, "T23:59:59Z")
    else:
        untildate = get_latest_datestamp()
    untildate = utc_to_localtime(untildate)

    if set_spec is not None: ## either it has a value or it empty, thus meaning all records
        last_updated = get_set_last_update(set_spec)
        if last_updated is not None:
            last_updated = utc_to_localtime(last_updated)
            if last_updated > fromdate:
                fromdate = utc_to_localtime(get_earliest_datestamp())

    recids = intbitset(recids) ## Let's clone :-)

    if fromdate and untildate:
        recids &= intbitset(run_sql("SELECT id FROM bibrec WHERE modification_date BETWEEN %s AND %s", (fromdate, untildate)))
    elif fromdate:
        recids &= intbitset(run_sql("SELECT id FROM bibrec WHERE modification_date >= %s", (fromdate, )))
    elif untildate:
        recids &= intbitset(run_sql("SELECT id FROM bibrec WHERE modification_date <= %s", (untildate, )))

    if cfg.get('CFG_OAI_FILTER_RESTRICTED_RECORDS', True):
        recids = recids - get_all_restricted_recids()

    return recids
Beispiel #2
0
def format_element(bfo,
                   only_public_records=1,
                   addthis_id=CFG_BIBFORMAT_ADDTHIS_ID):
    """Print the AddThis box from the <http://www.addthis.com/> service.

    :param only_public_records: if set to 1 (the default), prints the box only
        if the record is public (i.e. if it belongs to the root colletion and
        is accessible to the world).
    :param addthis_id: the pubid API parameter as provided by the service
        (e.g. ra-4ff80aae118f4dad). This can be set at the repository level
        in the variable CFG_BIBFORMAT_ADDTHIS_ID in invenio(-local).conf
    """
    if not addthis_id:
        return ""
    if int(only_public_records) and \
            bfo.recID not in get_all_restricted_recids():
        return ""
    return """\
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=%(addthis_id)s"></script>
<!-- AddThis Button END -->
""" % {
        'addthis_id': addthis_id
    }
Beispiel #3
0
def filter_out_based_on_date_range(recids, fromdate="", untildate="", set_spec=None):
    """ Filter out recids based on date range."""
    if fromdate:
        fromdate = normalize_date(fromdate, "T00:00:00Z")
    else:
        fromdate = get_earliest_datestamp()
    fromdate = utc_to_localtime(fromdate)

    if untildate:
        untildate = normalize_date(untildate, "T23:59:59Z")
    else:
        untildate = get_latest_datestamp()
    untildate = utc_to_localtime(untildate)

    if set_spec is not None: ## either it has a value or it empty, thus meaning all records
        last_updated = get_set_last_update(set_spec)
        if last_updated is not None:
            last_updated = utc_to_localtime(last_updated)
            if last_updated > fromdate:
                fromdate = utc_to_localtime(get_earliest_datestamp())

    recids = intbitset(recids) ## Let's clone :-)

    if fromdate and untildate:
        recids &= intbitset(run_sql("SELECT id FROM bibrec WHERE modification_date BETWEEN %s AND %s", (fromdate, untildate)))
    elif fromdate:
        recids &= intbitset(run_sql("SELECT id FROM bibrec WHERE modification_date >= %s", (fromdate, )))
    elif untildate:
        recids &= intbitset(run_sql("SELECT id FROM bibrec WHERE modification_date <= %s", (untildate, )))

    if cfg.get('CFG_OAI_FILTER_RESTRICTED_RECORDS', True):
        recids = recids - get_all_restricted_recids()

    return recids
Beispiel #4
0
def format_element(bfo, only_public_records=1,
                   addthis_id=CFG_BIBFORMAT_ADDTHIS_ID):
    """Print the AddThis box from the <http://www.addthis.com/> service.

    :param only_public_records: if set to 1 (the default), prints the box only
        if the record is public (i.e. if it belongs to the root colletion and
        is accessible to the world).
    :param addthis_id: the pubid API parameter as provided by the service
        (e.g. ra-4ff80aae118f4dad). This can be set at the repository level
        in the variable CFG_BIBFORMAT_ADDTHIS_ID in invenio(-local).conf
    """
    if not addthis_id:
        return ""
    if int(only_public_records) and \
            bfo.recID not in get_all_restricted_recids():
        return ""
    return """\
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=%(addthis_id)s"></script>
<!-- AddThis Button END -->
""" % {'addthis_id': addthis_id}
Beispiel #5
0
def oai_get_recid(identifier):
    """Returns the recid corresponding to the OAI identifier. Prefer a non deleted
    record if multiple recids matches but some of them are deleted (e.g. in
    case of merging). Returns None if no record matches."""
    if identifier:
        recids = search_pattern(p=identifier, f=CFG_OAI_ID_FIELD, m='e', ap=-9)
        if recids:
            restricted_recids = get_all_restricted_recids()
            for recid in recids:
                if record_exists(recid) > 0 and recid not in restricted_recids:
                    return recid
            if recid not in restricted_recids:
                return recid
    return None
Beispiel #6
0
def get_all_public_records(collections):
    """ Get all records which exist (i.e. not suppressed ones) and are in
    accessible collection.
    returns list of (recid, last_modification) tuples
    """
    all_restricted_recids = get_all_restricted_recids()
    recids = intbitset()
    minimum_timestamp = get_minimum_timestamp()
    for collection in collections:
        recids += get_collection_reclist(collection)
    recids = recids.difference(all_restricted_recids)
    query = "SELECT id, modification_date FROM bibrec"
    res = run_sql(query)
    return [(recid, max(lastmod, minimum_timestamp)) for (recid, lastmod) in res if recid in recids]
Beispiel #7
0
def oai_get_recid(identifier):
    """Returns the recid corresponding to the OAI identifier. Prefer a non deleted
    record if multiple recids matches but some of them are deleted (e.g. in
    case of merging). Returns None if no record matches."""
    if identifier:
        recids = search_pattern(p=identifier, f=CFG_OAI_ID_FIELD, m='e', ap=-9)
        if recids:
            restricted_recids = get_all_restricted_recids()
            for recid in recids:
                if record_exists(recid) > 0 and recid not in restricted_recids:
                    return recid
            if recid not in restricted_recids:
                return recid
    return None
Beispiel #8
0
def get_all_public_records(collections):
    """ Get all records which exist (i.e. not suppressed ones) and are in
    accessible collection.
    returns list of (recid, last_modification) tuples
    """
    all_restricted_recids = get_all_restricted_recids()
    recids = intbitset()
    minimum_timestamp = get_minimum_timestamp()
    for collection in collections:
        recids += get_collection_reclist(collection)
    recids = recids.difference(all_restricted_recids)
    query = 'SELECT id, modification_date FROM bibrec'
    res = run_sql(query)
    return [(recid, max(lastmod, minimum_timestamp)) for (recid, lastmod) in res if recid in recids]
Beispiel #9
0
def get_all_public_records_modified_last_month(collections):
    """ Get all records which exist (i.e. not suppressed ones) and are in
    accessible collection.
    returns list of (recid, last_modification) tuples
    """
    all_restricted_recids = get_all_restricted_recids()
    current_date = datetime.date.today()
    one_month_ago = current_date - datetime.timedelta(days = 31)
    recids = intbitset()
    for collection in collections:
        recids += get_collection_reclist(collection)
    recids = recids.difference(all_restricted_recids)
    query = 'SELECT id, modification_date FROM bibrec WHERE modification_date > %s'
    res = run_sql(query, (one_month_ago,))
    return [(recid, lastmod) for (recid, lastmod) in res if recid in recids]
Beispiel #10
0
def get_all_public_records_modified_last_month(collections):
    """ Get all records which exist (i.e. not suppressed ones) and are in
    accessible collection.
    returns list of (recid, last_modification) tuples
    """
    all_restricted_recids = get_all_restricted_recids()
    current_date = datetime.date.today()
    one_month_ago = current_date - datetime.timedelta(days=31)
    recids = intbitset()
    for collection in collections:
        recids += get_collection_reclist(collection)
    recids = recids.difference(all_restricted_recids)
    query = 'SELECT id, modification_date FROM bibrec WHERE modification_date > %s'
    res = run_sql(query, (one_month_ago, ))
    return [(recid, lastmod) for (recid, lastmod) in res if recid in recids]
Beispiel #11
0
def format_element(
        bfo,
        only_public_records=1,
        sites="linkedin,twitter,facebook,google,delicious,sciencewise"):
    """Return a snippet of JavaScript needed for displaying a bookmark toolbar.

    :param only_public_records: if set to 1 (the default), prints the box only
        if the record is public (i.e. if it belongs to the root colletion and
        is accessible to the world).

    :param sites: which sites to enable (default is
        'linkedin,twitter,facebook,google,delicious,sciencewise').
        This should be a comma separated list of strings.
        Valid values are available on:
            <http://keith-wood.name/bookmark.html#sites>
        Note that 'sciencewise' is an ad-hoc service that will be displayed
        only in case the record has an arXiv reportnumber and will always
        be displayed last.
    """
    if int(only_public_records) and \
            bfo.recID not in get_all_restricted_recids():
        return ""

    sitelist = sites.split(',')
    sitelist = [site.strip().lower() for site in sitelist]

    sciencewise = False
    if 'sciencewise' in sitelist:
        sciencewise = True
        sitelist.remove('sciencewise')

    sites_js = ", ".join("'%s'" % site for site in sitelist)

    title = bfo.field('245__a')
    description = bfo.field('520__a')

    sciencewise_script = ""
    if sciencewise:
        reportnumber = get_arxiv_reportnumber(bfo)
        sciencewise_url = ""
        if reportnumber:
            sciencewise_url = create_sciencewise_url(reportnumber)
        if not sciencewise_url and CFG_CERN_SITE:
            sciencewise_url = create_sciencewise_url(bfo.recID, cds=True)
        if sciencewise_url:
            sciencewise_script = """\
$.bookmark.addSite('sciencewise', 'ScienceWise.info', '%(siteurl)s/img/sciencewise.png', 'en', 'bookmark', '%(url)s');
$('#bookmark_sciencewise').bookmark({sites: ['sciencewise']});
""" % {
                'siteurl': CFG_SITE_URL,
                'url': sciencewise_url.replace("'", r"\'"),
            }

    url = '%(siteurl)s/%(record)s/%(recid)s' % \
          {'recid': bfo.recID,
           'record': CFG_SITE_RECORD,
           'siteurl': CFG_BASE_URL}

    args = parse_url_string(bfo.user_info['uri'])
    journal_name = args["journal_name"]
    if journal_name and \
       (journal_name in [info.get('journal_name', '') for info in get_journals_ids_and_names()]):
        # We are displaying a WebJournal article: URL is slightly different
        url = make_journal_url(bfo.user_info['uri'])

    return """\
<!-- JQuery Bookmark Button BEGIN -->
<div id="bookmark"></div><div id="bookmark_sciencewise"></div>
<style type="text/css">
    #bookmark_sciencewise, #bookmark { float: left; }
    #bookmark_sciencewise li { padding: 2px; width: 25px}
    #bookmark_sciencewise ul, #bookmark ul { list-style-image: none; }
</style>
<script type="text/javascript" src="%(siteurl)s/vendors/jquery.bookmark/jquery.bookmark.min.js"></script>
<style type="text/css">@import "%(siteurl)s/vendors/jquery.bookmark/jquery.bookmark.css";</style>
<script type="text/javascript">// <![CDATA[
    %(sciencewise)s
    $('#bookmark').bookmark({
        sites: [%(sites_js)s],
        icons: '%(siteurl)s/vendors/jquery.bookmark/bookmarks.png',
        url: '%(url)s',
        addEmail: true,
        title: "%(title)s",
        description: "%(description)s"
    });
// ]]>
</script>
<!-- JQuery Bookmark Button END -->
""" % {
        'siteurl':
        CFG_BASE_URL,
        'sciencewise':
        sciencewise_script,
        'title':
        escape_javascript_string(
            title, escape_for_html=False, escape_CDATA=True),
        'description':
        escape_javascript_string(
            description, escape_for_html=False, escape_CDATA=True),
        'sites_js':
        sites_js,
        'url':
        url,
    }
Beispiel #12
0
def format_element(
        bfo, only_public_records=1,
        sites="linkedin,twitter,facebook,google,delicious,sciencewise"):
    """Return a snippet of JavaScript needed for displaying a bookmark toolbar.

    :param only_public_records: if set to 1 (the default), prints the box only
        if the record is public (i.e. if it belongs to the root colletion and
        is accessible to the world).

    :param sites: which sites to enable (default is
        'linkedin,twitter,facebook,google,delicious,sciencewise').
        This should be a comma separated list of strings.
        Valid values are available on:
            <http://keith-wood.name/bookmark.html#sites>
        Note that 'sciencewise' is an ad-hoc service that will be displayed
        only in case the record has an arXiv reportnumber and will always
        be displayed last.
    """
    if int(only_public_records) and \
            bfo.recID not in get_all_restricted_recids():
        return ""

    sitelist = sites.split(',')
    sitelist = [site.strip().lower() for site in sitelist]

    sciencewise = False
    if 'sciencewise' in sitelist:
        sciencewise = True
        sitelist.remove('sciencewise')

    sites_js = ", ".join("'%s'" % site for site in sitelist)

    title = bfo.field('245__a')
    description = bfo.field('520__a')

    sciencewise_script = ""
    if sciencewise:
        reportnumber = get_arxiv_reportnumber(bfo)
        sciencewise_url = ""
        if reportnumber:
            sciencewise_url = create_sciencewise_url(reportnumber)
        if not sciencewise_url and CFG_CERN_SITE:
            sciencewise_url = create_sciencewise_url(bfo.recID, cds=True)
        if sciencewise_url:
            sciencewise_script = """\
$.bookmark.addSite('sciencewise', 'ScienceWise.info', '%(siteurl)s/img/sciencewise.png', 'en', 'bookmark', '%(url)s');
$('#bookmark_sciencewise').bookmark({sites: ['sciencewise']});
""" % {
                'siteurl': CFG_SITE_URL,
                'url': sciencewise_url.replace("'", r"\'"),
            }

    url = '%(siteurl)s/%(record)s/%(recid)s' % \
          {'recid': bfo.recID,
           'record': CFG_SITE_RECORD,
           'siteurl': CFG_BASE_URL}

    args = parse_url_string(bfo.user_info['uri'])
    journal_name = args["journal_name"]
    if journal_name and \
       (journal_name in [info.get('journal_name', '') for info in get_journals_ids_and_names()]):
        # We are displaying a WebJournal article: URL is slightly different
        url = make_journal_url(bfo.user_info['uri'])

    return """\
<!-- JQuery Bookmark Button BEGIN -->
<div id="bookmark"></div><div id="bookmark_sciencewise"></div>
<style type="text/css">
    #bookmark_sciencewise, #bookmark { float: left; }
    #bookmark_sciencewise li { padding: 2px; width: 25px}
    #bookmark_sciencewise ul, #bookmark ul { list-style-image: none; }
</style>
<script type="text/javascript" src="%(siteurl)s/vendors/jquery.bookmark/jquery.bookmark.min.js"></script>
<style type="text/css">@import "%(siteurl)s/vendors/jquery.bookmark/jquery.bookmark.css";</style>
<script type="text/javascript">// <![CDATA[
    %(sciencewise)s
    $('#bookmark').bookmark({
        sites: [%(sites_js)s],
        icons: '%(siteurl)s/vendors/jquery.bookmark/bookmarks.png',
        url: '%(url)s',
        addEmail: true,
        title: "%(title)s",
        description: "%(description)s"
    });
// ]]>
</script>
<!-- JQuery Bookmark Button END -->
""" % {
        'siteurl': CFG_BASE_URL,
        'sciencewise': sciencewise_script,
        'title': escape_javascript_string(title,
                                          escape_for_html=False,
                                          escape_CDATA=True),
        'description': escape_javascript_string(description,
                                                escape_for_html=False,
                                                escape_CDATA=True),
        'sites_js': sites_js,
        'url': url,
    }