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 Jan 17, 2024
1 parent 2db0640 commit 37c4d62
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 83 deletions.
2 changes: 1 addition & 1 deletion pod/bbb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class Livestream(models.Model):
verbose_name=_("Save meeting in Dashboard"),
help_text=_(
"Do you want to save the video of "
'this meeting, at the end of the live, directly in “Dashboard“?'
"this meeting, at the end of the live, directly in “Dashboard“?"
),
default=False,
)
Expand Down
8 changes: 6 additions & 2 deletions pod/playlist/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,13 @@ def test_folder_icon_in_video_links(self) -> None:
response = self.client.get(
reverse("playlist:content", kwargs={"slug": self.playlist_user1.slug})
)
self.assertTrue('class="bi bi-folder-minus card-footer-link-i"' in response.content.decode())
self.assertTrue(
'class="bi bi-folder-minus card-footer-link-i"' in response.content.decode()
)
response = self.client.get(self.url_fav_user1)
self.assertFalse('class="bi bi-folder-minus card-footer-link-i"' in response.content.decode())
self.assertFalse(
'class="bi bi-folder-minus card-footer-link-i"' in response.content.decode()
)
self.client.logout()
print(" ---> test_folder_icon_in_video_links ok")

Expand Down
28 changes: 12 additions & 16 deletions pod/video/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,11 @@ def __call__(self, value):
@receiver(post_save, sender=Video)
def launch_encode(sender, instance, created, **kwargs):
"""
Launch encoding after save Video if requested.
Launch encoding after save Video if requested.
Args:
sender (:class:`pod.video.models.Video`): Video model class.
instance (:class:`pod.video.models.Video`): Video object instance.
Args:
sender (:class:`pod.video.models.Video`): Video model class.
instance (:class:`pod.video.models.Video`): Video object instance.
"""
if hasattr(instance, "launch_encode") and instance.launch_encode is True:
instance.launch_encode = False
Expand All @@ -554,11 +554,11 @@ def launch_encode(sender, instance, created, **kwargs):
@receiver(post_save, sender=Video)
def launch_transcript(sender, instance, created, **kwargs):
"""
Launch transcription after save Video if requested.
Launch transcription after save Video if requested.
Args:
sender (:class:`pod.video.models.Video`): Video model class.
instance (:class:`pod.video.models.Video`): Video object instance.
Args:
sender (:class:`pod.video.models.Video`): Video model class.
instance (:class:`pod.video.models.Video`): Video object instance.
"""
if hasattr(instance, "launch_transcript") and instance.launch_transcript is True:
instance.launch_transcript = False
Expand Down Expand Up @@ -784,9 +784,8 @@ def clean(self):
and hasattr(self.instance, "video")
and cleaned_data["video"] != self.instance.video
)
self.launch_transcript = (
"transcript" in cleaned_data.keys()
and hasattr(self.instance, "transcript")
self.launch_transcript = "transcript" in cleaned_data.keys() and hasattr(
self.instance, "transcript"
)
self.change_user = (
self.launch_encode is False
Expand Down Expand Up @@ -911,10 +910,7 @@ def set_nostaff_config(self):
"description_%s" % key.replace("-", "_")
].widget = CKEditorWidget(config_name="default")
if self.fields.get("date_delete"):
if (
self.is_staff is False
or USE_OBSOLESCENCE is False
):
if self.is_staff is False or USE_OBSOLESCENCE is False:
del self.fields["date_delete"]
else:
self.fields["date_delete"].widget = forms.DateInput(
Expand Down Expand Up @@ -989,7 +985,7 @@ class Meta(object):
"date_evt": widgets.AdminDateWidget,
"restrict_access_to_groups": AddAccessGroupWidget,
"video": CustomClearableFileInput,
"restrict_access_to_groups": AddAccessGroupWidget
"restrict_access_to_groups": AddAccessGroupWidget,
}
initial = {
"date_added": __TODAY__,
Expand Down
21 changes: 9 additions & 12 deletions pod/video/templatetags/video_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,21 @@ def get_video_infos(video):
return {
"password": {
"status": is_password_protected,
"translation":
_("This content is password protected.")
if is_password_protected
else _("This content is not password protected."),
"translation": _("This content is password protected.")
if is_password_protected
else _("This content is not password protected."),
},
"draft": {
"status": video.is_draft,
"translation":
_("This content is in draft.")
if video.is_draft
else _("This content is public.")
"translation": _("This content is in draft.")
if video.is_draft
else _("This content is public."),
},
"chaptered": {
"status": is_chaptered,
"translation":
_("This content is chaptered.")
if is_chaptered
else _("This content is not chaptered."),
"translation": _("This content is chaptered.")
if is_chaptered
else _("This content is not chaptered."),
},
}

Expand Down
1 change: 1 addition & 0 deletions pod/video/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ class DashboardTestView(TestCase):
"""
Test Dashboard view access and videos pagination
"""

fixtures = [
"initial_data.json",
]
Expand Down
99 changes: 47 additions & 52 deletions pod/video/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ def theme_edit_save(request, channel):
# VIDEOS
# ############################################################################


@login_required(redirect_field_name="referrer")
def dashboard(request):
"""
Expand All @@ -510,7 +511,6 @@ def dashboard(request):
videos_list = videos_list.distinct()

if USER_VIDEO_CATEGORY:

cats = Category.objects.prefetch_related("video").filter(owner=request.user)
"""
" user's videos categories format =>
Expand All @@ -521,7 +521,9 @@ def dashboard(request):
"""
if request.GET.get("category") is not None:
category_checked = request.GET.get("category")
videos_list = get_object_or_404(Category, slug=category_checked, owner=request.user).video.all()
videos_list = get_object_or_404(
Category, slug=category_checked, owner=request.user
).video.all()

videos_without_cat = videos_list.exclude(category__in=cats)
cats = list(
Expand Down Expand Up @@ -552,7 +554,9 @@ def dashboard(request):
filtered_videos_list = get_filtered_videos_list(request, videos_list)
sort_field = request.GET.get("sort") if request.GET.get("sort") else "title"
sort_direction = request.GET.get("sort_direction")
sorted_videos_list = sort_videos_list(filtered_videos_list, sort_field, sort_direction)
sorted_videos_list = sort_videos_list(
filtered_videos_list, sort_field, sort_direction
)
ownersInstances = get_owners_has_instances(request.GET.getlist("owner"))
owner_filter = owner_is_searchable(request.user)

Expand All @@ -563,10 +567,15 @@ def dashboard(request):

videos_list_templates = {
"grid": "videos/video_list_grid_selectable.html",
"list": "videos/video_list_table_selectable.html"
"list": "videos/video_list_table_selectable.html",
}

display_mode = request.GET.get("display_mode") if request.GET.get("display_mode") and request.GET.get("display_mode") in videos_list_templates.keys() else "grid"
display_mode = (
request.GET.get("display_mode")
if request.GET.get("display_mode")
and request.GET.get("display_mode") in videos_list_templates.keys()
else "grid"
)
template = videos_list_templates[display_mode]

if request.is_ajax():
Expand All @@ -591,7 +600,11 @@ def dashboard(request):
)

data_context["form"] = form
data_context["fieldsets_dashboard"] = ["channel_option", "access_restrictions", "advanced_options"]
data_context["fieldsets_dashboard"] = [
"channel_option",
"access_restrictions",
"advanced_options",
]
data_context["use_category"] = USER_VIDEO_CATEGORY
data_context["use_obsolescence"] = USE_OBSOLESCENCE
data_context["use_transcription"] = USE_TRANSCRIPTION
Expand Down Expand Up @@ -646,15 +659,8 @@ def bulk_update(request):
if update_action == "fields":
# Bulk update fields
update_fields = json.loads(request.POST.get("update_fields"))
(
result["updated_videos"],
fields_errors,
status
) = (
bulk_update_fields(
request,
videos_list,
update_fields)
(result["updated_videos"], fields_errors, status) = bulk_update_fields(
request, videos_list, update_fields
)
result["fields_errors"] = fields_errors
counter = len(result["updated_videos"])
Expand All @@ -668,7 +674,9 @@ def bulk_update(request):
pass

delta = len(selected_videos) - counter
result, status = get_bulk_update_result(request, status, update_action, counter, delta, result)
result, status = get_bulk_update_result(
request, status, update_action, counter, delta, result
)
else:
status = 400
result["message"] = _("Sorry, no video found.")
Expand All @@ -694,15 +702,15 @@ def bulk_update_fields(request, videos_list, update_fields):
fields_errors = []

for video in videos_list:
form = (VideoForm(
form = VideoForm(
request.POST,
request.FILES,
instance=video,
is_staff=request.user.is_staff,
is_superuser=request.user.is_superuser,
current_user=request.user,
current_lang=request.LANGUAGE_CODE,
))
)
form.create_with_fields(update_fields)

if form.is_valid():
Expand Down Expand Up @@ -764,8 +772,10 @@ def get_bulk_update_result(request, status, update_action, counter, delta, resul
# Get global error messages (transcript or delete) and set status 400 if error message exists
if get_max_code_lvl_messages(request) >= 40:
status = 400
result["message"] = ' '.join(map(str, messages.get_messages(request)))
result["message"] += ' ' + get_recap_message_bulk_update(request, update_action, counter, delta)
result["message"] = " ".join(map(str, messages.get_messages(request)))
result["message"] += " " + get_recap_message_bulk_update(
request, update_action, counter, delta
)

# Prevent alert messages to popup on reload (asynchronous view)
dismiss_stored_messages(request)
Expand All @@ -788,42 +798,26 @@ def get_recap_message_bulk_update(request, update_action, counter, delta):
"""
# Define translations keys and message with plural management
message_translations = {
"delete":
ngettext(
"%(counter)s video removed",
"%(counter)s videos removed",
counter
) % {
"counter": counter
},
"transcript":
ngettext(
"%(counter)s video transcripted",
"%(counter)s videos transcripted",
counter
) % {
"counter": counter
},
"fields":
ngettext(
"%(counter)s video modified",
"%(counter)s videos modified",
counter
) % {
"counter": counter
},
"delete": ngettext(
"%(counter)s video removed", "%(counter)s videos removed", counter
)
% {"counter": counter},
"transcript": ngettext(
"%(counter)s video transcripted", "%(counter)s videos transcripted", counter
)
% {"counter": counter},
"fields": ngettext(
"%(counter)s video modified", "%(counter)s videos modified", counter
)
% {"counter": counter},
}
# Get plural translation for deleted, transcripted or updated videos
msg = message_translations[update_action]
counter = delta
# Get plural translation for videos in error
msg += ", " + ngettext(
"%(counter)s video in error",
"%(counter)s videos in error",
counter
) % {
"counter": counter
}
"%(counter)s video in error", "%(counter)s videos in error", counter
) % {"counter": counter}
return msg


Expand Down Expand Up @@ -1398,14 +1392,15 @@ def video_delete(request, slug=None):
"""View to delete video. Show form to approve deletion and do it if sent."""
video = get_object_or_404(Video, slug=slug, sites=get_current_site(request))
if video_is_deletable(request, video):

form = VideoDeleteForm()

if request.method == "POST":
form = VideoDeleteForm(request.POST)
if form.is_valid():
video.delete()
messages.add_message(request, messages.INFO, _("The video has been deleted."))
messages.add_message(
request, messages.INFO, _("The video has been deleted.")
)
return redirect(reverse("video:dashboard"))
else:
messages.add_message(
Expand Down

0 comments on commit 37c4d62

Please sign in to comment.