2
0
Эх сурвалжийг харах

added add new videos to playlist feature

sleepytaco 3 жил өмнө
parent
commit
1b0f084741

+ 31 - 0
apps/main/migrations/0046_auto_20210731_1349.py

@@ -0,0 +1,31 @@
+# Generated by Django 3.2.3 on 2021-07-31 18:49
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('main', '0045_tag_times_viewed_per_week'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='playlist',
+            name='confirm_before_deleting',
+        ),
+        migrations.RemoveField(
+            model_name='playlist',
+            name='hide_unavailable_videos',
+        ),
+        migrations.AlterField(
+            model_name='video',
+            name='user_label',
+            field=models.CharField(blank=True, max_length=100),
+        ),
+        migrations.AlterField(
+            model_name='video',
+            name='user_notes',
+            field=models.CharField(blank=True, max_length=420),
+        ),
+    ]

+ 18 - 0
apps/main/migrations/0047_playlist_auto_check_for_updates.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.2.3 on 2021-07-31 19:15
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('main', '0046_auto_20210731_1349'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='playlist',
+            name='auto_check_for_updates',
+            field=models.BooleanField(default=False),
+        ),
+    ]

+ 1 - 0
apps/main/models.py

@@ -1342,6 +1342,7 @@ class Playlist(models.Model):
     # playlist settings (moved to global preferences)
     #hide_unavailable_videos = models.BooleanField(default=False)
     #confirm_before_deleting = models.BooleanField(default=True)
+    auto_check_for_updates = models.BooleanField(default=False)
 
     # for import
     is_in_db = models.BooleanField(default=False)  # is true when all the videos of a playlist have been imported

+ 2 - 1
apps/main/templates/home.html

@@ -41,6 +41,7 @@
             <div hx-get="{% url 'user_playlists_updates' 'check-for-updates' %}" hx-trigger="load" hx-swap="outerHTML">
 
             </div>
+
         {% endif %}
 
         <div class="row">
@@ -195,7 +196,7 @@
                 <div class="d-flex justify-content-evenly h4">
                     {% if playlist_tags %}
                     <div class="w-100 d-flex justify-content-center flex-wrap">
-                    {% for tag in playlist_tags %}
+                    {% for tag in playlist_tags|slice:"0:19" %}
                         <a href="{% url 'tagged_playlists' tag.name %}" style="text-decoration: none" class="me-lg-1 mb-lg-1">
                         <span class="badge rounded-pill bg-warning bg-gradient text-black-50">{{ tag.name }} <span class="badge bg-dark text-white">{{ tag.times_viewed_per_week }} views</span></span>
                         </a>

+ 6 - 48
apps/main/templates/intercooler/playlists.html

@@ -21,7 +21,7 @@
 {% else %}
     {% for playlist in playlists %}
         <div class="col">
-            <div class="card overflow-auto" style="background-color: {{ bg_color|default:"#4790c7" }};">
+            <div class="card overflow-auto" style="background-color: {{ bg_color|default:"#357779" }};">
                 <a href="{% url 'playlist' playlist.playlist_id %}" style="text-decoration: none; color: black">
                     <img  class="bd-placeholder-img card-img-top" src="{% if playlist.thumbnail_url %}{{ playlist.thumbnail_url }}{% else %}https://i.ytimg.com/vi/9219YrnwDXE/maxresdefault.jpg{% endif %}" style="max-width:100%; height: 200px;   object-fit: cover;" alt="{{ playlist.name }} thumbnail">
                 </a>
@@ -54,11 +54,15 @@
                                             <i class="fas fa-tags"></i>
                                         </span>
                                     </small>
-                                    {% for tag in playlist.tags.all %}
+                                    {% for tag in playlist.tags.all|slice:"0:4" %}
                                         <span class="badge rounded-pill bg-info mb-lg-1 me-lg-1 text-black-50">
                                             {{ tag.name }}
                                         </span>
+                                        {% if forloop.last and playlist.tags.all.count > 4 %}
+                                            <small><span class="text-black-50"> & {{ playlist.tags.all.count|add:"-4" }} more</span></small>
+                                        {% endif %}
                                     {% endfor %}
