From 793d1d033a0647754f2b0e903de64286f36b9f33 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 15 Feb 2024 13:29:30 +0000 Subject: [PATCH] Fixup. Format code with Black --- pod/video/admin.py | 2 ++ pod/video/models.py | 2 ++ pod/video/tests/test_views.py | 27 ++++++--------------------- pod/video/urls.py | 2 +- pod/video/views.py | 30 +++++++++++++----------------- 5 files changed, 24 insertions(+), 39 deletions(-) diff --git a/pod/video/admin.py b/pod/video/admin.py index 5fb880d522..758c511581 100644 --- a/pod/video/admin.py +++ b/pod/video/admin.py @@ -662,6 +662,7 @@ def get_queryset(self, request): class CategoryAdmin(admin.ModelAdmin): """Admin for the Category model.""" + list_display = ("title", "owner", "videos_count") readonly_fields = ("slug",) # list_filter = ["owner"] @@ -674,6 +675,7 @@ def videos_count(self, obj) -> int: class VideoAccessTokenAdmin(admin.ModelAdmin): """Admin for the VideoAccessToken model.""" + list_display = ("video", "token") readonly_fields = ("token",) autocomplete_fields = ["video"] diff --git a/pod/video/models.py b/pod/video/models.py index d5f34cf7ce..97c109b7ea 100644 --- a/pod/video/models.py +++ b/pod/video/models.py @@ -1839,11 +1839,13 @@ class Meta: class VideoAccessToken(models.Model): """Video access token model.""" + video = models.ForeignKey(Video, on_delete=models.CASCADE) token = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) class Meta: """Video access token Metadata.""" + ordering = ["video", "token"] verbose_name = _("Video access token") verbose_name_plural = _("Video access tokens") diff --git a/pod/video/tests/test_views.py b/pod/video/tests/test_views.py index 88356c6d0e..a1377c8c46 100644 --- a/pod/video/tests/test_views.py +++ b/pod/video/tests/test_views.py @@ -1756,9 +1756,7 @@ def test_video_access_tokens_post_request(self): self.assertEqual(VideoAccessToken.objects.all().count(), 0) # ################################### # post random action - response = self.client.post(url, { - "action": "toto" - }) + response = self.client.post(url, {"action": "toto"}) # 302 redirect to remove post action self.assertEqual(response.status_code, 302) msg = _("An action must be specified.") @@ -1769,9 +1767,7 @@ def test_video_access_tokens_post_request(self): self.assertEqual(VideoAccessToken.objects.all().count(), 0) # ################################### # post add action - response = self.client.post(url, { - "action": "add" - }) + response = self.client.post(url, {"action": "add"}) # 302 redirect to remove post action self.assertEqual(response.status_code, 302) msg = _("A token has been created.") @@ -1782,9 +1778,7 @@ def test_video_access_tokens_post_request(self): self.assertEqual(VideoAccessToken.objects.all().count(), 1) # ################################### # post empty delete action - response = self.client.post(url, { - "action": "delete" - }) + response = self.client.post(url, {"action": "delete"}) # 302 redirect to remove post action self.assertEqual(response.status_code, 302) msg = _("Token not found.") @@ -1795,10 +1789,7 @@ def test_video_access_tokens_post_request(self): self.assertEqual(VideoAccessToken.objects.all().count(), 1) # ################################### # post invalid token delete action - response = self.client.post(url, { - "action": "delete", - "token": "1234" - }) + response = self.client.post(url, {"action": "delete", "token": "1234"}) # 302 redirect to remove post action self.assertEqual(response.status_code, 302) msg = _("Token not found.") @@ -1809,10 +1800,7 @@ def test_video_access_tokens_post_request(self): self.assertEqual(VideoAccessToken.objects.all().count(), 1) # ################################### # post randmon token delete action - response = self.client.post(url, { - "action": "delete", - "token": uuid.uuid4() - }) + response = self.client.post(url, {"action": "delete", "token": uuid.uuid4()}) # 302 redirect to remove post action self.assertEqual(response.status_code, 302) msg = _("Token not found.") @@ -1824,10 +1812,7 @@ def test_video_access_tokens_post_request(self): # ################################### # post good token delete action token = VideoAccessToken.objects.all().first().token - response = self.client.post(url, { - "action": "delete", - "token": token - }) + response = self.client.post(url, {"action": "delete", "token": token}) # 302 redirect to remove post action self.assertEqual(response.status_code, 302) msg = _("The token has been deleted.") diff --git a/pod/video/urls.py b/pod/video/urls.py index 7abf0ab76e..9db0a93638 100644 --- a/pod/video/urls.py +++ b/pod/video/urls.py @@ -59,7 +59,7 @@ url( r"^edit_access_tokens/(?P[\-\d\w]+)/$", video_edit_access_tokens, - name="video_edit_access_tokens" + name="video_edit_access_tokens", ), url( r"^delete/(?P[\-\d\w]+)/$", diff --git a/pod/video/views.py b/pod/video/views.py index 8b0a4e7d92..0748b1721b 100644 --- a/pod/video/views.py +++ b/pod/video/views.py @@ -1084,12 +1084,12 @@ def toggle_render_video_user_can_see_video( # and check_password(request.POST.get("password"), video.password) ) or ( - slug_private and ( + slug_private + and ( slug_private == video.get_hashkey() - or slug_private in [ - str(tok.token) for tok in VideoAccessToken.objects.filter( - video=video - ) + or slug_private + in [ + str(tok.token) for tok in VideoAccessToken.objects.filter(video=video) ] ) ) @@ -1405,17 +1405,17 @@ def video_edit_access_tokens(request: WSGIRequest, slug: str = None): token = request.POST.get("token") delete_token(request, video, token) else: - messages.add_message( - request, messages.ERROR, _("Token not found.") - ) + messages.add_message(request, messages.ERROR, _("Token not found.")) else: messages.add_message( request, messages.ERROR, _("An action must be specified.") ) # redirect to remove post data - return redirect(reverse('video:video_edit_access_tokens', args=(video.slug,))) + return redirect(reverse("video:video_edit_access_tokens", args=(video.slug,))) tokens = VideoAccessToken.objects.filter(video=video) - page_title = _('Manage access tokens for the video "%(vtitle)s"') % {"vtitle": video.title} + page_title = _('Manage access tokens for the video "%(vtitle)s"') % { + "vtitle": video.title + } return render( request, "videos/video_access_tokens.html", @@ -1423,18 +1423,14 @@ def video_edit_access_tokens(request: WSGIRequest, slug: str = None): ) -def delete_token(request, video:Video, token:VideoAccessToken): +def delete_token(request, video: Video, token: VideoAccessToken): """Remove token for the video if exist.""" try: uuid.UUID(str(token)) VideoAccessToken.objects.get(video=video, token=token).delete() - messages.add_message( - request, messages.INFO, _("The token has been deleted.") - ) + messages.add_message(request, messages.INFO, _("The token has been deleted.")) except (ValueError, ObjectDoesNotExist): - messages.add_message( - request, messages.ERROR, _("Token not found.") - ) + messages.add_message(request, messages.ERROR, _("Token not found.")) @csrf_protect