Przeglądaj źródła

confirm delete and hide unavailable implemented in playlist settings

sleepytaco 3 lat temu
rodzic
commit
aba7439186

+ 23 - 0
apps/main/migrations/0019_pin.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.2.3 on 2021-07-12 01:50
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('main', '0018_tag_times_viewed'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Pin',
+            fields=[
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('type', models.CharField(max_length=100)),
+                ('playlist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.playlist')),
+                ('video', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.video')),
+            ],
+        ),
+    ]

+ 23 - 0
apps/main/migrations/0020_auto_20210712_1246.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.2.3 on 2021-07-12 17:46
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('main', '0019_pin'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='playlist',
+            old_name='view_in_grid_mode',
+            new_name='confirm_before_deleting',
+        ),
+        migrations.AddField(
+            model_name='playlist',
+            name='hide_unavailable_videos',
+            field=models.BooleanField(default=False),
+        ),
+    ]

+ 18 - 0
apps/main/migrations/0021_alter_playlist_confirm_before_deleting.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.2.3 on 2021-07-12 17:49
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('main', '0020_auto_20210712_1246'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='playlist',
+            name='confirm_before_deleting',
+            field=models.BooleanField(default=True),
+        ),
+    ]

+ 15 - 5
apps/main/models.py

@@ -972,9 +972,10 @@ class PlaylistManager(models.Manager):
                 pl_request = youtube.playlistItems().delete(
                     id=playlist_item_id
                 )
-
+                print(pl_request)
                 try:
                     pl_response = pl_request.execute()
+                    print(pl_response)
                 except googleapiclient.errors.HttpError as e:  # failed to delete playlist item
                     # possible causes:
                     # playlistItemsNotAccessible (403)
@@ -1093,12 +1094,13 @@ class Playlist(models.Model):
 
     has_playlist_changed = models.BooleanField(default=False)  # determines whether playlist was modified online or not
 
-    # for UI
-    view_in_grid_mode = models.BooleanField(default=False)  # if False, videso will be showed in a list
-
     # set playlist manager
     objects = PlaylistManager()
 
+    # playlist settings
+    hide_unavailable_videos = models.BooleanField(default=False)
+    confirm_before_deleting = models.BooleanField(default=True)
+
     # for import
     is_in_db = models.BooleanField(default=False)  # is true when all the videos of a playlist have been imported
     created_at = models.DateTimeField(auto_now_add=True)
@@ -1119,7 +1121,8 @@ class Playlist(models.Model):
         return self.videos.filter(Q(is_unavailable_on_yt=False) & Q(was_deleted_on_yt=False)).count()
 
     def get_watched_videos_count(self):
-        return self.videos.filter(Q(is_marked_as_watched=True) & Q(is_unavailable_on_yt=False) & Q(was_deleted_on_yt=False)).count()
+        return self.videos.filter(
+            Q(is_marked_as_watched=True) & Q(is_unavailable_on_yt=False) & Q(was_deleted_on_yt=False)).count()
 
     # diff of time from when playlist was first marked as watched and playlist reached 100% completion
     def get_finish_time(self):
@@ -1153,6 +1156,7 @@ class Playlist(models.Model):
             all_vids_unavailable = True
         return all_vids_unavailable
 
+
 class Video(models.Model):
     playlist_item_id = models.CharField(max_length=100)  # the item id of the playlist this video beo
 
@@ -1234,3 +1238,9 @@ class PlaylistItem(models.Model):
 
     created_at = models.DateTimeField(auto_now_add=True)
     updated_at = models.DateTimeField(auto_now=True)
+
+
+class Pin(models.Model):
+    type = models.CharField(max_length=100)  # "playlist", "video"
+    playlist = models.ForeignKey(Playlist, on_delete=models.CASCADE)
+    video = models.ForeignKey(Video, on_delete=models.CASCADE)

+ 183 - 98
apps/main/templates/home.html

