Changeset View
Changeset View
Standalone View
Standalone View
training/management/commands/import_legacy_cloud_training.py
| Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | def import_training(self, training_abspath): | ||||
| # Fetch or create Training object | # Fetch or create Training object | ||||
| self.stdout.write(self.style.NOTICE('Creating training %s' % training_doc['url'])) | self.stdout.write(self.style.NOTICE('Creating training %s' % training_doc['url'])) | ||||
| if models_training.trainings.Training.objects.filter(slug=training_doc['url']).exists(): | if models_training.trainings.Training.objects.filter(slug=training_doc['url']).exists(): | ||||
| training = models_training.trainings.Training.objects.get(slug=training_doc['url']) | training = models_training.trainings.Training.objects.get(slug=training_doc['url']) | ||||
| self.stdout.write( | self.stdout.write( | ||||
| self.style.WARNING('Project %s already exists' % training_doc['url']) | self.style.WARNING('Project %s already exists' % training_doc['url']) | ||||
| ) | ) | ||||
| else: | else: | ||||
| # Create a GCS storage location (all trainings use this type of storage) | |||||
| storage_location: models_assets.StorageLocation = models_assets.StorageLocation.objects.create( | |||||
| name=training_doc['url'], | |||||
| category=models_assets.StorageLocationCategoryChoices.gcs, | |||||
| bucket_name=training_doc['_id'], | |||||
| ) | |||||
| training = models_training.trainings.Training.objects.create( | training = models_training.trainings.Training.objects.create( | ||||
| name=training_doc['name'], | name=training_doc['name'], | ||||
| slug=training_doc['url'], | slug=training_doc['url'], | ||||
| description=training_doc['summary'], | description=training_doc['summary'], | ||||
| summary=training_doc['description'], | summary=training_doc['description'], | ||||
| status=training_doc['status'], | status=training_doc['status'], | ||||
| type=training_doc['category'], | type=training_doc['category'], | ||||
| difficulty='beginner', | difficulty='beginner', | ||||
| storage_location=storage_location, | |||||
| ) | ) | ||||
| return training | return training | ||||
| def get_or_create_chapters(training): | def get_or_create_chapters(training): | ||||
| # Create Chapters | # Create Chapters | ||||
| training_chapters_path = training_abspath / 'chapters' | training_chapters_path = training_abspath / 'chapters' | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | def import_training(self, training_abspath): | ||||
| try: | try: | ||||
| video = section.video | video = section.video | ||||
| except models_training.sections.Video.DoesNotExist: | except models_training.sections.Video.DoesNotExist: | ||||
| video = models_training.sections.Video.objects.create( | video = models_training.sections.Video.objects.create( | ||||
| section=section, | section=section, | ||||
| size=25000, | size=25000, | ||||
| duration='10:00', | duration='10:00', | ||||
| file='stand/in/path.mp4', | file='stand/in/path.mp4', | ||||
| storage_location=section.chapter.training.storage_location, | |||||
| ) | ) | ||||
| models_training.sections.Video.objects.filter(pk=video.pk).update( | models_training.sections.Video.objects.filter(pk=video.pk).update( | ||||
| date_created=date_created, date_updated=date_updated | date_created=date_created, date_updated=date_updated | ||||
| ) | ) | ||||
| variation = file_doc['variations'][0] | variation = file_doc['variations'][0] | ||||
| add_static_asset_path(video, 'file', variation['file_path']) | add_static_asset_path(video, 'file', variation['file_path']) | ||||
| elif section_doc['properties']['content_type'] == 'file': | elif section_doc['properties']['content_type'] == 'file': | ||||
| if section.assets.exists(): | if section.assets.exists(): | ||||
| asset = section.assets.first() | asset = section.assets.first() | ||||
| else: | else: | ||||
| asset = models_training.sections.Asset.objects.create( | asset = models_training.sections.Asset.objects.create( | ||||
| section=section, | section=section, | ||||
| size=25000, | size=25000, | ||||
| file='stand/in/path.mp4', | file='stand/in/path.mp4', | ||||
| storage_location=section.chapter.training.storage_location, | |||||
| ) | ) | ||||
| add_static_asset_path(asset, 'file', file_doc['file_path']) | add_static_asset_path(asset, 'file', file_doc['file_path']) | ||||
| models_training.sections.Asset.objects.filter(pk=asset.pk).update( | models_training.sections.Asset.objects.filter(pk=asset.pk).update( | ||||
| date_created=date_created, date_updated=date_updated | date_created=date_created, date_updated=date_updated | ||||
| ) | ) | ||||
| # file_path_src = ( | # file_path_src = ( | ||||
| # file_doc_path.parent / 'variations' / pathlib.Path(variation['file_path']).name | # file_doc_path.parent / 'variations' / pathlib.Path(variation['file_path']).name | ||||
| ▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines | |||||