Esempio n. 1
0
def page_playlist(pl_id):
    login = get_login_info()

    try:
        owner = is_owner(pl_id)

        pl = playlist.Playlist(client, playlists_db_name, pl_id, owner)
        pl_details = pl.get_details()
        pl_rows = pl.get_rows()
        pl_cols = pl.get_columns()
    except IndexError:
        return abort(404)

    pl_data = {
        'id': pl_id,
        'duration': pl.get_duration(),
        'size': pl.get_size(),
        'timestamp': pl.get_timestamp(),
        'title': pl_details['playlist_title'],
        'creator': pl_details['playlist_creator_name'],
        'creator_id': pl_details['playlist_creator_id'],
        'desc': pl_details['playlist_desc']
    }

    return render_template("playlist_template.html",
                           data=pl_rows,
                           columns=pl_cols,
                           pl=pl_data,
                           login=login,
                           owner=owner)
Esempio n. 2
0
def add_map( pl_id ):
	login = get_login_info()

	if is_owner( pl_id ):
		pl = playlist.Playlist( client, playlists_db_name, pl_id )
		
		# POST method handler
		if request.method == 'POST':
			beatmap_str = request.form.get( 'beatmap_str' )
			status_msg = pl.add_map( beatmap_str )

		# GET method handler
		elif request.method == 'GET':
			status_msg = ""
		
		pl_data = pl.get_details()

		return render_template(
			"playlist_add_map_template.html",
			pl = pl_data,
			status_msg = status_msg,
			login = login
		)

	else:
		return redirect( '/unauthorized/' )
Esempio n. 3
0
def delete_playlist(pl_id):
    if is_owner(pl_id):
        if request.method == 'POST':
            pl = playlist.Playlist(client, playlists_db_name, pl_id)
            pl.delete()

        return redirect('/')

    else:
        return redirect('/unauthorized/')
Esempio n. 4
0
def is_owner( playlist_id ):
	pl_details = playlist.Playlist( client, playlists_db_name, playlist_id ).get_details()
	
	try:
		if str( session['user_id'] ) == str( pl_details['playlist_creator_id'] ):
			return True
	except Exception as e:
		print( e )

	return False
Esempio n. 5
0
def delete_map():
    playlist_id = request.form.get('playlist_id')

    if is_owner(playlist_id):
        user_id = request.form.get('user_id')
        beatmap_id = request.form.get('beatmap_id')

        pl = playlist.Playlist(client, playlists_db_name, playlist_id)
        pl.delete_map(user_id, beatmap_id)
        return redirect('/p/' + playlist_id)

    else:
        redirect('/unauthorized/')
Esempio n. 6
0
def edit_playlist( pl_id ):
	login = get_login_info()

	if is_owner( pl_id ):
		# POST method handler
		if request.method == 'POST':
			title = request.form.get( 'title' ).strip()[:max_playlist_title_len]
			desc = request.form.get( 'desc' ).strip()[:max_playlist_desc_len]

			if title == '':
				title = "untitled playlist"

			pl = playlist.Playlist( client, playlists_db_name, pl_id )
			pl.edit_details( title, desc )

			return redirect( f'/p/{ pl_id }/' )

		# GET method handler
		elif request.method == 'GET':
			pl = playlist.Playlist( client, playlists_db_name, pl_id )
			pl_details = pl.get_details()

			pl_data = {
				'id': pl_id,
				'title': pl_details['playlist_title'],
				'desc': pl_details['playlist_desc']			
			}

			return render_template(
				"playlist_edit_template.html",
				pl = pl_data,
				user_name = session['user_name'],
				user_id = session['user_id'],
				login = login
			)

	else:
		return redirect( '/unauthorized/' )