Example #1
0
def get(scrap_id):
    scrap = db_session.query(Scrapbook).get(scrap_id)
    if not scrap:
        return error("Scrap not found")
    scrap_dict = scrap.as_dict()
    scrap_dict['_link'] = url_for('get', **{'scrap_id': scrap.id})
    return jsonify(scrap.as_dict())
Example #2
0
def get_all():
    scraps = db_session.query(Scrapbook).all()
    scrap_dicts = []
    for scrap in scraps:
        scrap_dict = scrap.as_dict()
        scrap_dict['_link'] = url_for('get', **{'scrap_id': scrap.id})
        scrap_dicts.append(scrap_dict)
    # I returned a nice list comprehension here before, but had to add _link to each dict. Such is life
    return jsonify({'scraps': scrap_dicts})
Example #3
0
def delete(scrap_id):
    s = db_session.query(Scrapbook).get(scrap_id)
    uri = None
    if not s:
        return error("Scrap not found")
    else:
        uri = url_for('get', **{'scrap_id': s.id})
    db_session.delete(s)
    db_session.commit()
    return jsonify({"message": "%s was successfully deleted" % uri, "_link": url_for('get_all')})
Example #4
0
def show_entries():
    entries = db_session.query(Scrapbook).all()
    return render_template('show_entries.html', entries=entries)