diff --git a/portfolio/admin.py b/portfolio/admin.py index e84acc6..ace3605 100644 --- a/portfolio/admin.py +++ b/portfolio/admin.py @@ -23,6 +23,7 @@ Portfolio, PortfolioSummary, WorkExperience, + GetInTouchLog, ) logger = logging.getLogger(getattr(settings, "PORTFOLIO_LOGGER", "django")) @@ -315,6 +316,14 @@ def delete_model(self, request, obj): super().delete_model(request, obj) +class GetInTouchLogAdmin(admin.ModelAdmin): + list_display = ['name', 'email', 'subject', 'state', 'created_at'] + list_filter = ['state'] + search_fields = ['name', 'email', 'subject'] + ordering = ['-created_at'] + readonly_fields = ['created_at'] + + class ProjectPostHiddenAdmin(admin.ModelAdmin): def get_model_perms(self, request): # tric regist return {} @@ -327,4 +336,5 @@ def get_model_perms(self, request): # tric regist portfolio_admin_site.register(EducationStudy, EducationStudyAdmin) portfolio_admin_site.register(InterestedIn, InterestedInAdmin) portfolio_admin_site.register(AboutProjects, AboutProjectsAdmin) +portfolio_admin_site.register(GetInTouchLog, GetInTouchLogAdmin) portfolio_admin_site.register(ProjectPost, ProjectPostHiddenAdmin) diff --git a/portfolio/views.py b/portfolio/views.py index 9c7eb58..4e3521b 100644 --- a/portfolio/views.py +++ b/portfolio/views.py @@ -55,13 +55,14 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) lang = get_language_index() check_cached_key = dredis_cache_check_key( - self.cache_prefix + ":" + str(lang), + self.cache_prefix + ":" + str(lang[0]), 0, "info", ) if check_cached_key: logger.debug(f"called redis cache - {self.__class__.__name__}") - queryset = dredis_cache_get(self.cache_prefix, 0) + queryset = dredis_cache_get(self.cache_prefix + ":" + str(lang[0]), + 0,) context.update(queryset) else: logger.debug(f"called database - {self.__class__.__name__}") @@ -96,7 +97,7 @@ def get_context_data(self, **kwargs): f"redis cache - {self.__class__.__name__} caching_data exists" ) dredis_cache_set( - self.cache_prefix, + self.cache_prefix + ":" + str(lang[0]), 0, **caching_data, ) @@ -213,16 +214,17 @@ def post(self, request, *args, **kwargs): msg_html = render_to_string( settings.TEMPLATE_DIR + self.email_template_get_in_touch, email_context ) + subject_email = subject + " " + emailfrom send_mail( - subject=subject, + subject=subject_email, recipient_list=[ emailto, ], message=message, - from_email=emailfrom, + from_email=settings.DEFAULT_FROM_EMAIL, html_message=msg_html, - fail_silently=True, + fail_silently=False, ) GetInTouchLog.objects.create( diff --git a/utils/email/async_send_email.py b/utils/email/async_send_email.py index 54c6116..813399b 100644 --- a/utils/email/async_send_email.py +++ b/utils/email/async_send_email.py @@ -1,11 +1,15 @@ import random import string import threading +import logging from django.conf import settings from django.core.mail import EmailMultiAlternatives from django.core.mail import send_mail as sendmail +# 로거 설정 +logger = logging.getLogger(__name__) + class EmailThread(threading.Thread): def __init__( @@ -25,7 +29,18 @@ def run(self): ) if self.html: msg.attach_alternative(self.html, "text/html") - msg.send(self.fail_silently) + + try: + # 이메일 전송 시도 + result = msg.send(self.fail_silently) + # 전송 결과 로그 기록 + if result > 0: + logger.info(f"Email sent successfully to {self.recipient_list}.") + else: + logger.warning(f"Email not sent to {self.recipient_list}. No recipients were successfully sent.") + except Exception as e: + # 예외 발생 시 로그 기록 + logger.error(f"Error sending email to {self.recipient_list}: {e}") def send_mail( diff --git a/utils/email/verify_email_mixins.py b/utils/email/verify_email_mixins.py index f66dde7..c82cf1f 100644 --- a/utils/email/verify_email_mixins.py +++ b/utils/email/verify_email_mixins.py @@ -56,7 +56,7 @@ def __create_verification_email_generator_token( from_email=from_email, recipient_list=[user.email], html_message=msg_html, - fail_silently=True, + fail_silently=False, ) result["sending_mail_num"] = 1 return result @@ -110,7 +110,7 @@ def __create_verification_email_custom_token( from_email=from_email, recipient_list=[user.email], html_message=msg_html, - fail_silently=True, + fail_silently=False, ) result["sending_mail_num"] = 1 return result @@ -139,7 +139,7 @@ def __create_reset_password_verification_generator_token( from_email=from_email, recipient_list=[user.email], html_message=msg_html, - fail_silently=True, + fail_silently=False, ) result["sending_mail_num"] = 1 return result