瀏覽代碼

implemented modify and delete existing tags feature

sleepytaco 3 年之前
父節點
當前提交
da7c2f7401

+ 2 - 2
apps/main/models.py

@@ -979,8 +979,8 @@ class PlaylistManager(models.Manager):
 
                 if not playlist.playlist_items.filter(video__video_id=video.video_id).exists():
                     playlist.videos.remove(video)
-                    if video.playlists.all().count() == 0:  # also delete the video if it is not found in other playlists
-                        video.delete()
+                    #if video.playlists.all().count() == 0:  # also delete the video if it is not found in other playlists
+                    #    video.delete()
 
                 if playlist_id == "LL":
                     video.liked = False

+ 31 - 2
apps/main/templates/all_playlists_with_tag.html

@@ -2,10 +2,39 @@
 {% extends 'base.html' %}
 {% block content %}
 
+        <div class="alert alert-dark alert-dismissible fade show" role="alert" id="user-label-alert"  style="display:none;">
+            <form method="post" action="{% url 'edit_tag' tag.name %}" class="d-flex justify-content-center">
+                {% csrf_token %}
+                <span class="mt-2 me-1">Edit this tag's name:</span>
+                <input class="form-control w-25 me-2" type="text" placeholder="Enter here" name="tag_name" value="{{ tag.name }}" aria-label="user label">
+                <button type="submit" class="btn btn-primary">Update</button>
 
-        <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 mb-3">
-            <h1 class="h2"> <span style="border-bottom: 3px #e24949 dashed;" class="pt-3">Playlists Tagged as</span> <kbd>{{ tag.name }}</kbd> <span class="badge bg-warning rounded-pill">{{ playlists.count }}</span> </h1>
+            </form>
+            <button type="button" class="btn-close mt-2 me-2" onclick='document.getElementById("user-label-alert").style.display = "none";' aria-label="Close"></button>
+
+        </div>
+
+        <div class="alert alert-dark alert-dismissible fade show" role="alert" id="user-delete-alert"  style="display:none;">
+            <form method="post" action="{% url 'delete_tag' tag.name %}" class="d-flex justify-content-center">
+                {% csrf_token %}
+                <span class="mt-2 me-1">Are you sure you want to delete this tag{% if playlists.count != 0 %} and remove it from all the playlists below{% endif %}?</span>
+                <br>
+                <button type="submit" class="btn btn-danger btn-sm mt-1">Yes, delete it</button>
 
+            </form>
+            <button type="button" class="btn-close mt-2 me-2" onclick='document.getElementById("user-label-alert").style.display = "none";' aria-label="Close"></button>
+
+        </div>
+
+        <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 mb-3">
+            <h1 class="h2"> <span style="border-bottom: 3px #e24949 dashed;" class="pt-3">Playlists Tagged as</span> <kbd>{{ tag.name }}</kbd> <span class="badge bg-warning rounded-pill">{{ playlists.count }}</span>
+                <a href="#" style="text-decoration: none; color: black">
+                <i class="fas fa-pencil-alt fa-sm" onclick='document.getElementById("user-label-alert").style.display = "block";document.getElementById("user-delete-alert").style.display = "none";'></i>
+                </a>
+            </h1>
+            <a href="#" style="text-decoration: none; color: darkred">
+            <h1 class="h2"><i class="fas fa-trash-alt fa-sm me-2" style="color: darkred" onclick='document.getElementById("user-delete-alert").style.display = "block";document.getElementById("user-label-alert").style.display = "none";'></i></h1>
+            </a>
         </div>
 
         {% if playlists %}

+ 5 - 0
apps/main/templates/home.html

@@ -201,9 +201,14 @@
                         <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>
                     {% endfor %}
+
                     </div>
                     {% else %}
+                        {% if user.playlist_tags.all.count != 0 %}
+                        No playlist tag views this week.
+                        {% else %}
                         You haven't created any playlist tags yet.
+                            {% endif %}
                     {% endif %}
                 </div>
             {% if playlist_tags %}

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

