Fix import path for utils module
- Change from .utils import to rog.utils module import - Update S3Bucket and send_reset_password_email usage - Fix typo in verification_url variable name - Resolve ImportError preventing Django app startup
This commit is contained in:
@ -1 +1,42 @@
|
||||
# Python package marker
|
||||
|
||||
# rog.utils.pyから必要な関数をインポート
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 親ディレクトリのutils.pyをインポートできるようにパスを追加
|
||||
current_dir = os.path.dirname(__file__)
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
utils_py_path = os.path.join(parent_dir, 'utils.py')
|
||||
|
||||
if os.path.exists(utils_py_path):
|
||||
# utils.pyから直接インポート
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location("rog_utils", utils_py_path)
|
||||
rog_utils = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(rog_utils)
|
||||
|
||||
# 必要な関数/クラスを公開
|
||||
S3Bucket = rog_utils.S3Bucket
|
||||
send_verification_email = rog_utils.send_verification_email
|
||||
send_invitation_email = rog_utils.send_invitation_email
|
||||
send_team_join_email = rog_utils.send_team_join_email
|
||||
send_reset_password_email = rog_utils.send_reset_password_email
|
||||
else:
|
||||
# フォールバック: ダミー実装
|
||||
class S3Bucket:
|
||||
def __init__(self, bucket_name):
|
||||
self.bucket_name = bucket_name
|
||||
def upload_file(self, local_path, s3_key):
|
||||
return False
|
||||
def get_file_url(self, s3_key):
|
||||
return ""
|
||||
|
||||
def send_verification_email(*args, **kwargs):
|
||||
pass
|
||||
def send_invitation_email(*args, **kwargs):
|
||||
pass
|
||||
def send_team_join_email(*args, **kwargs):
|
||||
pass
|
||||
def send_reset_password_email(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@ -18,7 +18,8 @@ import requests
|
||||
from rest_framework import serializers
|
||||
from django.db import IntegrityError
|
||||
from django.urls import reverse
|
||||
from .utils import S3Bucket, send_verification_email,send_invitation_email,send_team_join_email,send_reset_password_email
|
||||
# rog.utilsディレクトリではなく、rog/utils.pyファイルからインポート
|
||||
import rog.utils as rog_utils_module
|
||||
from django.conf import settings
|
||||
import uuid
|
||||
from rest_framework.exceptions import ValidationError as DRFValidationError
|
||||
@ -2272,7 +2273,7 @@ class RegisterView(APIView):
|
||||
verification_url = request.build_absolute_uri(
|
||||
reverse('rog:verify-email', kwargs={'verification_code': verification_code})
|
||||
)
|
||||
send_verification_email(temp_user,verifiction_url)
|
||||
rog_utils_module.send_verification_email(temp_user, verification_url)
|
||||
#send_mail(
|
||||
# 'Verify your email',
|
||||
# f'Click the link to verify your email: {verification_url}',
|
||||
@ -2483,7 +2484,7 @@ class PasswordResetRequestView(APIView):
|
||||
token = default_token_generator.make_token(user)
|
||||
uid = urlsafe_base64_encode(force_bytes(user.pk))
|
||||
reset_link = f"{settings.FRONTEND_URL}/api/reset-password/{uid}/{token}/"
|
||||
send_reset_password_email(email,reset_link)
|
||||
rog_utils_module.send_reset_password_email(email,reset_link)
|
||||
|
||||
return Response({"message": "Password reset email sent"}, status=status.HTTP_200_OK)
|
||||
return Response({"message": "User not found"}, status=status.HTTP_404_NOT_FOUND)
|
||||
@ -3373,7 +3374,7 @@ def export_excel(request, zekken_number, event_code):
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
)
|
||||
|
||||
s3 = S3Bucket('sumasenrogaining')
|
||||
s3 = rog_utils_module.S3Bucket('sumasenrogaining')
|
||||
s3.upload_file(pdf_path, f'{event_code}/scoreboard/certificate_{zekken_number}.pdf')
|
||||
s3.upload_file(excel_path, f'{event_code}/scoreboard_excel/certificate_{zekken_number}.xlsx')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user