222 lines
8.8 KiB
Python
222 lines
8.8 KiB
Python
<<<<<<< HEAD
|
|
from django.core.management.base import BaseCommand
|
|
from django.core.mail import send_mail, get_connection
|
|
from django.conf import settings
|
|
from django.template.loader import render_to_string
|
|
from shop.models import Order, Product
|
|
from shop.emails import (
|
|
send_order_confirmation,
|
|
send_order_status_update,
|
|
send_shipping_confirmation,
|
|
send_admin_notification,
|
|
send_low_stock_notification
|
|
)
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Testet das E-Mail-System mit verschiedenen E-Mail-Typen'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
'--email',
|
|
type=str,
|
|
help='Test-E-Mail-Adresse',
|
|
)
|
|
parser.add_argument(
|
|
'--type',
|
|
type=str,
|
|
choices=['all', 'order', 'status', 'shipping', 'admin', 'stock'],
|
|
default='all',
|
|
help='Art der Test-E-Mail',
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
test_email = options['email']
|
|
if not test_email:
|
|
self.stdout.write(self.style.ERROR('Bitte geben Sie eine Test-E-Mail-Adresse an mit --email=ihre@email.de'))
|
|
return
|
|
|
|
email_type = options['type']
|
|
|
|
self.stdout.write('Starte E-Mail-Test...')
|
|
|
|
try:
|
|
# Debug-Informationen ausgeben
|
|
self.stdout.write(f'Backend: {settings.EMAIL_BACKEND}')
|
|
self.stdout.write(f'Host: {settings.EMAIL_HOST}')
|
|
self.stdout.write(f'Port: {settings.EMAIL_PORT}')
|
|
self.stdout.write(f'TLS: {settings.EMAIL_USE_TLS}')
|
|
self.stdout.write(f'Benutzer: {settings.EMAIL_HOST_USER}')
|
|
self.stdout.write('Passwort: ***versteckt***')
|
|
|
|
# Basis-Test
|
|
send_mail(
|
|
'Test E-Mail',
|
|
'Dies ist eine Test-E-Mail vom Fursuit Shop.',
|
|
settings.DEFAULT_FROM_EMAIL,
|
|
[test_email],
|
|
fail_silently=False,
|
|
)
|
|
self.stdout.write(self.style.SUCCESS('✓ Basis-E-Mail erfolgreich gesendet'))
|
|
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Basis-E-Mail fehlgeschlagen: {str(e)}'))
|
|
return
|
|
|
|
if email_type in ['all', 'order']:
|
|
try:
|
|
# Test-Bestellung erstellen
|
|
order = Order.objects.first()
|
|
if order:
|
|
send_order_confirmation(None, order)
|
|
self.stdout.write(self.style.SUCCESS('✓ Bestellbestätigung gesendet'))
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Bestellbestätigung fehlgeschlagen: {str(e)}'))
|
|
|
|
if email_type in ['all', 'status']:
|
|
try:
|
|
order = Order.objects.first()
|
|
if order:
|
|
send_order_status_update(None, order)
|
|
self.stdout.write(self.style.SUCCESS('✓ Status-Update gesendet'))
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Status-Update fehlgeschlagen: {str(e)}'))
|
|
|
|
if email_type in ['all', 'shipping']:
|
|
try:
|
|
order = Order.objects.filter(tracking_number__isnull=False).first()
|
|
if order:
|
|
send_shipping_confirmation(None, order)
|
|
self.stdout.write(self.style.SUCCESS('✓ Versandbestätigung gesendet'))
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Versandbestätigung fehlgeschlagen: {str(e)}'))
|
|
|
|
if email_type in ['all', 'admin']:
|
|
try:
|
|
order = Order.objects.first()
|
|
if order:
|
|
send_admin_notification(None, order, 'new_order')
|
|
self.stdout.write(self.style.SUCCESS('✓ Admin-Benachrichtigung gesendet'))
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Admin-Benachrichtigung fehlgeschlagen: {str(e)}'))
|
|
|
|
if email_type in ['all', 'stock']:
|
|
try:
|
|
product = Product.objects.first()
|
|
if product:
|
|
send_low_stock_notification(None, product)
|
|
self.stdout.write(self.style.SUCCESS('✓ Lagerbestand-Warnung gesendet'))
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Lagerbestand-Warnung fehlgeschlagen: {str(e)}'))
|
|
|
|
=======
|
|
from django.core.management.base import BaseCommand
|
|
from django.core.mail import send_mail, get_connection
|
|
from django.conf import settings
|
|
from django.template.loader import render_to_string
|
|
from shop.models import Order, Product
|
|
from shop.emails import (
|
|
send_order_confirmation,
|
|
send_order_status_update,
|
|
send_shipping_confirmation,
|
|
send_admin_notification,
|
|
send_low_stock_notification
|
|
)
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Testet das E-Mail-System mit verschiedenen E-Mail-Typen'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
'--email',
|
|
type=str,
|
|
help='Test-E-Mail-Adresse',
|
|
)
|
|
parser.add_argument(
|
|
'--type',
|
|
type=str,
|
|
choices=['all', 'order', 'status', 'shipping', 'admin', 'stock'],
|
|
default='all',
|
|
help='Art der Test-E-Mail',
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
test_email = options['email']
|
|
if not test_email:
|
|
self.stdout.write(self.style.ERROR('Bitte geben Sie eine Test-E-Mail-Adresse an mit --email=ihre@email.de'))
|
|
return
|
|
|
|
email_type = options['type']
|
|
|
|
self.stdout.write('Starte E-Mail-Test...')
|
|
|
|
try:
|
|
# Debug-Informationen ausgeben
|
|
self.stdout.write(f'Backend: {settings.EMAIL_BACKEND}')
|
|
self.stdout.write(f'Host: {settings.EMAIL_HOST}')
|
|
self.stdout.write(f'Port: {settings.EMAIL_PORT}')
|
|
self.stdout.write(f'TLS: {settings.EMAIL_USE_TLS}')
|
|
self.stdout.write(f'Benutzer: {settings.EMAIL_HOST_USER}')
|
|
self.stdout.write('Passwort: ***versteckt***')
|
|
|
|
# Basis-Test
|
|
send_mail(
|
|
'Test E-Mail',
|
|
'Dies ist eine Test-E-Mail vom Fursuit Shop.',
|
|
settings.DEFAULT_FROM_EMAIL,
|
|
[test_email],
|
|
fail_silently=False,
|
|
)
|
|
self.stdout.write(self.style.SUCCESS('✓ Basis-E-Mail erfolgreich gesendet'))
|
|
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Basis-E-Mail fehlgeschlagen: {str(e)}'))
|
|
return
|
|
|
|
if email_type in ['all', 'order']:
|
|
try:
|
|
# Test-Bestellung erstellen
|
|
order = Order.objects.first()
|
|
if order:
|
|
send_order_confirmation(None, order)
|
|
self.stdout.write(self.style.SUCCESS('✓ Bestellbestätigung gesendet'))
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Bestellbestätigung fehlgeschlagen: {str(e)}'))
|
|
|
|
if email_type in ['all', 'status']:
|
|
try:
|
|
order = Order.objects.first()
|
|
if order:
|
|
send_order_status_update(None, order)
|
|
self.stdout.write(self.style.SUCCESS('✓ Status-Update gesendet'))
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Status-Update fehlgeschlagen: {str(e)}'))
|
|
|
|
if email_type in ['all', 'shipping']:
|
|
try:
|
|
order = Order.objects.filter(tracking_number__isnull=False).first()
|
|
if order:
|
|
send_shipping_confirmation(None, order)
|
|
self.stdout.write(self.style.SUCCESS('✓ Versandbestätigung gesendet'))
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Versandbestätigung fehlgeschlagen: {str(e)}'))
|
|
|
|
if email_type in ['all', 'admin']:
|
|
try:
|
|
order = Order.objects.first()
|
|
if order:
|
|
send_admin_notification(None, order, 'new_order')
|
|
self.stdout.write(self.style.SUCCESS('✓ Admin-Benachrichtigung gesendet'))
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Admin-Benachrichtigung fehlgeschlagen: {str(e)}'))
|
|
|
|
if email_type in ['all', 'stock']:
|
|
try:
|
|
product = Product.objects.first()
|
|
if product:
|
|
send_low_stock_notification(None, product)
|
|
self.stdout.write(self.style.SUCCESS('✓ Lagerbestand-Warnung gesendet'))
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f'✗ Lagerbestand-Warnung fehlgeschlagen: {str(e)}'))
|
|
|
|
>>>>>>> 5b9b867963eca600ed64b617dc2dc86c30dbd9cb
|
|
self.stdout.write(self.style.SUCCESS('\nE-Mail-Test abgeschlossen!')) |