@@ -148,7 +148,6 @@
                 <div class="d-flex justify-content-center">
                     <h3>
                         <a href="{% url 'search' %}" class="btn btn-success">Filter Playlists by Tags</a>
-                        <a href="" class="btn btn-danger">Edit Tags</a>
                     </h3>
                 </div>
             </div>

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

@@ -34,7 +34,7 @@
             {% else %}
                 <div class="sticky-top mb-3" style="top: 0.5rem;">
                     {% if not playlist.is_yt_mix %}
-                        {% if user.profile.auto_check_for_updates or playlist.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...

+ 3 - 1
apps/main/templates/view_video.html

@@ -127,7 +127,7 @@
                                     <span class="badge bg-info text-black-50 mb-1"><i class="fas fa-comments"></i> {% if video.comment_count == -1 %}HIDDEN{% else %}{{ video.comment_count|intcomma }}{% endif %} </span>
                                 {% endif %}
                                     {% if video.is_unavailable_on_yt or video.was_deleted_on_yt %}<span class="badge bg-danger text-light mb-1">VIDEO WENT UNAVAILABLE ON YT</span>{% endif %}
-                                    <span class="badge bg-light text-black-50 mb-1"><a href="#found-in" style="text-decoration: none; color: grey"> Found in {{ video.playlists.all.count }} playlist{% if video.playlists.all.count > 1 %}s{% endif %}</a></span>
+                                    <span class="badge bg-light text-black-50 mb-1"><a href="#found-in" style="text-decoration: none; color: grey"> Found in {{ video.playlists.all.count }} playlist{% if video.playlists.all.count > 1 or video.playlists.all.count == 0 %}s{% endif %}</a></span>
                                     {% if video.is_marked_as_watched %}
                                         <span class="badge bg-dark text-white" >
 
@@ -190,12 +190,14 @@
 
     <br>
 
+    {% if video.playlists.all.count != 0 %}
     <div class="">
         <h3><span style="border-bottom: 3px #497ce2 dashed;">Video found in the following playlist{% if video.playlists.all.count > 1 %}s{% endif %}</span><i class="fas fa-binoculars ms-2" style="color: #4669d2"></i></h3>
         <div id="found-in" class="row row-cols-1 row-cols-md-4 g-4 text-dark mt-0" data-masonry='{"percentPosition": true }'>
             {% include 'intercooler/playlists.html' with playlists=video.playlists.all watching=False bg_color="#357779" show_controls=True %}
         </div>
     </div>
+    {% endif %}
 
 
 

+ 3 - 0
apps/main/urls.py

@@ -56,4 +56,7 @@ urlpatterns = [
     ### STUFF RELATED TO PLAYLISTS IN BULK
     path("playlists/<slug:playlist_type>/order-by/<slug:order_by>", views.order_playlists_by, name='order_playlists_by'),
     path("playlists/tag/<str:tag>", views.tagged_playlists, name='tagged_playlists'),
+    path("playlists/tag/<str:tag>/edit", views.edit_tag, name='edit_tag'),
+    path("playlists/tag/<str:tag>/delete", views.delete_tag, name='delete_tag'),
+
 ]

+ 38 - 15
apps/main/views.py

@@ -58,7 +58,7 @@ def home(request):
         return render(request, "import_in_progress.html")
     ##################################
 
-    playlist_tags = request.user.playlist_tags.order_by('-times_viewed')
+    playlist_tags = request.user.playlist_tags.filter(times_viewed_per_week__gte=1).order_by('-times_viewed_per_week')
 
     videos = request.user.videos.filter(Q(is_unavailable_on_yt=False) & Q(was_deleted_on_yt=False))
 
@@ -78,7 +78,7 @@ def home(request):
 def favorites(request):
     favorite_playlists = request.user.playlists.filter(Q(is_favorite=True) & Q(is_in_db=True)).order_by(
         '-last_accessed_on')
-    favorite_videos = request.user.videos.filter(is_favorite=True).order_by('updated_at')
+    favorite_videos = request.user.videos.filter(is_favorite=True).order_by('-num_of_accesses')
 
     return render(request, 'favorites.html', {"playlists": favorite_playlists,
                                               "videos": favorite_videos})
@@ -86,13 +86,13 @@ def favorites(request):
 
 @login_required
 def planned_to_watch(request):
-    planned_to_watch_playlists = request.user.playlists.filter(Q(marked_as='plan-to-watch') & Q(is_in_db=True)).order_by(
+    planned_to_watch_playlists = request.user.playlists.filter(
+        Q(marked_as='plan-to-watch') & Q(is_in_db=True)).order_by(
         '-last_accessed_on')
-    planned_to_watch_videos = request.user.videos.filter(is_planned_to_watch=True).order_by('updated_at')
+    planned_to_watch_videos = request.user.videos.filter(is_planned_to_watch=True).order_by('-num_of_accesses')
 
     return render(request, 'planned_to_watch.html', {"playlists": planned_to_watch_playlists,
-                                              "videos": planned_to_watch_videos})
-
+                                                     "videos": planned_to_watch_videos})
 
 
 @login_required
