sync
This commit is contained in:
parent
f4d26b9ad3
commit
9d7edd63b2
|
@ -35,6 +35,17 @@ def create_lesson_cover(media_path):
|
||||||
|
|
||||||
|
|
||||||
def add_lesson(course):
|
def add_lesson(course):
|
||||||
|
"""
|
||||||
|
This function is used to add lessons to a given course. It searches for media files in the course directory and
|
||||||
|
creates a new lesson for each media file found. If a lesson with the same media file already exists in the database,
|
||||||
|
it skips the creation of that lesson.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
course (Course): The course object to which the lessons will be added.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
|
"""
|
||||||
file_types = ('*.mp4', '*.avi', '*.mkv', '*.flv')
|
file_types = ('*.mp4', '*.avi', '*.mkv', '*.flv')
|
||||||
media_files = []
|
media_files = []
|
||||||
for ext in file_types:
|
for ext in file_types:
|
||||||
|
@ -61,6 +72,7 @@ def get_course_media():
|
||||||
# compare the existing courses with the content, if the course is not in the database, add it
|
# compare the existing courses with the content, if the course is not in the database, add it
|
||||||
for course_path in content:
|
for course_path in content:
|
||||||
if course_path not in existing_courses_path:
|
if course_path not in existing_courses_path:
|
||||||
|
|
||||||
course_title = Path(course_path).name
|
course_title = Path(course_path).name
|
||||||
Course.objects.create(title=course_title, description=course_title, instructor=course_title,
|
Course.objects.create(title=course_title, description=course_title, instructor=course_title,
|
||||||
course_path=course_path)
|
course_path=course_path)
|
||||||
|
|
|
@ -17,6 +17,8 @@ class IndexView(View):
|
||||||
class CourseDetailView(View):
|
class CourseDetailView(View):
|
||||||
def get(self, request, pk):
|
def get(self, request, pk):
|
||||||
course = Course.objects.get(pk=pk)
|
course = Course.objects.get(pk=pk)
|
||||||
|
from .auto_importer import add_lesson
|
||||||
|
add_lesson(course)
|
||||||
context = {'lesson_list': course.lesson_set.all(), 'course': course}
|
context = {'lesson_list': course.lesson_set.all(), 'course': course}
|
||||||
return render(request, 'courses/course_detail.html', context)
|
return render(request, 'courses/course_detail.html', context)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue