Exemple #1
0
def create_minimal_resources(db, minimal_member_record,
                             minimal_location_record, minimal_item_record,
                             minimal_document_record):
    """Simple patron record."""
    member = MemberWithLocations.create(minimal_member_record, dbcommit=True)
    location = Location.create(minimal_location_record, dbcommit=True)
    member.add_location(location)
    doc = DocumentsWithItems.create(minimal_document_record, dbcommit=True)
    item = Item.create({})
    item.update(minimal_item_record, dbcommit=True)
    doc.add_item(item, dbcommit=True)
    db.session.commit()
    yield doc, item, member, location
def test_create(db, minimal_document_record, minimal_item_record,
                minimal_member_record, minimal_location_record):
    """Test DocumentWithItems creation."""
    memb = MemberWithLocations.create(minimal_member_record, dbcommit=True)
    loc = Location.create(minimal_location_record, dbcommit=True)
    memb.add_location(loc, dbcommit=True)
    minimal_item_record['location_pid'] = loc.pid
    item = Item.create(minimal_item_record, dbcommit=True)
    doc = DocumentsWithItems.create(minimal_document_record, dbcommit=True)
    assert doc.itemslist == []

    doc.add_item(item, dbcommit=True)
    assert doc.itemslist[0] == item

    dump = doc.dumps()
    assert dump['itemslist'][0] == item.dumps()
Exemple #3
0
def test_member_name(db, minimal_member_record, minimal_item_record,
                     minimal_location_record):
    """Test member names."""
    member = MemberWithLocations.create(minimal_member_record, dbcommit=True)
    assert member
    location = Location.create(minimal_location_record, dbcommit=True)
    assert location
    member.add_location(location, dbcommit=True)
    assert member.locations
    item = Item.create({})
    item.update(minimal_item_record, dbcommit=True)
    assert item
    data = item.dumps()
    assert data.get('member_pid') == '1'
    assert data.get('member_name') == 'MV Sion'
    holding = data.get('_circulation').get('holdings')[1]
    assert holding['pickup_member_name'] == 'MV Sion'
Exemple #4
0
def request_item(pid_value, member):
    """HTTP GET request for Item request action."""
    try:
        patron = Patron.get_patron_by_email(current_user.email)
        patron_barcode = patron['barcode']
        item = Item.get_record_by_pid(pid_value)
        doc = DocumentsWithItems.get_document_by_itemid(item.id)
        request_datetime = pytz.utc.localize(datetime.now()).isoformat()
        item.request_item(patron_barcode=patron_barcode,
                          pickup_member_pid=member,
                          request_datetime=request_datetime)
        commit_item(item)
        flash(_('The item %s has been requested.' % pid_value), 'success')
        return_value = redirect(
            url_for('invenio_records_ui.doc', pid_value=doc['pid']))
        return redirect(url_for('invenio_records_ui.doc',
                                pid_value=doc['pid']))
    except Exception as e:
        return jsonify({'status': 'error: %s' % e}), 500
        flash(_('Something went wrong'), 'danger')
Exemple #5
0
def item_from_web_request(data):
    """Get item from web request data."""
    data = request.get_json()
    pid = data.pop('pid')
    return Item.get_record_by_pid(pid)