@@ -192,8 +192,6 @@ 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)
@@ -540,7 +538,6 @@ def mark_video_planned_to_watch(request, video_id):
         return HttpResponse('<i class="fas fa-clock" style="color: #000000"></i>')
 
 
-
 @login_required
 def mark_video_watched(request, playlist_id, video_id):
     playlist = request.user.playlists.get(playlist_id=playlist_id)
@@ -565,7 +562,6 @@ def mark_video_watched(request, playlist_id, video_id):
 ###########
 
 
-
 @login_required
 def load_more_videos(request, playlist_id, order_by, page):
     playlist = request.user.playlists.get(playlist_id=playlist_id)
@@ -897,12 +893,15 @@ def add_playlist_tag(request, playlist_id):
     if tag_name == 'Pick from existing unused tags':
         return HttpResponse("Pick something! >w<")
 
+    try:
+        tag = request.user.playlist_tags.get(name__iexact=tag_name)
+    except:
+        return HttpResponse("Uh-oh, looks like this tag was deleted :(")
+
     playlist = request.user.playlists.get(playlist_id=playlist_id)
 
     playlist_tags = playlist.tags.all()
     if not playlist_tags.filter(name__iexact=tag_name).exists():  # tag not on this playlist, so add it
-        tag = Tag.objects.filter(Q(created_by=request.user) & Q(name__iexact=tag_name)).first()
-
         # add it to playlist
         playlist.tags.add(tag)
     else:
@@ -1074,6 +1073,28 @@ def add_video_user_label(request, video_id):
     return redirect('video', video_id=video_id)
 
 
+@login_required
+@require_POST
+def edit_tag(request, tag):
+    tag = request.user.playlist_tags.get(name=tag)
+
+    if 'tag_name' in request.POST:
+        tag.name = bleach.clean(request.POST["tag_name"])
+        tag.save(update_fields=['name'])
+        messages.success(request, "Successfully updated the tag's name!")
+
+    return redirect('tagged_playlists', tag=tag.name)
+
+
+@login_required
+@require_POST
+def delete_tag(request, tag):
+    tag = request.user.playlist_tags.get(name__iexact=tag)
+    tag.delete()
+    messages.success(request, f"Successfully deleted the tag '{tag.name}'")
+    return redirect('/library/home')
+
+
 @login_required
 @require_POST
 def add_playlist_user_label(request, playlist_id):
@@ -1107,7 +1128,7 @@ def playlist_add_new_videos(request, playlist_id):
     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:
+    # else:
     #    message = f"Successfully added {added} videos to this playlist."
     #    messages.success(request, message)
 
