Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions pod/ai_enhancement/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,19 @@ def enhancement_is_ready(video: Video) -> bool:
return AIEnhancement.objects.filter(video=video, is_ready=True).exists()


def notify_user(video: Video):
def notify_user(video: Video, success: bool = True):
"""Notify user at the end of enhancement."""
if (
USE_NOTIFICATIONS
and video.owner.owner.accepts_notifications
and PushInformation.objects.filter(user=video.owner).exists()
):
send_notification_enhancement(video)
send_notification_enhancement(video, success)
if EMAIL_ON_ENHANCEMENT_COMPLETION:
send_email_enhancement(video)
send_email_enhancement(video, success)


def send_notification_enhancement(video):
def send_notification_enhancement(video, success: bool = True):
"""Send push notification on video encoding or transcripting completion."""
subject = "[%s] %s" % (
__TITLE_SITE__,
Expand All @@ -279,6 +279,14 @@ def send_notification_enhancement(video):
"content_title": video.title,
"site_title": __TITLE_SITE__,
}
if not success:
message = _(
"Something went wrong with IA improvement on “%(content_title)s”."
+ " Suggestions for improvement can’t be available on %(site_title)s."
) % {
"content_title": video.title,
"site_title": __TITLE_SITE__,
}

pwa_notify_user(
video.owner,
Expand All @@ -288,30 +296,38 @@ def send_notification_enhancement(video):
)


def send_email_enhancement(video) -> None:
def send_email_enhancement(video, success: bool = True) -> None:
"""Send email notification on video improvement completion."""
if DEBUG:
logger.info("SEND EMAIL ON IA IMPROVEMENT COMPLETION")
logger.info("SEND EMAIL ON IA IMPROVEMENT COMPLETION %s", success)
url_scheme = "https" if SECURE_SSL_REDIRECT else "http"
content_url = "%s:%s" % (url_scheme, video.get_full_url())
subject = "[%s] %s" % (
__TITLE_SITE__,
_("IA improvement #%(content_id)s completed") % {"content_id": video.id},
)
main_text = _(
"IA improvement “%(content_title)s” has been completed"
+ ", and is now available on %(site_title)s."
) % {
"content_title": "<strong>%s</strong>" % video.title,
"site_title": __TITLE_SITE__,
}
if not success:
main_text = _(
"Something went wrong with IA improvement on “%(content_title)s” "
+ " on %(site_title)s."
) % {
"content_title": "<strong>%s</strong>" % video.title,
"site_title": __TITLE_SITE__,
}

html_message = (
'<p>%s</p><p>%s</p><p>%s<br><a href="%s"><i>%s</i></a>\
</p><p>%s</p>'
% (
_("Hello,"),
_(
"IA improvement “%(content_title)s” has been completed"
+ ", and is now available on %(site_title)s."
)
% {
"content_title": "<strong>%s</strong>" % video.title,
"site_title": __TITLE_SITE__,
},
main_text,
_("You will find it here:"),
content_url,
content_url,
Expand Down
1 change: 1 addition & 0 deletions pod/ai_enhancement/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def toggle_webhook(request: WSGIRequest):
notify_user(enhancement.video)
return JsonResponse({"status": "OK"}, status=200)
else:
notify_user(enhancement.video, success=False)
return JsonResponse(
{"status": "Enhancement has not yet been successfully achieved."},
status=500,
Expand Down
Binary file modified pod/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
Loading
Loading