def test_get_supported_audio_language_description_with_invalid_code(self): valid_language_code = 'en' expected_language_description = 'English' self.assertEqual( utils.get_supported_audio_language_description( valid_language_code), expected_language_description) invalid_language_code = 'invalid_code' with self.assertRaisesRegexp( Exception, 'Unsupported audio language code: invalid_code'): utils.get_supported_audio_language_description( invalid_language_code)
def test_get_supported_audio_language_description_with_invalid_code(self): # type: () -> None valid_language_code = 'en' expected_language_description = 'English' self.assertEqual( utils.get_supported_audio_language_description( valid_language_code), expected_language_description) invalid_language_code = 'invalid_code' with self.assertRaisesRegexp( # type: ignore[no-untyped-call] Exception, 'Unsupported audio language code: invalid_code'): utils.get_supported_audio_language_description( invalid_language_code)
def send_rejected_voiceover_application_email(user_id, lesson_title, language_code, rejection_message): """Sends an email to users to give update on the rejected voiceover application. Args: user_id: str. The id of the user whose voiceover application got accepted. lesson_title: str. The title of the lessons for which the voiceover application got accepted. language_code: str. The language code in which for which the voiceover application got accepted. rejection_message: str. The message left by the reviewer while rejecting the voiceover application. """ email_subject = 'Updates on submitted voiceover application' email_body_template = ( 'Hi %s,<br><br>' 'Your voiceover application for "%s" lesson in language %s got rejected' ' and the reviewer has left a message.' '<br><br>Review message: %s<br><br>' 'You can create a new voiceover application through the' '<a href="https://oppia.org/community_dashboard">' 'community dashboard</a> page.<br><br>' '- The Oppia Team<br>' '<br>%s') if not feconf.CAN_SEND_EMAILS: log_new_error('This app cannot send emails to users.') return recipient_user_settings = user_services.get_user_settings(user_id) can_user_receive_email = user_services.get_email_preferences( user_id).can_receive_email_updates # Send email only if recipient wants to receive. if can_user_receive_email: language = utils.get_supported_audio_language_description( language_code) email_body = email_body_template % ( recipient_user_settings.username, lesson_title, language, rejection_message, EMAIL_FOOTER.value) _send_email(user_id, feconf.SYSTEM_COMMITTER_ID, feconf.EMAIL_INTENT_VOICEOVER_APPLICATION_UPDATES, email_subject, email_body, feconf.NOREPLY_EMAIL_ADDRESS)
def _get_complete_translation_contribution_stats( self, translation_contribution_stats): """Returns translation contribution stats dicts with all the necessary information for the frontend. Args: translation_contribution_stats: list(TranslationContributionStats). TranslationContributionStats domain objects. Returns: list(dict(TranslationContributionStats)). Dict representations of TranslationContributionStats domain objects with additional keys: language: str. Language description. topic_name: str. Topic name. contribution_months: str. Unique translation contribution months of format: "%b %Y", e.g. "Jan 2021". Unnecessary keys language_code, topic_id, contribution_dates, contributor_user_id are consequently deleted. """ translation_contribution_stats_dicts = [ stats.to_dict() for stats in translation_contribution_stats ] topic_ids = [ stats_dict['topic_id'] for stats_dict in translation_contribution_stats_dicts ] topic_summaries = topic_fetchers.get_multi_topic_summaries(topic_ids) topic_name_by_topic_id = {} for topic_summary in topic_summaries: if topic_summary is None: continue topic_name_by_topic_id[topic_summary.id] = topic_summary.name for stats_dict in translation_contribution_stats_dicts: stats_dict['topic_name'] = topic_name_by_topic_id.get( stats_dict['topic_id'], 'UNKNOWN') stats_dict['contribution_months'] = list({ contribution_date.strftime('%b %Y') for contribution_date in stats_dict['contribution_dates'] }) stats_dict['language'] = ( utils.get_supported_audio_language_description( stats_dict['language_code'])) del stats_dict['topic_id'] del stats_dict['language_code'] del stats_dict['contribution_dates'] del stats_dict['contributor_user_id'] return translation_contribution_stats_dicts
def send_accepted_voiceover_application_email(user_id, lesson_title, language_code): """Sends an email to users to an give update on the accepted voiceover application. Args: user_id: str. The id of the user whose voiceover application got accepted. lesson_title: str. The title of the lessons for which the voiceover application got accepted. language_code: str. The language code for which the voiceover application got accepted. """ email_subject = '[Accepted] Updates on submitted voiceover application' email_body_template = ( 'Hi %s,<br><br>' 'Congratulations! Your voiceover application for "%s" lesson got ' 'accepted and you have been assigned with a voice artist role in the ' 'lesson. Now you will be able to add voiceovers to the lesson in %s ' 'language.' '<br><br>You can check the wiki page to learn' '<a href="https://github.com/oppia/oppia/wiki/' 'Instructions-for-voice-artists">how to voiceover a lesson</a><br><br>' 'Thank you for helping improve Oppia\'s lessons!' '- The Oppia Team<br>' '<br>%s') if not feconf.CAN_SEND_EMAILS: log_new_error('This app cannot send emails to users.') return recipient_user_settings = user_services.get_user_settings(user_id) can_user_receive_email = user_services.get_email_preferences( user_id).can_receive_email_updates # Send email only if recipient wants to receive. if can_user_receive_email: language = utils.get_supported_audio_language_description( language_code) email_body = email_body_template % (recipient_user_settings.username, lesson_title, language, EMAIL_FOOTER.value) _send_email(user_id, feconf.SYSTEM_COMMITTER_ID, feconf.EMAIL_INTENT_VOICEOVER_APPLICATION_UPDATES, email_subject, email_body, feconf.NOREPLY_EMAIL_ADDRESS)