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, )))
    return recids - get_all_restricted_recids()
def filter_out_based_on_date_range(recids, fromdate="", untildate=""):
    """ 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)

    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, )))
    return recids - get_all_restricted_recids()
def oaigetsysnolist(set="", fromdate="", untildate=""):
    "Returns list of system numbers for the OAI set 'set', modified from 'fromdate' until 'untildate'."
    from invenio.oai_repository_updater import get_set_definitions

    if fromdate != "":
        fromdate = normalize_date(fromdate, "T00:00:00Z")
    else:
        fromdate = get_earliest_datestamp()

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

    collections = []
    for set_definition in get_set_definitions(set):
        collections.extend(coll.strip() for coll in set_definition['c'].split(','))
    recids = perform_request_search(f1=CFG_OAI_ID_FIELD, p1="oai:*", m1="e", op1='a',
                                    f2=((set and CFG_OAI_SET_FIELD) or ""), p2=set, m2="e",
                                    d1=utc_to_localtime(fromdate),
                                    d2=utc_to_localtime(untildate),
                                    c=collections,
                                    dt='m',
                                    ap=0)
    ## Let's discard non public records
    return list(intbitset(recids) - get_all_restricted_recids())
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')
        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
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]
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')
        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 #7
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]
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 #9
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 #10
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, )))
    return recids - get_all_restricted_recids()
def filter_out_based_on_date_range(recids, fromdate="", untildate=""):
    """ 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)

    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, )))
    return recids - get_all_restricted_recids()
Beispiel #12
0
def format_element(bfo, magnify='yes', check_existence='yes', source="auto", display_name="no", display_reference="yes", display_description="yes", display_comment="yes", display_tirage="yes", submission_doctype=""):
    """
    Prints html image and link to photo resources, if 8567 exists print only 8567
    otherwise if exists 8564.
    @param magnify If 'yes', images will be magnified when mouse is over images
    @param check_existence if 'yes' check that file is reachable
    @param source where to look for photos. Possible values are 'mediaarchive', 'doc', 'bibdoc' or 'auto' (check everywhere)
    """
    out = ""

    rec_is_restricted = bfo.recID in get_all_restricted_recids()
    # Hack to know about copyright while we do not have this stored in
    # the metatada.
    copyright_prefix = ''
    report_number = bfo.field('037__a')
    author = bfo.field('100__a').lower()
    if report_number.startswith('ATL') or \
           'claudia marcelloni' in author or \
           'atlas' in author or \
           'joao pequenao' in author or \
           'tiina wickstroem' in author or \
           'nikolai topilin' in author:
        copyright_prefix = '<br/>The ATLAS Experiment '

    cond_of_use = '''<a href="http://copyright.cern.ch/">Conditions of Use</a> '''
    if bfo.field('540__u') or bfo.field('542__u') or bfo.field('542__d') != 'CERN' or bfo.field('540__a'):
        cond_of_use = ''

    # Check if image is under creative commons license
    creative_commons = False
    if bfo.field('540__a').startswith('CC-BY'):
        creative_commons = True
        out += '<div about="%s" rev="license">' % get_kb_mapping(kb_name='LICENSE2URL', key=bfo.field('540__a'))['value']
    multimedia = {}
    if source in ['auto', 'mediaarchive']:
        multimedia = get_media(bfo, check_existence=(check_existence.lower() == 'yes'))
        # Also append master information to the multimedia structure
        masters = get_media(bfo, path_code='d', internal_note_code='x', check_existence=(check_existence.lower() == 'yes'))
        for (tirage, info) in masters.iteritems():
            if multimedia.has_key(tirage):
                multimedia[tirage]['master'] = info['master']

    if multimedia != {} and source in ['auto', 'mediaarchive']:
        out += '''<center><small><strong>%s%s</strong></small></center><br />''' % (cond_of_use, bfe_copyright.format_element(bfo) or '&copy; CERN')
        out += '''<center><small><a href="%(CFG_SITE_URL)s/help/high-res-multimedia?ln=%(ln)s">%(label)s</a></small></center>''' % \
               {'CFG_SITE_URL': CFG_SITE_URL,
                'ln': bfo.lang,
                'label': bfo.lang == "fr" and 'Besoin d\'aide pour acc&eacute;der aux photos en haute r&eacute;solution?' or \
                'Need help to download high-resolutions?'}
        mediaarchive_pictures = print_images(multimedia=multimedia, magnify=magnify,
                                reference=bfo.field('037__a'), bfo=bfo)
        if len(multimedia) > 1 and not rec_is_restricted: # we have at least 2 photos
            out += generate_view_button(bfo, report_number, mediaarchive_pictures)
        else:
            out += mediaarchive_pictures
        out += '''<script type="text/javascript">
        window.onload = function() {
            if (location.hash != ''){
                    var pic = document.getElementById('thumb'+location.hash.substring(1));
                    if (pic != null){
                        hs.expand(pic)
                    }
                }
        }
                </script>'''
    elif not source in ['mediaarchive']:
        out += '''<center><small><strong>%s%s</strong></small></center><br />''' % (cond_of_use, bfe_copyright.format_element(bfo) or '&copy; CERN')

        bibdoc_pictures = get_bibdoc_pictures(bfo, display_name, display_reference,
                                              display_description, display_comment,
                                              display_tirage, submission_doctype)
        if bibdoc_pictures and source in ['auto', 'bibdoc']:
            if bibdoc_pictures.count('<img ') > 1 and not rec_is_restricted:# we have at least 1 photo
                out += generate_view_button(bfo, report_number, bibdoc_pictures)
            else:
                out += bibdoc_pictures
        elif source in ['auto', 'doc']:
            # Use picture from doc
            out += get_doc_pictures(bfo)

    if creative_commons:
        out += '</div>'
    return out