def send_mail_after_scores_submission(persons, learning_unit_name, submitted_enrollments, all_encoded): """ Send an email to all the teachers after the scores submission for a learning unit :param persons: The list of the teachers of the leaning unit :param learning_unit_name: The name of the learning unit for which scores were submitted :param submitted_enrollments : The list of newly sibmitted enrollments :param all_encoded : Tell if all the scores are encoded and submitted :return An error message if the template is not in the database """ html_template_ref = 'assessments_scores_submission_html' txt_template_ref = 'assessments_scores_submission_txt' receivers = [message_config.create_receiver(person.id, person.email, person.language) for person in persons] suject_data = {'learning_unit_name': learning_unit_name} template_base_data = {'learning_unit_name': learning_unit_name, 'encoding_status': _('encoding_status_ended') if all_encoded else _('encoding_status_notended') } header_txt = ['acronym', 'session_title', 'registration_number', 'lastname', 'firstname', 'score', 'documentation'] submitted_enrollments_data = [ ( enrollment.learning_unit_enrollment.offer_enrollment.offer_year.acronym, enrollment.session_exam.number_session, enrollment.learning_unit_enrollment.offer_enrollment.student.registration_id, enrollment.learning_unit_enrollment.offer_enrollment.student.person.last_name, enrollment.learning_unit_enrollment.offer_enrollment.student.person.first_name, enrollment.score_final, _(enrollment.justification_final) if enrollment.justification_final else None, ) for enrollment in submitted_enrollments] table = message_config.create_table('submitted_enrollments', header_txt, submitted_enrollments_data) message_content = message_config.create_message_content(html_template_ref, txt_template_ref, [table], receivers, template_base_data, suject_data) return message_service.send_messages(message_content)
def send_message_after_all_encoded_by_manager(persons, enrollments, learning_unit_acronym, offer_acronym): """ Send a message to all tutor from a learning unit when all scores are submitted by program manager :param persons: The list of the tutor (person) of the learning unit :param enrollments: The enrollments that are encoded and submitted :param learning_unit_acronym The learning unit encoded :param offer_acronym: The offer which is managed :return: A message if an error occured, None if it's ok """ html_template_ref = 'assessments_all_scores_by_pgm_manager_html' txt_template_ref = 'assessments_all_scores_by_pgm_manager_txt' receivers = [ message_config.create_receiver(person.id, person.email, person.language) for person in persons ] suject_data = { 'learning_unit_acronym': learning_unit_acronym, 'offer_acronym': offer_acronym } template_base_data = { 'learning_unit_acronym': learning_unit_acronym, 'offer_acronym': offer_acronym, } enrollments_data = [( enrollment.learning_unit_enrollment.offer_enrollment.offer_year. acronym, enrollment.session_exam.number_session, enrollment.learning_unit_enrollment.offer_enrollment.student. registration_id, enrollment.learning_unit_enrollment.offer_enrollment.student.person. last_name, enrollment.learning_unit_enrollment.offer_enrollment.student.person. first_name, enrollment.score_final, enrollment.justification_final if enrollment.justification_final else None, ) for enrollment in enrollments] enrollments_headers = ('acronym', 'session_title', 'registration_number', 'lastname', 'firstname', 'score', 'justification') table = message_config.create_table('enrollments', enrollments_headers, enrollments_data, data_translatable=['justification']) attachment = build_scores_sheet_attachment(enrollments) message_content = message_config.create_message_content( html_template_ref, txt_template_ref, [table], receivers, template_base_data, suject_data, attachment) return message_service.send_messages(message_content)
def send_mail_applications_summary(global_id): application_list = get_application_list(global_id) if not application_list: return _('No application found') person = mdl_base.person.find_by_global_id(global_id) html_template_ref = 'applications_confirmation_html' txt_template_ref = 'applications_confirmation_txt' receivers = [ message_config.create_receiver(person.id, person.email, person.language) ] applications = _get_applications_table(application_list) table_applications = message_config.create_table( 'applications', [_('Acronym'), 'Vol. 1', 'Vol. 2'], applications) template_base_data = { 'first_name': person.first_name, 'last_name': person.last_name, } message_content = message_config.create_message_content( html_template_ref, txt_template_ref, [table_applications], receivers, template_base_data, None) return message_service.send_messages(message_content)
def __make_table(self): table_headers = ('acronym', 'session_title', 'registration_number', 'lastname', 'firstname', 'score', 'documentation') table_data = self.__make_table_data() return create_table('enrollments', table_headers, table_data)