Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrates to Bootstrap 5, closes #266 #267

Merged
merged 6 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions supysonic/frontend/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ def add_folder_post():
error = False
name, path = map(request.form.get, ("name", "path"))
if name in (None, ""):
flash("The name is required.")
flash("The name is required.", "danger")
error = True
if path in (None, ""):
flash("The path is required.")
flash("The path is required.", "danger")
error = True
if error:
return render_template("addfolder.html")

try:
FolderManager.add(name, path)
except ValueError as e:
flash(str(e), "error")
flash(str(e), "danger")
return render_template("addfolder.html")

flash(f"Folder '{name}' created. You should now run a scan")
flash(f"Folder '{name}' created. You should now run a scan", "success")
return redirect(url_for("frontend.folder_index"))


Expand All @@ -69,11 +69,11 @@ def add_folder_post():
def del_folder(id):
try:
FolderManager.delete(id)
flash("Deleted folder")
flash("Deleted folder", "success")
except ValueError as e:
flash(str(e), "error")
flash(str(e), "danger")
except Folder.DoesNotExist:
flash("No such folder", "error")
flash("No such folder", "danger")

return redirect(url_for("frontend.folder_index"))

Expand All @@ -90,10 +90,10 @@ def scan_folder(id=None):
DaemonClient(current_app.config["DAEMON"]["socket"]).scan(folders)
flash("Scanning started")
except ValueError as e:
flash(str(e), "error")
flash(str(e), "danger")
except Folder.DoesNotExist:
flash("No such folder", "error")
flash("No such folder", "danger")
except DaemonUnavailableError:
flash("Can't start scan", "error")
flash("Can't start scan", "danger")

return redirect(url_for("frontend.folder_index"))
14 changes: 7 additions & 7 deletions supysonic/frontend/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def decorated(uid):
try:
uid = uuid.UUID(uid)
except ValueError:
flash("Invalid playlist id")
flash("Invalid playlist id", "warning")
return redirect(url_for("frontend.playlist_index"))

try:
playlist = Playlist[uid]
except Playlist.DoesNotExist:
flash("Unknown playlist")
flash("Unknown playlist", "warning")
return redirect(url_for("frontend.playlist_index"))

return func(uid, playlist)
Expand Down Expand Up @@ -64,9 +64,9 @@ def playlist_export(uid, playlist):
@resolve_and_inject_playlist
def playlist_update(uid, playlist):
if playlist.user_id != request.user.id:
flash("You're not allowed to edit this playlist")
flash("You're not allowed to edit this playlist", "danger")
elif not request.form.get("name"):
flash("Missing playlist name")
flash("Missing playlist name", "danger")
else:
playlist.name = request.form.get("name")
playlist.public = request.form.get("public") in (
Expand All @@ -78,7 +78,7 @@ def playlist_update(uid, playlist):
"checked",
)
playlist.save()
flash("Playlist updated.")
flash("Playlist updated.", "success")

return playlist_details(str(uid))

Expand All @@ -87,9 +87,9 @@ def playlist_update(uid, playlist):
@resolve_and_inject_playlist
def playlist_delete(uid, playlist):
if playlist.user_id != request.user.id:
flash("You're not allowed to delete this playlist")
flash("You're not allowed to delete this playlist", "danger")
else:
playlist.delete_instance()
flash("Playlist deleted")
flash("Playlist deleted", "success")

return redirect(url_for("frontend.playlist_index"))
74 changes: 40 additions & 34 deletions supysonic/frontend/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def decorated_func(*args, **kwargs):
try:
user = UserManager.get(uid)
except ValueError as e:
flash(str(e), "error")
flash(str(e), "danger")
return redirect(url_for("frontend.index"))
except User.DoesNotExist:
flash("No such user", "error")
flash("No such user", "danger")
return redirect(url_for("frontend.index"))

if kwargs:
Expand Down Expand Up @@ -111,7 +111,7 @@ def update_clients(uid, user):
)
prefs.save()

