Browse Source
feat(podcast, video): implement category creation and playlist association for podcasts and videos
feat(podcast, video): implement category creation and playlist association for podcasts and videos
- Added management commands to create podcast and video categories in Russian, ensuring a structured categorization system. - Updated podcast and video playlist creation commands to associate playlists with the newly created categories. - Enhanced documentation to reflect the new category creation process and its integration into the podcast and video systems.master
6 changed files with 305 additions and 34 deletions
-
57PODCAST_SETUP_GUIDE.md
-
26VIDEO_REFACTORING_SUMMARY.md
-
88apps/podcast/management/commands/create_podcast_categories.py
-
40apps/podcast/management/commands/create_podcast_playlists.py
-
88apps/video/management/commands/create_video_categories.py
-
40apps/video/management/commands/create_video_playlists.py
@ -0,0 +1,88 @@ |
|||||
|
from django.core.management.base import BaseCommand |
||||
|
from django.db import transaction |
||||
|
from apps.podcast.models import PodcastCategory |
||||
|
|
||||
|
|
||||
|
class Command(BaseCommand): |
||||
|
help = 'Create podcast categories in Russian language' |
||||
|
|
||||
|
# Russian podcast categories |
||||
|
CATEGORIES_DATA = [ |
||||
|
{ |
||||
|
'title': 'Пророки и посланники', |
||||
|
'order': 10 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Имамы Ахль аль-Байт', |
||||
|
'order': 20 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Коранические истории', |
||||
|
'order': 30 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Исламская философия', |
||||
|
'order': 40 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Нравственность и этика', |
||||
|
'order': 50 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'История ислама', |
||||
|
'order': 60 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Кербела и Ашура', |
||||
|
'order': 70 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Духовное развитие', |
||||
|
'order': 80 |
||||
|
} |
||||
|
] |
||||
|
|
||||
|
def add_arguments(self, parser): |
||||
|
parser.add_argument( |
||||
|
'--clean', |
||||
|
action='store_true', |
||||
|
help='Delete existing categories before creating new ones' |
||||
|
) |
||||
|
|
||||
|
def handle(self, *args, **options): |
||||
|
clean = options.get('clean', False) |
||||
|
|
||||
|
if clean: |
||||
|
deleted_count = PodcastCategory.objects.count() |
||||
|
PodcastCategory.objects.all().delete() |
||||
|
self.stdout.write(self.style.WARNING(f'Deleted {deleted_count} existing categories')) |
||||
|
|
||||
|
try: |
||||
|
with transaction.atomic(): |
||||
|
created_categories = [] |
||||
|
|
||||
|
for category_data in self.CATEGORIES_DATA: |
||||
|
# Check if category already exists |
||||
|
title = category_data['title'] |
||||
|
category, created = PodcastCategory.objects.get_or_create( |
||||
|
title=title, |
||||
|
defaults={ |
||||
|
'order': category_data['order'], |
||||
|
'status': True |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
if created: |
||||
|
self.stdout.write(self.style.SUCCESS(f'✓ Created category: {category.title}')) |
||||
|
created_categories.append(category) |
||||
|
else: |
||||
|
self.stdout.write(self.style.WARNING(f'⚠ Category already exists: {category.title}')) |
||||
|
|
||||
|
if created_categories: |
||||
|
self.stdout.write(self.style.SUCCESS(f'\n✓ Successfully created {len(created_categories)} categories!')) |
||||
|
else: |
||||
|
self.stdout.write(self.style.WARNING('\nNo new categories created (all already exist)')) |
||||
|
|
||||
|
except Exception as e: |
||||
|
self.stdout.write(self.style.ERROR(f'\n✗ Error during creation: {str(e)}')) |
||||
|
raise |
||||
@ -0,0 +1,88 @@ |
|||||
|
from django.core.management.base import BaseCommand |
||||
|
from django.db import transaction |
||||
|
from apps.video.models import VideoCategory |
||||
|
|
||||
|
|
||||
|
class Command(BaseCommand): |
||||
|
help = 'Create video categories in Russian language' |
||||
|
|
||||
|
# Russian video categories |
||||
|
CATEGORIES_DATA = [ |
||||
|
{ |
||||
|
'title': 'Пророки и посланники', |
||||
|
'order': 10 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Имамы Ахль аль-Байт', |
||||
|
'order': 20 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Коранические истории', |
||||
|
'order': 30 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Исламская философия', |
||||
|
'order': 40 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Нравственность и этика', |
||||
|
'order': 50 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'История ислама', |
||||
|
'order': 60 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Кербела и Ашура', |
||||
|
'order': 70 |
||||
|
}, |
||||
|
{ |
||||
|
'title': 'Духовное развитие', |
||||
|
'order': 80 |
||||
|
} |
||||
|
] |
||||
|
|
||||
|
def add_arguments(self, parser): |
||||
|
parser.add_argument( |
||||
|
'--clean', |
||||
|
action='store_true', |
||||
|
help='Delete existing categories before creating new ones' |
||||
|
) |
||||
|
|
||||
|
def handle(self, *args, **options): |
||||
|
clean = options.get('clean', False) |
||||
|
|
||||
|
if clean: |
||||
|
deleted_count = VideoCategory.objects.count() |
||||
|
VideoCategory.objects.all().delete() |
||||
|
self.stdout.write(self.style.WARNING(f'Deleted {deleted_count} existing categories')) |
||||
|
|
||||
|
try: |
||||
|
with transaction.atomic(): |
||||
|
created_categories = [] |
||||
|
|
||||
|
for category_data in self.CATEGORIES_DATA: |
||||
|
# Check if category already exists |
||||
|
title = category_data['title'] |
||||
|
category, created = VideoCategory.objects.get_or_create( |
||||
|
title=title, |
||||
|
defaults={ |
||||
|
'order': category_data['order'], |
||||
|
'status': True |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
if created: |
||||
|
self.stdout.write(self.style.SUCCESS(f'✓ Created category: {category.title}')) |
||||
|
created_categories.append(category) |
||||
|
else: |
||||
|
self.stdout.write(self.style.WARNING(f'⚠ Category already exists: {category.title}')) |
||||
|
|
||||
|
if created_categories: |
||||
|
self.stdout.write(self.style.SUCCESS(f'\n✓ Successfully created {len(created_categories)} categories!')) |
||||
|
else: |
||||
|
self.stdout.write(self.style.WARNING('\nNo new categories created (all already exist)')) |
||||
|
|
||||
|
except Exception as e: |
||||
|
self.stdout.write(self.style.ERROR(f'\n✗ Error during creation: {str(e)}')) |
||||
|
raise |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue