def playlists(): playlists = db.get_playlists_by_user(get_current_user()) or [] if wants_html(): return render_template('playlists.html', playlists=playlists) else: return get_json_response(playlists)
def dashboard(): if user_logged_in(): return render_template('dashboard.html', links=get_current_user_links(session['user']), user=get_current_user(), url_not_valid=request.args.get('url_not_valid')) return redirect(url_for('login'))
def profile(): if request.method == 'POST': type_ = request.form['type'] if type_ == 'password': try: new_password, old_password = request.form[ 'new_password'], request.form['old_password'] if find_by_key_value('user', _id=ObjectId( session['user']))['password'] == old_password: update_by_key_value( 'user', target={'_id': ObjectId(session['user'])}, to_update_data={'password': new_password}) flash('Password Successfully updated', 'success') else: flash( 'Your old password seems to have been entered incorrectly!', 'failed') except: flash('Something went wrong, please try again later!', 'failed') elif type_ == 'name': try: name = request.form['name'] update_by_key_value('user', target={'_id': ObjectId(session['user'])}, to_update_data={'name': name}) flash('Name successfully updated', 'success') except: flash('Something went wrong, please try again later!', 'failed') else: try: email = request.form['email'] update_by_key_value('user', target={'_id': ObjectId(session['user'])}, to_update_data={ 'email': email, 'is_verified': 0 }) send_account_verification_email(email, session['user']) flash( 'Email updated. A verification email has been on your updated email account' ) except: flash('Something went wrong, please try again later!', 'failed') return redirect(url_for('profile')) return render_template('profile.html', user=get_current_user())
def track(track_id: int): import images import lyrics track = db.get_track_by_id(track_id) playlists = db.get_playlists_by_user(get_current_user()) # track.album banner_colour = images.get_predominant_colour(track.album) button_colour = images.get_button_colour(banner_colour) text_colour = images.get_text_colour(banner_colour) if wants_html(): return render_template( 'track.html', track=track, banner_colour=banner_colour, text_colour=text_colour, button_colour=button_colour, lyrics=lyrics.get_song_lyrics(track).split('\n'), playlists=playlists) else: return get_json_response(track, max_depth=1)
def add_to_playlist(track_id: int, playlist_id: int = None, playlist_name: str = None): if not playlist_id: playlist_id = int(request.form.get('playlist_id')) if playlist_id == -1: if not playlist_name: playlist_name = request.form.get('playlist_name') playlist = db.Playlist(name=playlist_name, creator_id=get_current_user().id) else: playlist = db.get_playlist_by_id(playlist_id) track = db.get_track_by_id(track_id) # Check track not already in playlist f = [*filter(lambda track: track.id == track_id, playlist.tracks)] if not f or len(f) == 0: playlist.tracks.append(track) db.session().commit() return redirect(request.referrer)
def api_access_information(): return render_template('api_access_info.html', token=get_user_api_token().decode('utf-8'), user=get_current_user())
def create_playlist(name: str): playlist = db.Playlist(name=name, creator_id=get_current_user().id) db.add_single(playlist) return redirect(request.referrer)
def short_link_usage_log(short_code): usage_logs = db_log.find({'short_code':short_code}) return render_template('short_link_log.html',usage_logs=usage_logs,short_code=short_code,user=get_current_user())