update
This commit is contained in:
0
emails/management/__init__.py
Normal file
0
emails/management/__init__.py
Normal file
BIN
emails/management/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
emails/management/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
0
emails/management/commands/__init__.py
Normal file
0
emails/management/commands/__init__.py
Normal file
BIN
emails/management/commands/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
emails/management/commands/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
49
emails/management/commands/create_default_folders.py
Normal file
49
emails/management/commands/create_default_folders.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth import get_user_model
|
||||
from emails.models import EmailFolder
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Create default email folders for all users'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
users = User.objects.all()
|
||||
created_count = 0
|
||||
|
||||
for user in users:
|
||||
# Check if user already has folders
|
||||
if EmailFolder.objects.filter(user=user).exists():
|
||||
self.stdout.write(
|
||||
self.style.WARNING(f'User {user.email} already has folders, skipping...')
|
||||
)
|
||||
continue
|
||||
|
||||
# Create default folders
|
||||
default_folders = [
|
||||
{'name': 'Inbox', 'folder_type': 'inbox', 'color': '#007bff'},
|
||||
{'name': 'Sent', 'folder_type': 'sent', 'color': '#28a745'},
|
||||
{'name': 'Drafts', 'folder_type': 'drafts', 'color': '#ffc107'},
|
||||
{'name': 'Trash', 'folder_type': 'trash', 'color': '#dc3545'},
|
||||
{'name': 'Spam', 'folder_type': 'spam', 'color': '#6c757d'},
|
||||
{'name': 'Archive', 'folder_type': 'archive', 'color': '#17a2b8'},
|
||||
]
|
||||
|
||||
for folder_data in default_folders:
|
||||
EmailFolder.objects.create(
|
||||
user=user,
|
||||
name=folder_data['name'],
|
||||
folder_type=folder_data['folder_type'],
|
||||
color=folder_data['color'],
|
||||
is_system=True
|
||||
)
|
||||
created_count += 1
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f'Created default folders for user {user.email}')
|
||||
)
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f'Successfully created {created_count} default folders')
|
||||
)
|
||||
Reference in New Issue
Block a user