예제 #1
0
파일: oai.py 프로젝트: jilljenn/dissemin
def find_earliest_oai_date(record):
    """ Find the latest publication date (if any) in a record """
    earliest = None
    for date in record[1]._map['date']:
        try:
            parsed = tolerant_datestamp_to_datetime(date)
            if earliest is None or parsed < earliest:
                earliest = parsed
        except (DatestampError, ValueError):
            continue
    return earliest
예제 #2
0
파일: oai.py 프로젝트: Lysxia/dissemin
def find_earliest_oai_date(record):
    """ Find the latest publication date (if any) in a record """
    earliest = None
    for date in record[1]._map['date']:
        try:
            parsed = tolerant_datestamp_to_datetime(date)
            if earliest is None or parsed < earliest:
                earliest = parsed
        except (DatestampError, ValueError):
            continue
    return earliest
예제 #3
0
def getListQuery(context, request):
    """
    Returns the query dictionary corresponding to the request
    Raises OaiRequestError if anything goes wrong
    """
    queryParameters = dict()

    # Both POST and GET arguments *must* be supported according to the standard
    # In this implementation, POST arguments are prioritary.
    getParams = dict(request.GET.dict().items() + request.POST.dict().items())
    
    # metadataPrefix
    metadataPrefix = getParams.pop('metadataPrefix', None)
    if not metadataPrefix:
        raise OaiRequestError('badArgument', 'The metadataPrefix argument is required.')
    if metadataPrefix != 'any':
        try:
            format = OaiFormat.objects.get(name=metadataPrefix)
        except ObjectDoesNotExist:
            raise OaiRequestError('badArgument', 'The metadata format "'+metadataPrefix+'" does not exist.')
        queryParameters['format'] = format

    # set
    set = getParams.pop('set', None)
    if set:
        if set.startswith(FINGERPRINT_IDENTIFIER_PREFIX):
            fingerprint = set[len(FINGERPRINT_IDENTIFIER_PREFIX):]
            if not fingerprint:
                raise OaiRequestError('badArgument', 'Invalid fingerprint.')
            queryParameters['fingerprint'] = fingerprint
        elif set.startswith(DOI_IDENTIFIER_PREFIX):
            doi = set[len(DOI_IDENTIFIER_PREFIX):]
            if not doi:
                raise OaiRequestError('badArgument', 'Invalid DOI.')
            queryParameters['doi'] = doi.lower()
        else:
            matchingSet = OaiSet.byRepresentation(set)
            if not matchingSet:
                raise OaiRequestError('badArgument', 'The set "'+set+'" does not exist.')
            queryParameters['sets'] = matchingSet

    
    # from
    from_ = getParams.pop('from', None)
    if from_:
        try:
            from_ = tolerant_datestamp_to_datetime(from_)
        except DatestampError:
            raise OaiRequestError('badArgument',
                    'The parameter "from" expects a valid date, not "'+from_+"'.")
        queryParameters['last_modified__gte'] = make_aware(from_, UTC())

    # until
    until = getParams.pop('until', None)
    if until:
        try:
            until = tolerant_datestamp_to_datetime(until)
        except DatestampError:
            raise OaiRequestError('badArgument',
                    'The parameter "until" expects a valid date, not "'+until+"'.")
        queryParameters['last_modified__lte'] = make_aware(until, UTC())

    # Check that from <= until
    if from_ and until and from_ > until:
        raise OaiRequestError('badArgument', '"from" should not be after "until".')

    # Check that there are no other arguments
    getParams.pop('verb', None)
    for key in getParams:
        raise OaiRequestError('badArgument', 'The argument "'+key+'" is illegal.')

    return queryParameters
