Example #1
0
def search():
    conn = get_conn()
    record = db.get_media(conn, session['user_id'],
                          title=request.args['query'])

    if record:
        return redirect('/media/%s' % record['id'])
    else:
        flash('Could not find media with title "%s"' % request.args['query'])
        return redirect(url_for('index'))
Example #2
0
def media_by_id(media_id):
    conn = get_conn()
    status_value = db.get_status(conn, session['user_id'], media_id)

    record = db.get_media(conn, session['user_id'], media_id=media_id)
    if not record:
        flash('Could not find media with id "%s"' % media_id)
        return redirect(url_for('index'))

    record['length'] = convert.length_to_display(record['length'])
    record['rating'] = round(record['rating'], 2)
    record['status'] = convert.status_to_display(status_value)

    received = db.get_recommendations_received(conn, session['user_id'],
                                               media_id)
    sent = db.get_recommendations_sent(conn, session['user_id'], media_id)

    users = [u for u in db.get_users(conn)
             if u['id'] != session['user_id'] and \
                u['id'] not in (s['user_id'] for s in sent)]

    return render_template('media.html', media=record, received=received,
                           sent=sent, users=users)