Skip to content

Commit

Permalink
bug fix in portfolio key setting. and change send_mail option to acti…
Browse files Browse the repository at this point in the history
…vate exception mode.
  • Loading branch information
bluebamus committed Nov 2, 2024
1 parent 7941ca1 commit 05893fe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
10 changes: 10 additions & 0 deletions portfolio/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Portfolio,
PortfolioSummary,
WorkExperience,
GetInTouchLog,
)

logger = logging.getLogger(getattr(settings, "PORTFOLIO_LOGGER", "django"))
Expand Down Expand Up @@ -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 {}
Expand All @@ -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)
14 changes: 8 additions & 6 deletions portfolio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}")
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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(
Expand Down
17 changes: 16 additions & 1 deletion utils/email/async_send_email.py
Original file line number Diff line number Diff line change
@@ -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__(
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions utils/email/verify_email_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 05893fe

Please sign in to comment.