From 5f1502d41d27e2011cb7f5964742087bf2361224 Mon Sep 17 00:00:00 2001 From: spl0k Date: Sun, 23 Mar 2014 16:05:35 +0100 Subject: [PATCH] Converting frontend:playlists --- frontend/playlist.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/playlist.py b/frontend/playlist.py index 8c77718..f53ce73 100644 --- a/frontend/playlist.py +++ b/frontend/playlist.py @@ -20,13 +20,13 @@ from flask import request, session, flash, render_template, redirect, url_for import uuid -from web import app -import db +from web import app, store +from db import Playlist @app.route('/playlist') def playlist_index(): - return render_template('playlists.html', mine = db.Playlist.query.filter(db.Playlist.user_id == uuid.UUID(session.get('userid'))), - others = db.Playlist.query.filter(db.Playlist.user_id != uuid.UUID(session.get('userid')))) + return render_template('playlists.html', mine = store.find(Playlist, Playlist.user_id == uuid.UUID(session.get('userid'))), + others = store.find(Playlist, Playlist.user_id != uuid.UUID(session.get('userid')))) @app.route('/playlist/') def playlist_details(uid): @@ -36,7 +36,7 @@ def playlist_details(uid): flash('Invalid playlist id') return redirect(url_for('playlist_index')) - playlist = db.Playlist.query.get(uid) + playlist = store.get(Playlist, uid) if not playlist: flash('Unknown playlist') return redirect(url_for('playlist_index')) @@ -51,7 +51,7 @@ def playlist_update(uid): flash('Invalid playlist id') return redirect(url_for('playlist_index')) - playlist = db.Playlist.query.get(uid) + playlist = store.get(Playlist, uid) if not playlist: flash('Unknown playlist') return redirect(url_for('playlist_index')) @@ -63,7 +63,7 @@ def playlist_update(uid): else: playlist.name = request.form.get('name') playlist.public = request.form.get('public') in (True, 'True', 1, '1', 'on', 'checked') - db.session.commit() + store.commit() flash('Playlist updated.') return playlist_details(uid) @@ -76,14 +76,14 @@ def playlist_delete(uid): flash('Invalid playlist id') return redirect(url_for('playlist_index')) - playlist = db.Playlist.query.get(uid) + playlist = store.get(Playlist, uid) if not playlist: flash('Unknown playlist') elif str(playlist.user_id) != session.get('userid'): flash("You're not allowed to delete this playlist") else: - db.session.delete(playlist) - db.session.commit() + store.remove(playlist) + store.commit() flash('Playlist deleted') return redirect(url_for('playlist_index'))