flash("Clients preferences updated.")
flash("Clients preferences updated.", "success")
return user_profile(uid, user)


Expand All @@ -121,10 +121,10 @@ def change_username_form(uid):
try:
user = UserManager.get(uid)
except ValueError as e:
flash(str(e), "error")
flash(str(e), "danger")
return redirect(url_for("frontend.index"))
except User.DoesNotExist:
flash("No such user", "error")
flash("No such user", "danger")
return redirect(url_for("frontend.index"))

return render_template("change_username.html", user=user)
Expand All @@ -136,20 +136,20 @@ def change_username_post(uid):
try:
user = UserManager.get(uid)
except ValueError as e:
flash(str(e), "error")
flash(str(e), "danger")
return redirect(url_for("frontend.index"))
except User.DoesNotExist:
flash("No such user", "error")
flash("No such user", "danger")
return redirect(url_for("frontend.index"))

username = request.form.get("user")
if username in ("", None):
flash("The username is required")
flash("The username is required", "danger")
return render_template("change_username.html", user=user)
if user.name != username:
try:
User.get(name=username)
flash("This name is already taken")
flash("This name is already taken", "danger")
return render_template("change_username.html", user=user)
except User.DoesNotExist:
pass
Expand All @@ -163,7 +163,7 @@ def change_username_post(uid):
user.name = username
user.admin = admin
user.save()
flash(f"User '{username}' updated.")
flash(f"User '{username}' updated.", "success")
else:
flash(f"No changes for '{username}'.")

Expand Down Expand Up @@ -198,16 +198,16 @@ def change_password_post(uid, user):
if user.id == request.user.id:
current = request.form.get("current")
if not current:
flash("The current password is required")
flash("The current password is required", "danger")
error = True

new, confirm = map(request.form.get, ("new", "confirm"))

if not new:
flash("The new password is required")
flash("The new password is required", "danger")
error = True
if new != confirm:
flash("The new password and its confirmation don't match")
flash("The new password and its confirmation don't match", "danger")
error = True

if not error:
Expand All @@ -217,10 +217,10 @@ def change_password_post(uid, user):
else:
UserManager.change_password2(user.name, new)

flash("Password changed")
flash("Password changed", "success")
return redirect(url_for("frontend.user_profile", uid=uid))
except ValueError as e:
flash(str(e), "error")
flash(str(e), "danger")

return change_password_form(uid, user)

Expand All @@ -240,22 +240,22 @@ def add_user_post():
args.pop, ("user", "passwd", "passwd_confirm"), (None,) * 3
)
if not name:
flash("The name is required.")
flash("The name is required.", "danger")
error = True
if not passwd:
flash("Please provide a password.")
flash("Please provide a password.", "danger")
error = True
elif passwd != passwd_confirm:
flash("The passwords don't match.")
flash("The passwords don't match.", "danger")
error = True

if not error:
try:
UserManager.add(name, passwd, **args)
flash(f"User '{name}' successfully added")
flash(f"User '{name}' successfully added", "success")
return redirect(url_for("frontend.user_index"))
except ValueError as e:
flash(str(e), "error")
flash(str(e), "danger")

return add_user_form()

Expand All @@ -265,11 +265,11 @@ def add_user_post():
def del_user(uid):
try:
UserManager.delete(uid)
flash("Deleted user")
flash("Deleted user", "success")
except ValueError as e:
flash(str(e), "error")
flash(str(e), "danger")
except User.DoesNotExist:
flash("No such user", "error")
flash("No such user", "danger")

return redirect(url_for("frontend.user_index"))

Expand All @@ -279,12 +279,15 @@ def del_user(uid):
def lastfm_reg(uid, user):
token = request.args.get("token")
if not token:
flash("Missing LastFM auth token")
flash("Missing LastFM auth token", "warning")
return redirect(url_for("frontend.user_profile", uid=uid))

lfm = LastFm(current_app.config["LASTFM"], user)
status, error = lfm.link_account(token)
flash(error if not status else "Successfully linked LastFM account")
if not status:
flash(error, "danger")
else:
flash("Successfully linked LastFM account", "success")