@@ -52,7 +52,61 @@
             </div>
             {% endif %}
 
+            <div class="row row-cols-1 row-cols-md-4 g-4 text-dark d-flex justify-content-center">
+                <div class="col">
+                    <div class="card">
+                        <a style="background: linear-gradient(-45deg, #ae6ba3, #ab7b91, #bc8a9a, #d69aa1); background-size: 400% 400%; animation: gradient 7s ease infinite;" href="#" class="list-group-item list-group-item-action" aria-current="true">
+                            <div class="card-body">
+                                <div class="d-flex justify-content-center h1">
+                                    <i class="fas fa-map-pin"></i>
+                                </div>
+                                <div class="d-flex justify-content-center h1">
+                                    YOUR
+                                </div>
+                                <div class="d-flex justify-content-center h1">
+                                    PINS
+                                </div>
+                            </div>
+                        </a>
+                    </div>
+                </div>
+                <div class="col">
+                    <div class="card">
+                        <a style="background: linear-gradient(-45deg, #0645a4, #2480cd, #84bcf3, #b7d6f7); background-size: 400% 400%; animation: gradient 7s ease infinite;" href="#" class="list-group-item list-group-item-action" aria-current="true">
+                            <div class="card-body">
+                                <div class="d-flex justify-content-center h1">
+                                    <i class="fas fa-thumbs-up"></i>
+                                </div>
+                                <div class="d-flex justify-content-center h1">
+                                    LIKED
+                                </div>
+                                <div class="d-flex justify-content-center h1">
+                                    VIDEOS
+                                </div>
+                            </div>
+                        </a>
+                    </div>
+                </div>
+                <div class="col">
+                    <div class="card">
+                        <a style="background: linear-gradient(-45deg, #e2b968, #68af5b, #8a97bc, #d69ab2); background-size: 400% 400%; animation: gradient 7s ease infinite;" href="#" class="list-group-item list-group-item-action" aria-current="true">
+                            <div class="card-body">
+                                <div class="d-flex justify-content-center h1">
+                                    <i class="fas fa-history"></i>
+                                </div>
+                                <div class="d-flex justify-content-center h1">
+                                    YOUR
+                                </div>
+                                <div class="d-flex justify-content-center h1">
+                                    ACTIVITY
+                                </div>
+                            </div>
+                        </a>
+                    </div>
+                </div>
 
+            </div>
+            <br>
 
             {% if watching %}
                 <div class="border border-5 rounded-3 border-primary p-3">
@@ -107,127 +161,158 @@
             </div>
             </div>
                 <br>
-                {% endif %}
+            {% endif %}
+
+
+
 
-            <h3><span style="border-bottom: 3px #ffffff dashed;">Most viewed playlists</span> <a href="{% url 'all_playlists' 'all' %}" class="pt-1"><i class="fas fa-binoculars"></i> </a></h3>
-            {% if user_playlists %}
-            <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
-                {% for playlist in user_playlists|slice:"0:3" %}
+
+           <div class="row text-dark mt-0 d-flex justify-content-evenly">
                 <div class="col">
