Esempio n. 1
0
def signed_out():
    """Find instruments that haven't been signed back in yet"""
    found = InstrumentModel.scan((InstrumentModel.assignedTo.exists())
                                 & (InstrumentModel.gifted == False))
    instruments_out = api_models.process_instrument_db_list(found)

    return data_or_404(instruments_out)
Esempio n. 2
0
def history_and_assigned(search: api_models.Search):
    """Find a student's assigned instrument and history"""
    found_items = InstrumentModel.scan(
        InstrumentModel.history.contains(search.term)
        | InstrumentModel.assignedTo.contains(search.term))
    instruments_out = api_models.process_instrument_db_list(found_items)
    return data_or_404(instruments_out)
Esempio n. 3
0
def main(instrument_filter: api_models.InstrumentFilter):
    """Filter instruments by certain values"""
    filter_string = instrument_filter.generate_filter_string()

    found = InstrumentModel.scan(eval(filter_string))
    instruments_out = api_models.process_instrument_db_list(found)

    return success(instruments_out)
Esempio n. 4
0
def sign_out_instrument(sign_out):
    found = list(InstrumentModel.scan(InstrumentModel.number == sign_out.number))
    if not found:
        return None
    item = found[0]
    if item.assignedTo:
        item.history = make_new_history(item.history, item.assignedTo)
    item.assignedTo = sign_out.assignedTo
    item.location = sign_out.location
    item.save()
    item.refresh()
    return item
Esempio n. 5
0
def main(sign_out: api_models.SignOut):
    """Sign out an instrument"""
    # noinspection PyTypeChecker
    found = list(InstrumentModel.scan(InstrumentModel.number == sign_out.number))
    item = sign_out_instrument(sign_out)
    if item:
        return success(
            {
                "message": f"Instrument {item.number} signed out to {item.assignedTo}"
                f" at {item.location}",
                "id": item.id,
            }
        )
    else:
        return not_found()
Esempio n. 6
0
def single(body: api_models.RetrieveSingle):
    """Mark an instrument as having been retrieved"""
    # noinspection PyTypeChecker
    found = list(
        InstrumentModel.scan(InstrumentModel.number == body.number.upper()))
    if not found:
        return not_found()
    item = found[0]
    item.location = "Storage"
    if item.assignedTo:
        item.history = make_new_history(item.history, item.assignedTo)
    item.assignedTo = None
    item.gifted = False
    item.save()
    return success({
        "message": f"{item.type} {item.number} retrieved",
        "id": item.id
    })
Esempio n. 7
0
def multiple(body: api_models.RetrieveMultiple):
    """Mark multiple instruments as having been retrieved"""
    numbers = [number.upper() for number in body.numbers]
    response_body = {"instrumentsUpdated": [], "instrumentsFailed": []}
    scan = InstrumentModel.scan(InstrumentModel.number.is_in(*numbers))
    for ins in scan:
        try:
            ins.location = "Storage"
            if ins.assignedTo:
                ins.history = make_new_history(ins.history, ins.assignedTo)
            ins.assignedTo = None
            ins.gifted = False
            ins.save()
            response_body["instrumentsUpdated"].append(ins.number)
        except Exception as err:
            print(err)
            response_body["instrumentsFailed"].append(ins.number)
    for instrument_number in body.numbers:
        if (instrument_number not in response_body["instrumentsUpdated"] and
                instrument_number not in response_body["instrumentsFailed"]):
            response_body["instrumentsFailed"].append(instrument_number)
    return success(response_body)
Esempio n. 8
0
def all_():
    """Get all the instruments"""
    instruments = api_models.process_instrument_db_list(InstrumentModel.scan())
    return success(instruments)
Esempio n. 9
0
def gifted():
    """Find instruments that have been given away to students"""
    found = InstrumentModel.scan(InstrumentModel.gifted == True)
    instruments_out = api_models.process_instrument_db_list(found)
    return data_or_404(instruments_out)
Esempio n. 10
0
def number(search: api_models.Search):
    """Find an instrument by number"""
    # noinspection PyTypeChecker
    found_items = InstrumentModel.scan(InstrumentModel.number == search.term)
    instruments_out = api_models.process_instrument_db_list(found_items)
    return data_or_404(instruments_out)
Esempio n. 11
0
def history(search: api_models.Search):
    """Find an instrument by its history"""
    found_items = InstrumentModel.scan(
        InstrumentModel.history.contains(search.term))
    instruments_out = api_models.process_instrument_db_list(found_items)
    return data_or_404(instruments_out)
Esempio n. 12
0
def assigned(search: api_models.Search):
    """Find an instrument by who it's assigned to"""
    found_items = InstrumentModel.scan(
        InstrumentModel.assignedTo.contains(search.term))
    instruments_out = api_models.process_instrument_db_list(found_items)
    return data_or_404(instruments_out)