@@ -1118,6 +1139,7 @@ def playlist_add_new_videos(request, playlist_id):
             </script>
     """)
 
+
 @login_required
 @require_POST
 def playlist_create_new_playlist(request, playlist_id):
@@ -1128,7 +1150,8 @@ def playlist_create_new_playlist(request, playlist_id):
 
     unclean_playlist_item_ids = request.POST.getlist("video-id", default=[])
     clean_playlist_item_ids = [bleach.clean(playlist_item_id) for playlist_item_id in unclean_playlist_item_ids]
-    playlist_items = request.user.playlists.get(playlist_id=playlist_id).playlist_items.filter(playlist_item_id__in=clean_playlist_item_ids)
+    playlist_items = request.user.playlists.get(playlist_id=playlist_id).playlist_items.filter(
+        playlist_item_id__in=clean_playlist_item_ids)
 
     if not playlist_items.exists():
         return HttpResponse("Select some videos first!")
@@ -1154,4 +1177,4 @@ def playlist_create_new_playlist(request, playlist_id):
     else:
         message = f"""Successfully created '{playlist_name}' and added {added} videos to it. Visit the <a href="/home/" target="_blank" style="text-decoration: none; color: white" class="ms-1 me-1">dashboard</a> to import it into UnTube."""
 
-    return HttpResponse(message)
+    return HttpResponse(message)

+ 1 - 0
apps/search/views.py

@@ -212,6 +212,7 @@ def search_library(request, library_type):
 
     return HttpResponse(loader.get_template("intercooler/playlists.html")
                         .render({"playlists": playlists.order_by("-updated_at"),
+                                 "show_controls": True,
                                  "watching": watching}))
 
 

+ 17 - 0
apps/users/migrations/0013_remove_profile_auto_check_for_updates.py

@@ -0,0 +1,17 @@
+# Generated by Django 3.2.3 on 2021-08-02 02:43
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('users', '0012_alter_profile_hide_unavailable_videos'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='profile',
+            name='auto_check_for_updates',
+        ),
+    ]

+ 0 - 1
apps/users/models.py

@@ -36,7 +36,6 @@ class Profile(models.Model):
     enable_gradient_bg = models.BooleanField(default=False)
 
     # playlist preferences (this will apply to all playlists)
-    auto_check_for_updates = models.BooleanField(default=False)
     hide_unavailable_videos = models.BooleanField(default=True)
     confirm_before_deleting = models.BooleanField(default=True)
     ###########################

+ 1 - 7
apps/users/templates/settings.html

@@ -127,17 +127,11 @@
                         <label class="form-check-label" for="gradient-bg">Use a gradient background</label>
                         </div>
 
-                        <div class="mb-3 form-check form-switch">
-                        <input class="form-check-input" name="auto refresh playlists" type="checkbox" id="auto-update-playlists" {% if user.profile.auto_check_for_updates %}checked{% endif %}>
-                        <label class="form-check-label" for="auto-update-playlists" >Automatically check for playlist updates on visit (this might slow down the playlist page for a bit)</label>
-                        </div>
-
                         <div class="mb-3 form-check form-switch">
                         <input class="form-check-input" name="hide videos" type="checkbox" id="hide-videos" {% if user.profile.hide_unavailable_videos %}checked{% endif %}>
                         <label class="form-check-label" for="hide-videos">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="confirm-before-delete" {% if user.profile.confirm_before_deleting  %}checked{% endif %}>
                         <label class="form-check-label" for="confirm-before-delete">Confirm before deleting</label>
@@ -150,7 +144,7 @@
               <div class="row">
                 <div class="col-sm-12">
 
-                    <button type="submit" class="btn btn-success">Save</button>
+                    <button type="submit" class="btn btn-success me-1">Save</button>
                     <a class="btn btn-outline-danger" href="{% url 'delete_account' %}">Delete UnTube account</a>
 
                 </div>

+ 0 - 11
apps/users/views.py

@@ -100,17 +100,6 @@ def update_settings(request):
     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 and user.profile.auto_check_for_updates is False:
-        user.profile.auto_check_for_updates = True
-        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 and user.profile.confirm_before_deleting is False:
         user.profile.confirm_before_deleting = True
     elif 'confirm before deleting' not in request.POST and user.profile.confirm_before_deleting is True: