Skip to content

Commit

Permalink
Merge pull request #780 from Studio-Yandex-Practicum/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
AntonZelinsky authored May 15, 2024
2 parents 96669cf + ae4d3c2 commit 4e3a065
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
16 changes: 8 additions & 8 deletions apps/core/services/send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ def send_email(from_email: str, to_emails: tuple, template_id: str, context: dic
elif message.anymail_status.esp_response.status_code == status.HTTP_200_OK:
return True
return False
except AnymailConfigurationError as error:
except AnymailConfigurationError:
msg = f"Неверные настройки Mailjet. Не удалось отправить письмо на почтовые адреса - {to_emails}."
logger.critical(msg, error, exc_info=True)
except (AnymailRequestsAPIError, AnymailInvalidAddress) as error:
logger.critical(msg, exc_info=True)
except (AnymailRequestsAPIError, AnymailInvalidAddress):
msg = (
f"Не указан адрес электронной почты отправителя."
f"Не удалось отправить письмо на почтовые адреса - {to_emails}."
)
logger.critical(msg, error, exc_info=True)
except ValueError as error:
logger.critical(msg, exc_info=True)
except ValueError:
msg = f"Неверный ID шаблона Mailjet. Не удалось отправить письмо на почтовые адреса - {to_emails}."
logger.critical(msg, error, exc_info=True)
except AnymailError as error:
logger.critical(msg, exc_info=True)
except AnymailError:
msg = "Ooops, something goes wrong! :("
logger.critical(msg, error, exc_info=True)
logger.critical(msg, exc_info=True)
49 changes: 26 additions & 23 deletions apps/feedback/services/participation_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,32 @@ def _get_email_settings(self):

def _mail_send_export(self, instance, file_link):
"""Отправка почтового уведомления о новой заявке на участие."""
email_settings = self._get_email_settings()
from_email = email_settings.get("email_send_from")
to_emails = (email_settings.get("submit_play_email"),)
template_id = settings.MAILJET_TEMPLATE_ID_PARTICIPATION_APPLICATION
context = {
"year": instance.year,
"birth_year": instance.birth_year,
"first_name": instance.first_name,
"nickname": instance.nickname,
"last_name": instance.last_name,
"city": instance.city,
"phone_number": instance.phone_number.as_international,
"email": instance.email,
"title": instance.title,
"file_link": file_link,
"file_path": instance.file.path,
}
send_email_success = send_email(from_email, to_emails, template_id, context, attach_file=True)
if send_email_success:
instance.sent_to_email = True
instance.save()
# Отправка подтверждения участнику
send_email(from_email, (instance.email,), template_id, context, attach_file=True)
try:
email_settings = self._get_email_settings()
from_email = email_settings.get("email_send_from")
to_emails = (email_settings.get("submit_play_email"),)
template_id = settings.MAILJET_TEMPLATE_ID_PARTICIPATION_APPLICATION
context = {
"year": instance.year,
"birth_year": instance.birth_year,
"first_name": instance.first_name,
"nickname": instance.nickname,
"last_name": instance.last_name,
"city": instance.city,
"phone_number": instance.phone_number.as_international,
"email": instance.email,
"title": instance.title,
"file_link": file_link,
"file_path": instance.file.path,
}
send_email_success = send_email(from_email, to_emails, template_id, context, attach_file=True)
if send_email_success:
instance.sent_to_email = True
instance.save()
# Отправка подтверждения участнику
send_email(from_email, (instance.email,), template_id, context, attach_file=True)
except Exception:
logger.critical(msg="Ошибка при подготовке сообщения электронной почты", exc_info=True)

def export_application(self, instance, file_link):
"""Функция, объединяющая экспорт на диск, в таблицу и отправку на почту."""
Expand Down
8 changes: 4 additions & 4 deletions apps/feedback/services/spreadsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ def export(self, instance, file_url) -> Optional[bool]:
self._set_borders(service)
self._set_header(service)
return self._export_new_object(instance, service, file_url)
except (ValueError, Exception) as error:
except (ValueError, Exception):
msg = f"Не удалось выгрузить данные заявки от {instance.email} на Google Sheets."
logger.critical(msg, error, exc_info=True)
logger.critical(msg, exc_info=True)

def find_and_replace(self, find, replacement):
try:
Expand Down Expand Up @@ -261,6 +261,6 @@ def find_and_replace(self, find, replacement):
break
service.spreadsheets().close()
return rows_changed
except (ValueError, Exception) as error:
except (ValueError, Exception):
msg = f"Не удалось произвести замену {find} на Google Sheets."
logger.critical(msg, error, exc_info=True)
logger.critical(msg, exc_info=True)
4 changes: 2 additions & 2 deletions apps/feedback/services/yandex_disk_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def yandex_disk_export(instance) -> Optional[bool]:
yndx.upload(from_dir, to_dir)

return publish_file(yndx, to_dir)
except (ValueError, YaDiskError) as error:
except (ValueError, YaDiskError):
msg = f"Не удалось загрузить пьесу {instance.title} от {instance.email} на Яндекс диск."
logger.critical(msg, error, exc_info=True)
logger.critical(msg, exc_info=True)

0 comments on commit 4e3a065

Please sign in to comment.