feat: multiple instructors on course card and course home

This commit is contained in:
Jannat Patel
2022-02-07 13:41:28 +05:30
parent 3e46db9c11
commit bf3a496ea3
7 changed files with 33 additions and 34 deletions

View File

@@ -19,7 +19,7 @@
"video_link",
"image",
"column_break_3",
"instructor",
"instructors",
"tags",
"section_break_7",
"is_published",
@@ -104,10 +104,10 @@
"options": "Chapter Reference"
},
{
"fieldname": "instructor",
"fieldname": "instructors",
"fieldtype": "Table MultiSelect",
"in_standard_filter": 1,
"label": "Instructor",
"label": "Instructors",
"options": "Course Instructor"
},
{
@@ -167,7 +167,7 @@
"link_fieldname": "course"
}
],
"modified": "2022-02-07 11:41:39.735324",
"modified": "2022-02-07 11:41:39.735325",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Course",
@@ -192,4 +192,4 @@
"states": [],
"title_field": "title",
"track_changes": 1
}
}

View File

@@ -143,10 +143,14 @@ class LMSCourse(Document):
fieldname="batch")
return batch_name and frappe.get_doc("LMS Batch", batch_name)
def get_instructor(self):
if self.instructor:
return frappe.get_doc("User", self.instructor)
return frappe.get_doc("User", self.owner)
def get_instructors(self):
instructors = []
if self.instructors:
for instructor in self.instructors:
instructors.append(frappe.get_doc("User", instructor.instructor))
else:
instructors.append(frappe.get_doc("User", self.owner))
return instructors
def get_chapters(self):
"""Returns all chapters of this course.

View File

@@ -41,14 +41,16 @@
</div>
<div class="card-heading course-card-title">{{ course.title }}</div>
<div {% if not read_only %} class="mb-4" {% endif %}>
{% for instructor in course.get_instructors() %}
<span class="zindex">
{{ widgets.Avatar(member=course.get_instructor(), avatar_class="avatar-small") }}
<a class="button-links" href="{{ get_profile_url(course.get_instructor().username) }}">
{{ widgets.Avatar(member=instructor, avatar_class="avatar-small") }}
<a class="button-links" href="{{ get_profile_url(instructor.username) }}">
<span class="course-instructor">
{{ course.get_instructor().full_name }}
{{ instructor.full_name }}
</span>
</a>
</span>
{% endfor %}
<span class="course-student-count">
{% if course.get_students() | length %}
<span class="vertically-center mr-4">

View File

@@ -1,19 +0,0 @@
<div class="course-teaser">
<div class="course-body">
<h3 class="course-title"><a href="/courses/{{ course.name }}">{{ course.title }}</a></h3>
<div class="course-intro">
{{ course.short_introduction or "" }}
</div>
</div>
<div class="course-footer">
{% set batch = course.get_student_batch(frappe.session.user) %}
{% if batch %}
<a class="btn btn-secondary pull-right" href="/courses/{{course.name}}/{{batch.name}}/learn">Resume Course</a>
{% endif %}
<div class="course-author">
{% with author = course.get_instructor() %}
{{ widgets.Avatar(member=author, avatar_class="avatar-medium") }} <a href="{{get_profile_url(author.username)}}">{{ author.full_name }}</a>
{% endwith %}
</div>
</div>
</div>

View File

@@ -21,4 +21,4 @@ execute:frappe.delete_doc("DocType", "LMS Topic") #06-10-2021
school.patches.v0_0.add_progress_to_membership #20-10-2021
execute:frappe.delete_doc("Workspace", "LMS", ignore_missing=True, force=True) #24-10-2021
execute:frappe.delete_doc("Custom Field", "User-verify_age", ignore_missing=True, force=True)
school.patches.v0_0.multiple_instructors
school.patches.v0_0.multiple_instructors #08-02-2022

View File

@@ -1,4 +1,14 @@
import frappe
def execute():
frappe.get_all("LMS Course", fields=["name", "instructor"])
frappe.reload_doc("lms", "doctype", "lms_course")
courses = frappe.get_all("LMS Course", fields=["name", "instructor"])
for course in courses:
doc = frappe.get_doc({
"doctype": "Course Instructor",
"parent": course.name,
"parentfield": "instructors",
"parenttype": "LMS Course",
"instructor": course.instructor
})
doc.save()

View File

@@ -129,7 +129,9 @@
<div class="course-home-headings">
Creator
</div>
{{ widgets.MemberCard(member=course.get_instructor(), show_course_count=True, avatar_class="avatar-large") }}
{% for instructor in course.get_instructors() %}
{{ widgets.MemberCard(member=instructor, show_course_count=True, avatar_class="avatar-large") }}
{% endfor %}
</div>
{% endmacro %}