Пример #1
0
def generic_add(client, dbclass, entry):
    db_store = client['db_store']

    if 'id' in entry:
        raise AskgodException("You can't pass the 'id' field in an entry.")

    convert_properties(entry)
    validate_properties(dbclass, entry)

    dbentry = dbclass()
    for key, value in entry.items():
        setattr(dbentry, key, value)

    db_store.add(dbentry)
    return db_commit(db_store)
Пример #2
0
def generic_update(client, dbclass, entryid, entry):
    db_store = client['db_store']

    if not isinstance(entryid, int):
        raise AskgodException("The ID must be an integer.")

    if 'id' in entry:
        raise AskgodException("You can't pass the 'id' field in an entry.")

    results = db_store.find(dbclass, id=entryid)
    if results.count() != 1:
        raise AskgodException("Can't find a match for id=%s" % entryid)

    convert_properties(entry)
    validate_properties(dbclass, entry)

    flag = results[0]
    for key, value in entry.items():
        setattr(flag, key, value)

    return db_commit(db_store)