Skip to content

Commit

Permalink
Fixup. Format code with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Feb 15, 2024
1 parent 6fd6734 commit 793d1d0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 39 deletions.
2 changes: 2 additions & 0 deletions pod/video/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down
2 changes: 2 additions & 0 deletions pod/video/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
27 changes: 6 additions & 21 deletions pod/video/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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.")
Expand All @@ -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.")
Expand All @@ -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.")
Expand All @@ -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.")
Expand All @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion pod/video/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
url(
r"^edit_access_tokens/(?P<slug>[\-\d\w]+)/$",
video_edit_access_tokens,
name="video_edit_access_tokens"
name="video_edit_access_tokens",
),
url(
r"^delete/(?P<slug>[\-\d\w]+)/$",
Expand Down
30 changes: 13 additions & 17 deletions pod/video/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
)
)
Expand Down Expand Up @@ -1405,36 +1405,32 @@ 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",
{"video": video, "tokens": tokens, "page_title": page_title},
)


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
Expand Down

0 comments on commit 793d1d0

Please sign in to comment.