-                    <div class="card">
-                        <a style="background-color: #35795b;" 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">
-                           #{{ forloop.counter }} <br><br>{{ playlist.name }}
-                            {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
-                            {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
-                        </h5>
-                        <p class="card-text">
-                            {% if playlist.description %}
-                                {{ playlist.description|truncatewords:"15" }}
-                            {% else %}
-                                No description
-                            {% endif %}
-                        </p>
-                        <small>
-                            <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
-                            <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
-                            <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
+                  <div class="card bg-dark text-white">
+                        <div class="card-body">
+                          <h6 class="d-flex align-items-center mb-3"><span class="text-info me-2">{{ user.profile.playlists.count }}</span>Playlists Statistics</h6>
 
-                        </small>
+                          <small>Public <span class="text-warning ms-1">{{ statistics.public_x }}%</span></small>
+                          <div class="progress mb-3" style="height: 5px">
+                            <div class="progress-bar bg-primary" role="progressbar" style="width: {{ statistics.public_x }}%" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100"></div>
+                          </div>
+
+                          <small>Private <span class="text-warning ms-1">{{ statistics.private_x }}%</span></small>
+                          <div class="progress mb-3" style="height: 5px">
+                            <div class="progress-bar bg-primary" role="progressbar" style="width: {{ statistics.private_x }}%" aria-valuenow="72" aria-valuemin="0" aria-valuemax="100"></div>
+                          </div>
+                          <small>Favorites <span class="text-warning ms-1">{{ statistics.favorites_x }}%</span></small>
+                          <div class="progress mb-3" style="height: 5px">
+                            <div class="progress-bar bg-primary" role="progressbar" style="width: {{ statistics.favorites_x }}%" aria-valuenow="89" aria-valuemin="0" aria-valuemax="100"></div>
+                          </div>
+                          <small>Watching <span class="text-warning ms-1">{{ statistics.watching_x }}%</span></small>
+                          <div class="progress mb-3" style="height: 5px">
+                            <div class="progress-bar bg-primary" role="progressbar" style="width: {{ statistics.watching_x }}%" aria-valuenow="55" aria-valuemin="0" aria-valuemax="100"></div>
+                          </div>
+                          <small>Imported <span class="text-warning ms-1">{{ statistics.imported_x }}%</span></small>
+                          <div class="progress mb-3" style="height: 5px">
+                            <div class="progress-bar bg-primary" role="progressbar" style="width: {{ statistics.imported_x }}%" aria-valuenow="66" aria-valuemin="0" aria-valuemax="100"></div>
+                          </div>
                         </div>
-                        </a>
-                    </div>
+                      </div>
+
                 </div>
-                {% endfor %}
+               <div class="col">
+                  <div class="card bg-transparent text-black border border-5 rounded-3 border-success p-3">
+                        <div class="card-body">
+                              <h3><span style="border-bottom: 3px #ffffff dashed;">Most viewed playlists</span> <a href="{% url 'all_playlists' 'all' %}" class="pt-1"><i class="fas fa-binoculars"></i> </a></h3>
+                                {% if user_playlists %}
+                                <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
+                                    {% for playlist in user_playlists|slice:"0:3" %}
+                                    <div class="col">
+                                        <div class="card">
+                                            <a style="background-color: #4790c7;" 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">
+                                               #{{ forloop.counter }} <br><br>{{ playlist.name }}
+                                                {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
+                                                {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
+                                            </h5>
+                                            <small>
+                                                <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
+                                                <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
+                                                <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
 
-            </div>
+                                            </small>
+                                            </div>
+                                            </a>
+                                        </div>
+                                    </div>
+                                    {% endfor %}
 
-            {% else %}
-                <br>
-            <h5>Nothing to see here... yet.</h5>
-            {% endif %}
+                                </div>
 
+                                {% else %}
+                                    <br>
+                                <h5>Nothing to see here... yet.</h5>
+                                {% endif %}
 
-        <br>
-            <h3><span style="border-bottom: 3px #ffffff dashed;">Recently Accessed</span> <i class="fas fa-redo fa-sm" style="color: #3c3fd2"></i></h3>
-
-            {% if recently_accessed_playlists %}
-            <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
-                {% for playlist in recently_accessed_playlists %}
-                <div class="col">
-                    <div class="card">
-                        <a style="background-color: #357779;" 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">
-                           {{ playlist.name }}
-                            {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
-                            {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
-                        </h5>
-                        <p class="card-text">
-                            {% if playlist.description %}
-                                {{ playlist.description|truncatewords:"15" }}
-                            {% else %}
-                                No description
-                            {% endif %}
-                        </p>
-                        <small>
-                            <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
-                            <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
-                            <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
 
-                        </small>
                         </div>
-                        </a>
-                    </div>
+                      </div>
                 </div>
-                {% endfor %}
             </div>
-            {% else %}
+
             <br>
-            <h5>Nothing to see here... yet.</h5>
-            {% endif %}
 
-        <br>
-            <h3><span style="border-bottom: 3px #ffffff dashed;">Recently Added</span> <i class="fas fa-plus-square" style="color:#972727;"></i></h3>
-            {% if recently_added_playlists %}
-            <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
-                {% for playlist in recently_added_playlists %}
+           <div class="row text-dark mt-0 d-flex justify-content-evenly">
+               <div class="col">
+
+                <h3><span style="border-bottom: 3px #ffffff dashed;">Recently Added</span> <i class="fas fa-plus-square" style="color:#972727;"></i></h3>
+                {% if recently_added_playlists %}
+                    <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
+                        {% for playlist in recently_added_playlists %}
+                        <div class="col">
+                            <div class="card">
+                                <a style="background-color: #958a44;" 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">
+                                   {{ playlist.name }}
+                                    {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
+                                    {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
+                                </h5>
+                                <small>
+                                    <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
+                                    <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
+                                    <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
+
+                                </small>
+                                </div>
+                                </a>
+                            </div>
+                        </div>
+                        {% endfor %}
+                    </div>
+                     {% else %}
+                    <br>
+                    <h5>You have no playlists ;-;</h5>
+                    {% endif %}
+               </div>
+
                 <div class="col">
-                    <div class="card">
-                        <a style="background-color: #958a44;" 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">
-                           {{ playlist.name }}
-                            {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
-                            {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
-                        </h5>
-                        <p class="card-text">
-                            {% if playlist.description %}
-                                {{ playlist.description|truncatewords:"15" }}
-                            {% else %}
-                                No description
-                            {% endif %}
-                        </p>
-                        <small>
-                            <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
-                            <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
-                            <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
+                    <h3><span style="border-bottom: 3px #ffffff dashed;">Recently Accessed</span> <i class="fas fa-redo fa-sm" style="color: #3c3fd2"></i></h3>
 
-                        </small>
+                    {% if recently_accessed_playlists %}
+                    <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
+                        {% for playlist in recently_accessed_playlists %}
+                        <div class="col">
+                            <div class="card">
+                                <a style="background-color: #357779;" 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">
+                                   {{ playlist.name }}
+                                    {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
+                                    {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
+                                </h5>
+                                <small>
+                                    <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
+                                    <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
+                                    <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
+
+                                </small>
+                                </div>
+                                </a>
+                            </div>
                         </div>
-                        </a>
+                        {% endfor %}
                     </div>
+                    {% else %}
+                    <br>
+                    <h5>Nothing to see here... yet.</h5>
+                    {% endif %}
+
                 </div>
-                {% endfor %}
             </div>
-             {% else %}
-            <br>
-            <h5>You have no playlists ;-;</h5>
-            {% endif %}
-        <br>
 
 
+            <br>
+            <br>
         {% endif %}
 
 

+ 14 - 3
apps/main/templates/view_playlist.html

@@ -53,11 +53,19 @@
                     </span>
                     {% endif %}
                 </span>
+                <span id="">
+                    <span class="badge bg-dark">
+                        <i class="fas fa-map-pin"></i>
+                    </span>
+                </span>
             </h4>
         </div>
         <p class="mb-1">
             {% if playlist.description %}
-            <h5>{{ playlist.description|truncatewords:"50"|linebreaksbr }}</h5>
+            <h5 class="overflow-auto" {% if playlist.description|length > 750 %} style="height: 150px;"{% endif %}>
+                {{ playlist.description|linebreaksbr }}
+            </h5>
+
             {% else %}
             <h5>No description</h5>
             {% endif %}
@@ -323,11 +331,14 @@
           <div class="collapse border-danger" id="deleteItemsCollapse">
               <div class="card card-body bg-dark text-white-50">
                   <div id="delete-videos-confirm-box">
+                      {% if not playlist.confirm_before_deleting %}
+                          <h5>Note: You have set confirm before deleting to False. Buttons below will take effect immediately when clicked.</h5>
+                          <hr>
+                      {% endif %}
                     </div>
-                <br>
                   <div class="d-flex justify-content-start">
                       <div class="btn-group me-2">
-                        <button hx-post="{% url 'delete_videos' playlist.playlist_id 'confirm' %}" hx-include="[id='video-checkboxes']" hx-target="#delete-videos-confirm-box" type="button" class="btn btn-primary">
+                        <button hx-post="{% url 'delete_videos' playlist.playlist_id 'confirm' %}" hx-include="[id='video-checkboxes']" hx-vals='{"confirm before deleting": "{{ playlist.confirm_before_deleting }}"}' hx-target="#delete-videos-confirm-box" type="button" class="btn btn-primary">
                             Delete Selected
                         </button>
                       </div>

+ 2 - 2
apps/main/templates/view_playlist_settings.html

@@ -70,13 +70,13 @@
                         <div class="col-sm-9 text-white">
 
                             <div class="mb-3 form-check form-switch">
-                            <input class="form-check-input" name="hide videos" type="checkbox" id="flexSwitchCheckChecked" checked>
+                            <input class="form-check-input" name="hide videos" type="checkbox" id="flexSwitchCheckChecked" {% if playlist.hide_unavailable_videos %}checked{% endif %}>
                             <label class="form-check-label" for="flexSwitchCheckChecked">Hide deleted/private videos</label>
                             </div>
 
 
                             <div class="mb-3 form-check form-switch">
-                            <input class="form-check-input" name="confirm before deleting" type="checkbox" id="flexSwitchCheckChecked" checked>
+                            <input class="form-check-input" name="confirm before deleting" type="checkbox" id="flexSwitchCheckChecked" {% if playlist.confirm_before_deleting %}checked{% endif %}>
                             <label class="form-check-label" for="flexSwitchCheckChecked">Confirm before deleting</label>
                             </div>
                         </div>

+ 59 - 10
apps/main/views.py

@@ -77,13 +77,33 @@ def home(request):
 
         print("TESTING")
 
+    user_playlists = request.user.profile.playlists.filter(is_in_db=True)
+    total_num_playlists = user_playlists.count()
+
+    statistics = {
+        "public_x": 0,
+        "private_x": 0,
+        "favorites_x": 0,
+        "watching_x": 0,
+        "imported_x": 0
+    }
+
+    if total_num_playlists != 0:
+        # x means  percentage
+        statistics["public_x"] = round(user_playlists.filter(is_private_on_yt=False).count() / total_num_playlists, 1) * 100
+        statistics["private_x"] = round(user_playlists.filter(is_private_on_yt=True).count() / total_num_playlists, 1) * 100
+        statistics["favorites_x"] = round(user_playlists.filter(is_favorite=True).count() / total_num_playlists, 1) * 100
+        statistics["watching_x"] = round(user_playlists.filter(marked_as="watching").count() / total_num_playlists, 1) * 100
+        statistics["imported_x"] = round(user_playlists.filter(is_user_owned=False).count() / total_num_playlists, 1) * 100
+
     return render(request, 'home.html', {"channel_found": channel_found,
                                          "playlist": playlist,
                                          "videos": videos,
                                          "user_playlists": user_playlists,
                                          "watching": watching,
                                          "recently_accessed_playlists": recently_accessed_playlists,
-                                         "recently_added_playlists": recently_added_playlists})
+                                         "recently_added_playlists": recently_added_playlists,
+                                         "statistics": statistics})
 
 
 @login_required
@@ -327,6 +347,12 @@ def order_playlist_by(request, playlist_id, order_by):
 
 @login_required
 def order_playlists_by(request, playlist_type, order_by):
+    print("GET", request.GET)
+    print("POST", request.POST)
+    print("CONTENT PARAMS", request.content_params)
+    print("HEAD", request.headers)
+    print("BODY", request.body)
+
     watching = False
 
     if playlist_type == "" or playlist_type.lower() == "all":
@@ -398,13 +424,20 @@ def playlists_home(request):
 def delete_videos(request, playlist_id, command):
     video_ids = request.POST.getlist("video-id", default=[])
 
+    print(request.POST)
+    num_vids = len(video_ids)
+    extra_text = " "
+    if num_vids == 0:
+        return HttpResponse("<h5>Select some videos first!</h5><hr>")
+
+    if 'confirm before deleting' in request.POST:
+        if request.POST['confirm before deleting'] == 'False':
+            command = "confirmed"
+
     if command == "confirm":
         print(video_ids)
-        num_vids = len(video_ids)
-        extra_text = " "
-        if num_vids == 0:
-            return HttpResponse("<h5>Select some videos first!</h5><hr>")
-        elif num_vids == request.user.profile.playlists.get(playlist_id=playlist_id).videos.all().count():
+
+        if num_vids == request.user.profile.playlists.get(playlist_id=playlist_id).videos.all().count():
             delete_text = "ALL VIDEOS"
             extra_text = " This will not delete the playlist itself, will only make the playlist empty. "
         else:
@@ -412,21 +445,24 @@ def delete_videos(request, playlist_id, command):
         return HttpResponse(
             f"""<h5>
                 Are you sure you want to delete {delete_text} from your YouTube playlist?{extra_text}This cannot be undone.</h5>
-                <button hx-post="/from/{playlist_id}/delete-videos/confirmed" hx-include="[id='video-checkboxes']" hx-target="#delete-videos-confirm-box" type="button" class="btn btn-outline-danger btn-sm" id="select-all-btn">Confirm</button>
+                <button hx-post="/from/{playlist_id}/delete-videos/confirmed" hx-include="[id='video-checkboxes']" hx-target="#delete-videos-confirm-box" type="button" class="btn btn-outline-danger btn-sm">Confirm</button>
                 <hr>
             """)
     elif command == "confirmed":
         print(video_ids)
         return HttpResponse(
-            f'<div class="spinner-border text-light" role="status" hx-post="/from/{playlist_id}/delete-videos/start" hx-trigger="load" hx-swap="outerHTML"></div>')
+            """
+            <div class="spinner-border text-light" role="status" hx-post="/from/""" + playlist_id + """/delete-videos/start" hx-trigger="load" hx-include="[id='video-checkboxes']" hx-target="#delete-videos-confirm-box" hx-vals="{'confirm before deleting': '""" + request.POST['confirm before deleting'] + """'}"></div><hr>
+            """)
     elif command == "start":
+        print("Deleting", len(video_ids), "videos")
         Playlist.objects.deletePlaylistItems(request.user, playlist_id, video_ids)
         # playlist = request.user.profile.playlists.get(playlist_id=playlist_id)
         # playlist.has_playlist_changed = True
         # playlist.save(update_fields=['has_playlist_changed'])
         return HttpResponse(f"""
         <h5 hx-get="/playlist/{playlist_id}/update/checkforupdates" hx-trigger="load delay:3s" hx-target="#checkforupdates">
-            Done deleting videos from your playlist on YouTube. Playlist on UnTube will update soon.
+            Done deleting selected videos from your playlist on YouTube. Playlist on UnTube will update soon.
         </h5>
         <hr>
         """)
@@ -710,8 +746,9 @@ def update_playlist_settings(request, playlist_id):
     message_type = "success"
     message_content = "Saved!"
 
+    print(request.POST)
+    playlist = request.user.profile.playlists.get(playlist_id=playlist_id)
     if "user_label" in request.POST:
-        playlist = request.user.profile.playlists.get(playlist_id=playlist_id)
         playlist.user_label = request.POST["user_label"]
         playlist.save(update_fields=['user_label'])
 
@@ -720,6 +757,18 @@ def update_playlist_settings(request, playlist_id):
             {"message_type": message_type,
              "message_content": message_content}))
 
+    if 'confirm before deleting' in request.POST:
+        playlist.confirm_before_deleting = True
+    else:
+        playlist.confirm_before_deleting = False
+
+    if 'hide videos' in request.POST:
+        playlist.hide_unavailable_videos = True
+    else:
+        playlist.hide_unavailable_videos = False
+
+    playlist.save(update_fields=['hide_unavailable_videos', 'confirm_before_deleting'])
+
     valid_title = request.POST['playlistTitle'].replace(">", "greater than").replace("<", "less than")
     valid_description = request.POST['playlistDesc'].replace(">", "greater than").replace("<", "less than")
     details = {

+ 23 - 0
apps/users/migrations/0008_auto_20210712_1246.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.2.3 on 2021-07-12 17:46
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('users', '0007_rename_just_joined_profile_show_import_page'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='profile',
+            old_name='hide_deleted_private_videos',
+            new_name='hide_unavailable_videos',
+        ),
+        migrations.AddField(
+            model_name='profile',
+            name='confirm_before_deleting',
+            field=models.BooleanField(default=True),
+        ),
+    ]

+ 4 - 1
apps/users/models.py

@@ -27,7 +27,10 @@ class Profile(models.Model):
 
     # preferences
     open_search_new_tab = models.BooleanField(default=True)  # open search page in new tab by default
-    hide_deleted_private_videos = models.BooleanField(default=False)
+
+    # global playlist preferences (this will make all playlists)
+    hide_unavailable_videos = models.BooleanField(default=False)
+    confirm_before_deleting = models.BooleanField(default=True)
 
     # manage user
     objects = ProfileManager()

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

@@ -107,7 +107,7 @@
 
                 <div class="row">
                     <div class="col-sm-3">
-                        <h6 class="mb-0">Preferences</h6>
+                        <h6 class="mb-0">Global Preferences</h6>
                     </div>
                     <div class="col-sm-9 text-white">
                         <div class="mb-3 form-check form-switch">
@@ -121,13 +121,13 @@
                         </div>
 
                         <div class="mb-3 form-check form-switch">
-                        <input class="form-check-input" name="hide videos" type="checkbox" id="flexSwitchCheckChecked" checked>
+                        <input class="form-check-input" name="hide videos" type="checkbox" id="flexSwitchCheckChecked" {% if profile.hide_unavailable_videos %}checked{% endif %}>
                         <label class="form-check-label" for="flexSwitchCheckChecked">Hide deleted/private videos</label>
                         </div>
 
 
                         <div class="mb-3 form-check form-switch">
-                        <input class="form-check-input" name="confirm before deleting" type="checkbox" id="flexSwitchCheckChecked" checked>
+                        <input class="form-check-input" name="confirm before deleting" type="checkbox" id="flexSwitchCheckChecked" {% if profile.confirm_before_deleting  %}checked{% endif %}>
                         <label class="form-check-label" for="flexSwitchCheckChecked">Confirm before deleting</label>
                         </div>
                     </div>

+ 2 - 1
templates/base.html

@@ -14,7 +14,8 @@
 
         <style type="text/css">
             body {
-                background: linear-gradient(-45deg, #B2A3FF, #84bcf3, #AE876B, #B0E7AE);
+                background: linear-gradient(-45deg, #e2b968, #68af5b, #8a97bc, #d69ab2);
+                //background: linear-gradient(-45deg, #B2A3FF, #84bcf3, #AE876B, #B0E7AE);
                 //background: linear-gradient(-45deg, #0645a4, #2480cd, #84bcf3, #b7d6f7);
                 //background: linear-gradient(-45deg, #AE876B, #ABA27B, #A7BC8A, #A3D69A);
                 background-size: 400% 400%;