Esempio n. 1
0
def ill_request(record_id=None):
    """Interface to request an inter library loan for the user.

    Without a record_id, an empty form will be presented.
    """
    try:
        get_user(current_user)
    except AttributeError:
        # Anonymous User
        return render_template('invenio_theme/401.html')

    if record_id:
        _uuid = PersistentIdentifier.get('recid', record_id).object_uuid
        rec = Record.get_record(_uuid)
    else:
        rec = {}

    _prepare_record(rec, rec_fields)
    _prepare_record_authors(rec)

    start_date = datetime.date.today().isoformat()
    end_date = datetime.date.today() + datetime.timedelta(weeks=4)

    return render_template('circulation_ill_request.html',
                           action='request', record_id=record_id,
                           start_date=start_date, end_date=end_date, **rec)
def ill_request(record_id=None):
    """Interface to request an inter library loan for the user.

    Without a record_id, an empty form will be presented.
    """
    try:
        get_user(current_user)
    except AttributeError:
        # Anonymous User
        return render_template("invenio_theme/401.html")

    if record_id:
        _uuid = PersistentIdentifier.get("recid", record_id).object_uuid
        rec = Record.get_record(_uuid)
    else:
        rec = {}

    _prepare_record(rec, rec_fields)
    _prepare_record_authors(rec)

    start_date = datetime.date.today().isoformat()
    end_date = datetime.date.today() + datetime.timedelta(weeks=4)

    return render_template(
        "circulation_ill_request.html",
        action="request",
        record_id=record_id,
        start_date=start_date,
        end_date=end_date,
        **rec
    )
def request_acquisition():
    try:
        user = get_user(current_user)
        data = json.loads(request.get_json())
        return _create_acquisition(data, user)
    except AttributeError:
        return ('', 403)
def request_acquisition():
    try:
        user = get_user(current_user)
        data = json.loads(request.get_json())
        return _create_acquisition(data, user)
    except AttributeError:
        return ('', 403)
Esempio n. 5
0
def api_user_run_action():
    """API to run a specified user action on a hold."""
    from flask_login import current_user
    from invenio_circulation.signals import run_action, convert_params
    from invenio_circulation.api.utils import ValidationExceptions
    from invenio_circulation.views.utils import get_user

    data = json.loads(request.get_json())

    # We restrict the possibilities a bit
    if data['action'] not in ['request', 'loan_extension', 'cancel_clcs']:
        return ('', 500)

    try:
        user = get_user(current_user)
    except AttributeError:
        return ('', 500)

    res = send_signal(convert_params, data['action'], data)
    for key, value in reduce(lambda x, y: dict(x, **y), res).items():
        data[key] = value

    data['user'] = user

    try:
        message = send_signal(run_action, data['action'], data)[0]
    except ValidationExceptions:
        flash(('The desired action failed, click *CHECK PARAMETERS* '
               'for more information.'), 'danger')
        return ('', 500)

    flash(message)
    return ('', 200)
Esempio n. 6
0
def user_record_actions(record_id, state=None):
    """User interface providing user interactions on a given record."""
    from flask_login import current_user

    try:
        user = get_user(current_user)
    except AttributeError:
        user = None

    record = models.CirculationRecord.get(record_id)

    start_date, end_date, waitlist, delivery = _get_state(state)

    record._items = _get_record_items(record_id, user,
                                      start_date, end_date,
                                      waitlist)

    cal_range = _get_cal_heatmap_range(x['item'] for x in record._items)
    cal_range = max(cal_range, (end_date.month - start_date.month + 1))

    return render_template('user/user_record_actions.html',
                           user=user, record=record,
                           start_date=start_date.isoformat(),
                           end_date=end_date.isoformat(),
                           waitlist=waitlist, delivery=delivery,
                           cal_range=cal_range, cal_data={})
def request_ill():
    """API to request an inter library loan for the user."""
    try:
        user = get_user(current_user)
        data = json.loads(request.get_json())
        return _create_ill(data, user)
    except AttributeError:
        return ("", 403)
Esempio n. 8
0
def request_ill():
    """API to request an inter library loan for the user."""
    try:
        user = get_user(current_user)
        data = json.loads(request.get_json())
        return _create_ill(data, user)
    except AttributeError:
        return ('', 403)
def acquisition_request(record_id=None):
    try:
        get_user(current_user)
    except AttributeError:
        # Anonymous User
        return render_template('invenio_theme/401.html')

    if record_id:
        _uuid = PersistentIdentifier.get('recid', record_id).object_uuid
        rec = Record.get_record(_uuid)
    else:
        rec = {}

    _prepare_record(rec, rec_fields)
    _prepare_record_authors(rec)

    return render_template('circulation_acquisition_request.html',
                           type='acquisition', action='request',
                           **rec)
def acquisition_request(record_id=None):
    try:
        get_user(current_user)
    except AttributeError:
        # Anonymous User
        return render_template('invenio_theme/401.html')

    if record_id:
        _uuid = PersistentIdentifier.get('recid', record_id).object_uuid
        rec = Record.get_record(_uuid)
    else:
        rec = {}

    _prepare_record(rec, rec_fields)
    _prepare_record_authors(rec)

    return render_template('circulation_acquisition_request.html',
                           type='acquisition',
                           action='request',
                           **rec)
Esempio n. 11
0
def users_current_holds():
    """User interface showing the current users holds."""
    from flask_login import current_user
    from invenio_circulation.signals import user_current_holds

    try:
        user = get_user(current_user)
    except AttributeError:
        # Anonymous User
        return render_template('invenio_theme/401.html')

    editor_schema = json.dumps(user._json_schema, default=datetime_serial)
    editor_data = json.dumps(user.jsonify(), default=datetime_serial)

    holds = send_signal(user_current_holds, 'user_current_holds', user.id)

    return render_template('user/user_overview.html',
                           editor_data=editor_data,
                           editor_schema=editor_schema,
                           holds=flatten(holds))