return redirect(url_for("frontend.user_profile", uid=uid))

Expand All @@ -294,7 +297,7 @@ def lastfm_reg(uid, user):
def lastfm_unreg(uid, user):
lfm = LastFm(current_app.config["LASTFM"], user)
lfm.unlink_account()
flash("Unlinked LastFM account")
flash("Unlinked LastFM account", "success")
return redirect(url_for("frontend.user_profile", uid=uid))


Expand All @@ -303,12 +306,15 @@ def lastfm_unreg(uid, user):
def listenbrainz_reg(uid, user):
token = request.args.get("token")
if not token:
flash("Missing ListenBrainz auth token")
flash("Missing ListenBrainz auth token", "warning")
return redirect(url_for("frontend.user_profile", uid=uid))

lbz = ListenBrainz(current_app.config["LISTENBRAINZ"], user)
status, error = lbz.link_account(token)
flash(error if not status else "Successfully linked ListenBrainz account")
if not status:
flash(error, "danger")
else:
flash("Successfully linked ListenBrainz account", "success")

return redirect(url_for("frontend.user_profile", uid=uid))

Expand All @@ -318,7 +324,7 @@ def listenbrainz_reg(uid, user):
def listenbrainz_unreg(uid, user):
lbz = ListenBrainz(current_app.config["LISTENBRAINZ"], user)
lbz.unlink_account()
flash("Unlinked ListenBrainz account")
flash("Unlinked ListenBrainz account", "success")
return redirect(url_for("frontend.user_profile", uid=uid))


Expand All @@ -335,30 +341,30 @@ def login():
name, password = map(request.form.get, ("user", "password"))
error = False
if not name:
flash("Missing user name")
flash("Missing user name", "danger")
error = True
if not password:
flash("Missing password")
flash("Missing password", "danger")
error = True

if not error:
user = UserManager.try_auth(name, password)
if user:
logger.info("Logged user %s (IP: %s)", name, request.remote_addr)
session["userid"] = str(user.id)
flash("Logged in!")
flash("Logged in!", "success")
return redirect(return_url)
else:
logger.error(
"Failed login attempt for user %s (IP: %s)", name, request.remote_addr
)
flash("Wrong username or password")
flash("Wrong username or password", "danger")

return render_template("login.html")


@frontend.route("/user/logout")
def logout():
session.clear()
flash("Logged out!")
flash("Logged out!", "success")
return redirect(url_for("frontend.login"))
6 changes: 0 additions & 6 deletions supysonic/static/css/bootstrap-theme.min.css

This file was deleted.

1 change: 0 additions & 1 deletion supysonic/static/css/bootstrap-theme.min.css.map

This file was deleted.

10 changes: 5 additions & 5 deletions supysonic/static/css/bootstrap.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion supysonic/static/css/bootstrap.min.css.map

Large diffs are not rendered by default.

30 changes: 4 additions & 26 deletions supysonic/static/css/supysonic.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This file is part of Supysonic.
* Supysonic is a Python implementation of the Subsonic server API.
*
* Copyright (C) 2017 Óscar García Amor
* 2017 Alban 'spl0k' Féron
* Copyright (C) 2017-2024 Óscar García Amor
* 2017-2024 Alban 'spl0k' Féron
*
* Distributed under terms of the GNU AGPLv3 license.
*/
Expand All @@ -12,30 +12,8 @@ body {
padding-top: 60px;
}

#loginbox {
margin-top: 30px;
}

#loginform > div {
margin-bottom: 20px;
}

#adduserform label {
margin-bottom: 0;
}

#clients td,
#playlist td {
vertical-align: middle;
}

.first-header {
margin-top: 20px;
}

.placeholders {
text-align: center;
padding-top: 15px;
.bi-va-fix {
vertical-align: -.125em;
}

.stats {
Expand Down
Binary file not shown.
Loading
Loading