예제 #4
0
파일: views.py 프로젝트: marcore/pok-eco
def get_list_query(request):
    """
    Returns the query dictionary corresponding to the request
    Raises OaiRequestError if anything goes wrong
    """
    query_parameters = dict()

    # Both POST and GET arguments *must* be supported according to the standard
    # In this implementation, POST arguments are prioritary.
    getParams = dict(request.GET.dict().items() + request.POST.dict().items())

    # metadataPrefix
    metadataPrefix = getParams.pop('metadataPrefix', None)
    if not metadataPrefix:
        raise OaiRequestError(
            'badArgument', 'The metadataPrefix argument is required.')
    try:
        oai_format = OaiFormat.objects.get(name=metadataPrefix)
    except ObjectDoesNotExist:
        raise OaiRequestError(
            'badArgument', 'The metadata format "' + metadataPrefix + '" does not exist.')
    query_parameters['format'] = oai_format

    # set
    set_by_param = getParams.pop('set', None)
    if set_by_param:
        matching_set = OaiSet.by_representation(set_by_param)
        if not matching_set:
            raise OaiRequestError(
                'badArgument', 'The set "' + set_by_param + '" does not exist.')
        query_parameters['sets'] = matching_set

    # from
    from_ = getParams.pop('from', None)
    if from_:
        try:
            from_ = tolerant_datestamp_to_datetime(from_)
        except DatestampError:
            raise OaiRequestError('badArgument',
                                  'The parameter "from" expects a valid date, not "' + from_ + "'.")
        query_parameters['timestamp__gte'] = make_aware(from_, UTC())

    # until
    until = getParams.pop('until', None)
    if until:
        try:
            until = tolerant_datestamp_to_datetime(until)
        except DatestampError:
            raise OaiRequestError('badArgument',
                                  'The parameter "until" expects a valid date, not "' + until + "'.")
        query_parameters['timestamp__lte'] = make_aware(until, UTC())

    # Check that from <= until
    if from_ and until and from_ > until:
        raise OaiRequestError(
            'badArgument', '"from" should not be after "until".')

    # Check that there are no other arguments
    getParams.pop('verb', None)
    for key in getParams:
        raise OaiRequestError(
            'badArgument', 'The argument "' + key + '" is illegal.')

    return query_parameters
예제 #5
0
파일: views.py 프로젝트: zuphilip/proaixy
def getListQuery(context, request):
    """
    Returns the query dictionary corresponding to the request
    Raises OaiRequestError if anything goes wrong
    """
    queryParameters = dict()

    # Both POST and GET arguments *must* be supported according to the standard
    # In this implementation, POST arguments are prioritary.
    getParams = dict(request.GET.dict().items() + request.POST.dict().items())

    # metadataPrefix
    metadataPrefix = getParams.pop('metadataPrefix', None)
    if not metadataPrefix:
        raise OaiRequestError('badArgument',
                              'The metadataPrefix argument is required.')
    try:
        format = OaiFormat.objects.get(name=metadataPrefix)
    except ObjectDoesNotExist:
        raise OaiRequestError(
            'badArgument',
            'The metadata format "' + metadataPrefix + '" does not exist.')
    queryParameters['format'] = format

    # set
    set = getParams.pop('set', None)
    if set:
        if set.startswith(FINGERPRINT_IDENTIFIER_PREFIX):
            fingerprint = set[len(FINGERPRINT_IDENTIFIER_PREFIX):]
            if not fingerprint:
                raise OaiRequestError('badArgument', 'Invalid fingerprint.')
            queryParameters['fingerprint'] = fingerprint
        elif set.startswith(DOI_IDENTIFIER_PREFIX):
            doi = set[len(DOI_IDENTIFIER_PREFIX):]
            if not doi:
                raise OaiRequestError('badArgument', 'Invalid DOI.')
            queryParameters['doi'] = doi.lower()
        else:
            matchingSet = OaiSet.byRepresentation(set)
            if not matchingSet:
                raise OaiRequestError('badArgument',
                                      'The set "' + set + '" does not exist.')
            queryParameters['sets'] = matchingSet

    # from
    from_ = getParams.pop('from', None)
    if from_:
        try:
            from_ = tolerant_datestamp_to_datetime(from_)
        except DatestampError:
            raise OaiRequestError(
                'badArgument',
                'The parameter "from" expects a valid date, not "' + from_ +
                "'.")
        queryParameters['timestamp__gte'] = make_aware(from_, UTC())

    # until
    until = getParams.pop('until', None)
    if until:
        try:
            until = tolerant_datestamp_to_datetime(until)
        except DatestampError:
            raise OaiRequestError(
                'badArgument',
                'The parameter "until" expects a valid date, not "' + until +
                "'.")
        queryParameters['timestamp__lte'] = make_aware(until, UTC())

    # Check that from <= until
    if from_ and until and from_ > until:
        raise OaiRequestError('badArgument',
                              '"from" should not be after "until".')

    # Check that there are no other arguments
    getParams.pop('verb', None)
    for key in getParams:
        raise OaiRequestError('badArgument',
                              'The argument "' + key + '" is illegal.')

    return queryParameters