+
                                 </span>
                             </p>
                         {% endif %}
@@ -86,50 +90,4 @@
         </div>
     {% endfor %}
 
-    <!-- minified version
-    {% for playlist in playlists %}
-    <div class="col">
-        <div class="card" style="background-color: #515355;">
-            <a style="background-color: #1A4464;" href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item list-group-item-action" aria-current="true">
-
-                <div class="card-body">
-
-                    <h5 class="card-title text-white">
-                        {{ playlist.name }}
-
-                    </h5>
-
-                    <p class="card-text">
-                        {% if playlist.is_user_owned %}<small><span class="badge bg-light text-black-50">OWNED</span></small>{% else %}<small><span class="badge bg-light text-black-50">IMPORTED</span></small>{% endif %}
-                        {% if playlist.is_private_on_yt %}<small><span class="badge bg-secondary text-white">Private</span></small> {% endif %}
-                        {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-black-50">YT</span></small> {% endif %}
-                        {% if playlist.marked_as == "watching" %}<small><span class="badge bg-primary text-white">WATCHING</span></small>{% endif %}
-                    </p>
-
-                    {% if playlist.tags.all %}
-                        <p class="card-text">
-                        <span class="d-flex justify-content-start flex-wrap">
-                        <small>
-                        <span style="color: #eed868;" class="me-lg-1 mb-lg-1">
-                            <i class="fas fa-tags"></i>
-                        </span>
-                        </small>
-                        {% for tag in playlist.tags.all %}
-                            <span class="badge rounded-pill bg-info mb-lg-1 me-lg-1 text-black-50">
-                                {{ tag.name }}
-                            </span>
-                        {% endfor %}
-                        </span>
-                        </p>
-                    {% endif %}
-                    <small>
-                        <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
-                        <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
-                    </small>
-                </div>
-            </a>
-        </div>
-    </div>
-    {% endfor %}
-    -->
 {% endif %}

+ 2 - 0
apps/main/templates/intercooler/video_cards.html

@@ -6,7 +6,9 @@
             <div class="row g-0">
                 {% if not video.is_unavailable_on_yt and not video.was_deleted_on_yt %}
                 <div class="col-md-4">
+                    <a href="{% url 'video' video.video_id %}" style="text-decoration: none; color: white">
                     <img src="{{ video.thumbnail_url }}" class="img-fluid" style="width: 100%; height: 15vw; object-fit: cover;">
+                    </a>
                 </div>
                 {% endif %}
                 <div class="col-md-8">

+ 1 - 1
apps/main/templates/library.html

@@ -124,7 +124,7 @@
     <div class="card bg-dark text-white">
             <div class="card-header">
                 <div class="d-flex justify-content-center">
-                    <h3><span style="border-bottom: 3px #ffffff dashed;">Your Playlist Tags</span></h3>
+                    <h3><span style="border-bottom: 3px #ffffff dashed;">Your Playlist Tags</span><small class="ms-2"><span class="badge bg-warning rounded-pill">{{ user.playlist_tags.all.count }}</span></small> </h3>
                 </div>
             </div>
             <div class="card-body">

+ 66 - 29
apps/main/templates/view_playlist.html

@@ -33,12 +33,16 @@
                 </div>
             {% else %}
                 <div class="sticky-top mb-3" style="top: 0.5rem;">
-                    {% if user.profile.auto_check_for_updates and not playlist.is_yt_mix %}
-                        <div hx-get="{% url 'update_playlist' playlist.playlist_id 'checkforupdates' %}" hx-trigger="load" hx-swap="outerHTML" id="checkforupdates">
-                            <div class="alert alert-info alert-dismissible fade show" role="alert">
-                                Checking playlist for updates...
-                            </div>
-                        </div>
+                    {% if not playlist.is_yt_mix %}
+                        {% if user.profile.auto_check_for_updates %}
+                            {% if playlist.auto_check_for_updates %}
+                                <div hx-get="{% url 'update_playlist' playlist.playlist_id 'checkforupdates' %}" hx-trigger="load" hx-swap="outerHTML" id="checkforupdates">
+                                    <div class="alert alert-info alert-dismissible fade show" role="alert">
+                                        Checking playlist for updates...
+                                    </div>
+                                </div>
+                            {% endif %}
+                        {% endif %}
                     {% endif %}
                     {% if playlist.marked_as == "watching" %}
                         <div id="playlist-watch-message">
@@ -503,18 +507,13 @@
 
 
                                 <div class="col-md-8 text-dark">
-                                    <div id="add-videos-from">
-                                        <textarea name="add-videos-textarea" class="form-control" id="add-videos-text-area" placeholder="Enter video links or video IDs line by line here" rows="5"
-                                            hx-post="{% url 'manage_save' 'manage_playlists_import_textarea' %}"
-                                            hx-trigger="keyup changed delay:500ms"
-                                            hx-indicator="#spinner">{{ manage_playlists_import_textarea }}</textarea>
-                                        <div id="add-videos-text-area" class="form-text">
-                                            <a href="{% url 'search' %}?mode=videos&type=all" target="_blank" style="color: #398439; text-decoration: none">search on UnTube <i class="fas fa-external-link-alt"></i> </a> or
-                                            <a href="https://www.youtube.com/" target="_blank" style="color: #ec2d90; text-decoration: none">search on YouTube <i class="fas fa-external-link-alt"></i> </a>
-                                        </div>
-
+                                    <textarea name="add-videos-textarea" class="form-control" id="add-videos-textarea" placeholder="Enter video links or video IDs line by line here"
+                                        rows="5">{{ manage_playlists_import_textarea }}</textarea>
+                                    <div class="form-text">
+                                        Note: You can only add 25 videos at a time. Find videos by
+                                        <a href="{% url 'search' %}?mode=videos&type=all" target="_blank" style="color: #398439; text-decoration: none">searching on UnTube <i class="fas fa-external-link-alt"></i> </a> or
+                                        <a href="https://www.youtube.com/" target="_blank" style="color: #ec2d90; text-decoration: none">searching on YouTube <i class="fas fa-external-link-alt"></i> </a>
                                     </div>
-
                                 </div>
 
                             </div>
@@ -522,16 +521,17 @@
                             <div class="d-flex justify-content-start mt-2">
 
                                 <div class="btn-group ms-1 mt-1">
-                                    <button hx-indicator="#add-videos-loader" hx-post="{% url 'playlist_move_copy_videos' playlist.playlist_id 'copy' %}" hx-include="#playlists-to-move-to, #video-checkboxes" hx-target="#move-copy-videos-box" type="button" class="btn btn-primary">
+                                    <button hx-indicator="#add-videos-loader" hx-post="{% url 'playlist_add_new_videos' playlist.playlist_id %}" hx-include="#add-videos-textarea" hx-target="#add-videos-box" type="button" class="btn btn-primary">
                                         Add
                                     </button>
                                 </div>
-                                <div id="add-videos-box" class="d-flex align-items-end ms-2">
+                                <div id="add-videos-box" class="d-flex align-items-end ms-2 text-warning">
+
+                                </div>
+                                <div class="htmx-indicator d-flex align-items-center" id="add-videos-loader">
+                                    <img src="{% static 'svg-loaders/grid.svg' %}" width="25" height="25" class="ms-2 mt-2">
+                                    <span class="mt-2 ms-2 text-warning">Adding videos, please wait... </span>
                                 </div>
-                                    <div class="htmx-indicator d-flex align-items-center" id="add-videos-loader">
-                                        <img src="{% static 'svg-loaders/grid.svg' %}" width="25" height="25" class="ms-2 mt-2">
-                                        <span class="mt-2 ms-2 text-warning">Adding videos, please wait... </span>
-                                    </div>
                             </div>
 
                         </div>
@@ -569,10 +569,10 @@
                                 </div>
                                 <div id="add-videos-box" class="d-flex align-items-end ms-2">
                                 </div>
-                                    <div class="htmx-indicator d-flex align-items-center" id="create-playlist-loader">
-                                        <img src="{% static 'svg-loaders/grid.svg' %}" width="25" height="25" class="ms-2 mt-2">
-                                        <span class="mt-2 ms-2 text-warning">Creating playlist, please wait... </span>
-                                    </div>
+                                <div class="htmx-indicator d-flex align-items-center" id="create-playlist-loader">
+                                    <img src="{% static 'svg-loaders/grid.svg' %}" width="25" height="25" class="ms-2 mt-2">
+                                    <span class="mt-2 ms-2 text-warning">Creating playlist, please wait... </span>
+                                </div>
                             </div>
 
                         </div>
@@ -713,15 +713,52 @@
 
                         </div>
                     {% else %}
-                        <div class="card bg-dark text-white mb-3">
+                        <div class="card bg-dark text-white">
                             <div class="card-body">
-                                <div class="d-flex justify-content-center align-content-center">
+                                <div class="d-flex justify-content-center align-content-center mt-2">
                                     Playlist is empty ;-;
                                 </div>
                                 <div class="d-flex justify-content-center align-content-center">
                                     Consider moving/copying videos from other playlists into this playlist by copying and using this playlist's ID.
                                 </div>
+                                <div class="d-flex justify-content-center align-content-center">
+                                    - OR -
+                                </div>
+                                <div class="d-flex justify-content-center align-content-center">
+                                    Add new videos to this playlist
+                                </div>
+
+                                <div class="d-flex justify-content-center mt-2">
+                                    <textarea name="add-videos-textarea" class="form-control w-50" id="add-videos-textarea" placeholder="Enter video links or video IDs line by line here"
+                                        rows="5">{{ manage_playlists_import_textarea }}</textarea>
+
+                                </div>
+                                <div class="d-flex justify-content-center">
+
+                                    <div class="form-text">
+                                        Note: You can only add 25 videos at a time. Find videos by
+                                        <a href="{% url 'search' %}?mode=videos&type=all" target="_blank" style="color: #398439; text-decoration: none">searching on UnTube <i class="fas fa-external-link-alt"></i> </a> or
+                                        <a href="https://www.youtube.com/" target="_blank" style="color: #ec2d90; text-decoration: none">searching on YouTube <i class="fas fa-external-link-alt"></i> </a>
+                                    </div>
+                                </div>
+                                <div class="d-flex justify-content-center mt-2">
 
+                                    <div class="btn-group ms-1 mt-1">
+                                        <button hx-indicator="#add-videos-loader" hx-post="{% url 'playlist_add_new_videos' playlist.playlist_id %}" hx-include="#add-videos-textarea" hx-target="#add-videos-box" type="button" class="btn btn-primary">
+                                            Add
+                                        </button>
+                                    </div>
+
+                                </div>
+                                <div class="d-flex justify-content-center mt-2">
+                                    <div id="add-videos-box" class="d-flex align-items-end ms-2 text-warning">
+
+                                    </div>
+                                    <div class="htmx-indicator d-flex align-items-center" id="add-videos-loader">
+                                        <img src="{% static 'svg-loaders/grid.svg' %}" width="25" height="25" class="ms-2 mt-2">
+                                        <span class="mt-2 ms-2 text-warning">Adding videos, please wait... </span>
+                                    </div>
+                                </div>
                             </div>
                         </div>
 

+ 22 - 1
apps/main/templates/view_playlist_settings.html

@@ -7,7 +7,7 @@
 
 
     <div id="view_playlist">
-    {% if playlist.is_user_owned %}
+    {% if playlist.is_user_owned and not playlist.playlist_id == "LL" %}
 
         <div class="table-responsive" id="videos-div">
 
@@ -72,6 +72,16 @@
                         </div>
                         </div>
                       <hr>
+                    <div class="row">
+                        <div class="col-sm-3">
+                          <h6 class="mb-0">Check for updates upon visit</h6>
+                        </div>
+                        <div class="col-sm-9 text-white-50">
+                            <input class="form-check-input" type="checkbox" value="" name="pl-auto-update" {% if playlist.auto_check_for_updates %}checked{% endif %}>
+                        </div>
+                      </div>
+
+                        <hr>
                     <div class="row">
                         <div class="col-sm-3">
                           <h6 class="mb-0">Danger Zone</h6>
@@ -141,6 +151,17 @@
                       </div>
 
                         <hr>
+                    {% if not playlist.is_yt_mix %}
+                        <div class="row">
+                        <div class="col-sm-3">
+                          <h6 class="mb-0">Automatically check for updates upon visit</h6>
+                        </div>
+                        <div class="col-sm-9 text-white-50">
+                              <input class="form-check-input" type="checkbox" value="" name="pl-auto-update" {% if playlist.auto_check_for_updates %}checked{% endif %}>
+                        </div>
+                      </div>
+                        <hr>
+                    {% endif %}
                       <div class="row">
                         <div class="col-sm-3">
                           <h6 class="mb-0">Danger Zone</h6>

+ 3 - 1
apps/main/urls.py

@@ -38,7 +38,7 @@ urlpatterns = [
     path("playlist/<slug:playlist_id>/get-tags", views.get_playlist_tags, name="get_playlist_tags"),
     path("playlist/<slug:playlist_id>/get-unused-tags", views.get_unused_playlist_tags, name="get_unused_playlist_tags"),
     path("playlist/<slug:playlist_id>/get-watch-message", views.get_watch_message, name="get_watch_message"),
-    path("playlist/<slug:playlist_id>/delete-videos/<slug:command>", views.delete_videos, name='delete_videos'),
+    path("playlist/<slug:playlist_id>/delete-videos/<slug:command>", views.playlist_delete_videos, name='delete_videos'),
     path("playlist/<slug:playlist_id>/delete-specific-videos/<slug:command>", views.delete_specific_videos, name='delete_specific_videos'),
     path("playlist/<slug:playlist_id>/delete-playlist", views.delete_playlist, name="delete_playlist"),
     path("playlist/<slug:playlist_id>/reset-watched", views.reset_watched, name="reset_watched"),
@@ -46,6 +46,8 @@ urlpatterns = [
     path("playlist/<slug:playlist_id>/open-random-video", views.playlist_open_random_video, name="playlist_open_random_video"),
     path("playlist/<slug:playlist_id>/get-playlist-completion-times", views.playlist_completion_times,
          name="playlist_completion_times"),
+    path("playlist/<slug:playlist_id>/add-new-videos", views.playlist_add_new_videos,
+         name="playlist_add_new_videos"),
 
     ### STUFF RELATED TO PLAYLISTS IN BULK
     path("playlists/<slug:playlist_type>/order-by/<slug:order_by>", views.order_playlists_by, name='order_playlists_by'),

+ 14 - 0
apps/main/util.py

@@ -77,6 +77,20 @@ def generateWatchingMessage(playlist):
     pass
 
 
+def getVideoId(video_link):
+    """
+    takes in a valid video link and returns a video id
+    """
+    if "?" not in video_link:
+        return video_link
+
+    temp = video_link.split("?")[-1].split("&")
+
+    for el in temp:
+        if "v=" in el:
+            return el.split("v=")[-1]
+
+
 def increment_tag_views(playlist_tags):
     """
     Increments playlist tag overall views and views per week. If its been a week, views per week is reset to

+ 50 - 10
apps/main/views.py

@@ -24,8 +24,7 @@ from .util import *
 def home(request):
     user_profile = request.user
     watching = user_profile.playlists.filter(Q(marked_as="watching") & Q(is_in_db=True)).order_by("-num_of_accesses")
-    recently_accessed_playlists = user_profile.playlists.filter(is_in_db=True).filter(
-        updated_at__gt=user_profile.profile.created_at).order_by("-updated_at")[:6]
+    recently_accessed_playlists = user_profile.playlists.filter(is_in_db=True).order_by("-updated_at")[:6]
     recently_added_playlists = user_profile.playlists.filter(is_in_db=True).order_by("-created_at")[:6]
 
     #### FOR NEWLY JOINED USERS ######
@@ -187,7 +186,7 @@ def view_playlist(request, playlist_id):
 @login_required
 def tagged_playlists(request, tag):
     tag = get_object_or_404(Tag, created_by=request.user, name=tag)
-    playlists = tag.playlists.all()
+    playlists = request.user.playlists.all().filter(Q(is_in_db=True) & Q(tags__name=tag.name)).order_by("-updated_at")
 
     return render(request, 'all_playlists_with_tag.html', {"playlists": playlists, "tag": tag})
 
@@ -248,7 +247,7 @@ def library(request, library_type):
     else:
         return redirect('home')
 
-    return render(request, 'all_playlists.html', {"playlists": playlists,
+    return render(request, 'all_playlists.html', {"playlists": playlists.order_by("-updated_at"),
                                                   "library_type": library_type,
                                                   "library_type_display": library_type_display,
                                                   "watching": watching})
@@ -396,7 +395,7 @@ def playlists_home(request):
 
 @login_required
 @require_POST
-def delete_videos(request, playlist_id, command):
+def playlist_delete_videos(request, playlist_id, command):
     all = False
     num_vids = 0
     playlist_item_ids = []
@@ -693,12 +692,18 @@ def update_playlist_settings(request, playlist_id):
     playlist = request.user.playlists.get(playlist_id=playlist_id)
 
     if 'user_label' in request.POST:
-        playlist.user_label = request.POST["user_label"]
-        playlist.save(update_fields=['user_label'])
+        playlist.user_label = bleach.clean(request.POST["user_label"])
+
+    if 'pl-auto-update' in request.POST:
+        playlist.auto_check_for_updates = True
+    else:
+        playlist.auto_check_for_updates = False
+
+    playlist.save(update_fields=['auto_check_for_updates', 'user_label'])
 
     try:
-        valid_title = request.POST['playlistTitle'].replace(">", "greater than").replace("<", "less than")
-        valid_description = request.POST['playlistDesc'].replace(">", "greater than").replace("<", "less than")
+        valid_title = bleach.clean(request.POST['playlistTitle'])
+        valid_description = bleach.clean(request.POST['playlistDesc'])
         details = {
             "title": valid_title,
             "description": valid_description,
@@ -1062,7 +1067,7 @@ def playlist_move_copy_videos(request, playlist_id, action):
                                                              playlist_item_ids=playlist_item_ids,
                                                              action="move")
         if result['status'] == -1:
-            if status[1] == 404:
+            if result['status'] == 404:
                 return HttpResponse(
                     "<span class='text-danger'>You cannot copy/move unavailable videos! De-select them and try again.</span>")
             return HttpResponse("Error moving!")
@@ -1134,3 +1139,38 @@ def add_playlist_user_label(request, playlist_id):
         playlist.user_label = bleach.clean(request.POST["user_label"].strip())
         playlist.save(update_fields=['user_label'])
     return redirect('playlist', playlist_id=playlist_id)
+
+
+@login_required
+@require_POST
+def playlist_add_new_videos(request, playlist_id):
+    textarea_input = bleach.clean(request.POST["add-videos-textarea"])
+    video_links = textarea_input.strip().split("\n")[:25]
+
+    video_ids = []
+    for video_link in video_links:
+        if video_link.strip() == "":
+            continue
+        video_id = getVideoId(video_link)
+        if video_id is None or video_id in video_ids:
+            continue
+        video_ids.append(video_id)
+    result = Playlist.objects.addVideosToPlaylist(request.user, playlist_id, video_ids)
+    added = result["num_added"]
+    max_limit_reached = result["playlistContainsMaximumNumberOfVideos"]
+    if max_limit_reached and added == 0:
+        message = "Could not add any new videos to this playlist as the max limit has been reached :("
+        messages.error(request, message)
+    elif max_limit_reached and added != 0:
+        message = f"Only added the first {added} video link(s) to this playlist as the max playlist limit has been reached :("
+        messages.warning(request, message)
+    #else:
+    #    message = f"Successfully added {added} videos to this playlist."
+    #    messages.success(request, message)
+
+    return HttpResponse("""
+        Done! Refreshing...
+            <script>
+            window.location.reload();
+            </script>
+    """)

+ 2 - 2
apps/search/views.py

@@ -209,7 +209,7 @@ def search_library(request, library_type):
         return HttpResponse(loader.get_template("intercooler/video_cards.html").render({"videos": videos}))
 
     return HttpResponse(loader.get_template("intercooler/playlists.html")
-                        .render({"playlists": playlists,
+                        .render({"playlists": playlists.order_by("-updated_at"),
                                  "watching": watching}))
 
 
@@ -221,7 +221,7 @@ def search_tagged_playlists(request, tag):
         playlists = request.user.playlists.all().filter(Q(is_in_db=True) & Q(tags__name=tag)).filter(
             Q(name__startswith=search_query) | Q(user_label__startswith=search_query))
     except:
-        playlists = request.user.playlists.all().filter(Q(is_in_db=True) & Q(tags__name=tag))
+        playlists = request.user.playlists.all().filter(Q(is_in_db=True) & Q(tags__name=tag)).order_by("-updated_at")
 
     return HttpResponse(loader.get_template("intercooler/playlists.html")
                         .render({"playlists": playlists}))

+ 2 - 2
apps/users/templates/settings.html

@@ -27,7 +27,7 @@
               {% endif %}
 
       <div class="row g-5">
-        <div class="col-md-4 mb-3 d-flex justify-content-start">
+        <div class="col-md-3 mb-3 d-flex justify-content-start">
           <h1><span style="border-bottom: 3px #a35a5a dashed;">User Settings</span></h1>
           <div class="card bg-dark text-white visually-hidden">
             <div class="card-body">
@@ -75,7 +75,7 @@
           </div>
 
         </div>
-        <div class="col-md-8">
+        <div class="col-md-9">
 
           <div class="card bg-dark text-white mb-3">
             <div class="card-body">

+ 16 - 10
apps/users/views.py

@@ -86,29 +86,35 @@ def update_settings(request):
             message_content = f"Username updated to {username_input}!"
             messages.success(request, message_content)
 
-    if 'open search in new tab' in request.POST:
+    if 'open search in new tab' in request.POST and user.profile.open_search_new_tab is False:
         user.profile.open_search_new_tab = True
-    else:
+    elif 'open search in new tab' not in request.POST and user.profile.open_search_new_tab is True:
         user.profile.open_search_new_tab = False
 
-    if 'enable gradient bg' in request.POST:
+    if 'enable gradient bg' in request.POST and user.profile.enable_gradient_bg is False:
         user.profile.enable_gradient_bg = True
-    else:
+    elif 'enable gradient bg' not in request.POST and user.profile.enable_gradient_bg is True:
         user.profile.enable_gradient_bg = False
 
-    if 'auto refresh playlists' in request.POST:
+    if 'auto refresh playlists' in request.POST and user.profile.auto_check_for_updates is False:
         user.profile.auto_check_for_updates = True
-    else:
+        for playlist in user.playlists.all():
+            playlist.auto_check_for_updates = True
+            playlist.save(update_fields=['auto_check_for_updates'])
+    elif 'auto refresh playlists' not in request.POST and user.profile.auto_check_for_updates is True:
         user.profile.auto_check_for_updates = False
+        for playlist in user.playlists.all():
+            playlist.auto_check_for_updates = False
+            playlist.save(update_fields=['auto_check_for_updates'])
 
-    if 'confirm before deleting' in request.POST:
+    if 'confirm before deleting' in request.POST and user.profile.confirm_before_deleting is False:
         user.profile.confirm_before_deleting = True
-    else:
+    elif 'confirm before deleting' not in request.POST and user.profile.confirm_before_deleting is True:
         user.profile.confirm_before_deleting = False
 
-    if 'hide videos' in request.POST:
+    if 'hide videos' in request.POST and user.profile.hide_unavailable_videos is False:
         user.profile.hide_unavailable_videos = True
-    else:
+    elif 'hide videos' not in request.POST and user.profile.hide_unavailable_videos is True:
         user.profile.hide_unavailable_videos = False
 
     user.save()