From 1e3152e303cb8a977375d3d1a344f1c75a781b8e Mon Sep 17 00:00:00 2001 From: pateljannat Date: Thu, 10 Jun 2021 13:41:11 +0530 Subject: [PATCH] fix: ui --- community/hooks.py | 18 +++--- community/lms/doctype/chapter/chapter.py | 1 + community/lms/doctype/lesson/lesson.json | 11 +++- community/lms/doctype/lms_batch/lms_batch.py | 2 +- .../lms_batch_membership.py | 3 + .../lms/doctype/lms_course/lms_course.py | 7 ++- community/lms/models.py | 2 +- community/lms/widgets/BatchTabs.html | 18 +++--- community/lms/widgets/ChapterTeaser.html | 6 +- community/lms/widgets/CourseOutline.html | 10 ++-- community/lms/widgets/InstructorSection.html | 7 ++- community/public/css/style.css | 1 + community/public/css/style.less | 2 +- community/www/batch/home.html | 18 +++--- community/www/batch/learn.py | 9 ++- community/www/batch/members.html | 18 +++--- community/www/batch/progress.html | 2 +- community/www/batch/progress.py | 7 ++- community/www/batch/utils.py | 9 ++- community/www/courses/course.html | 58 +++++++++---------- community/www/courses/index.html | 10 ++-- community/www/hackathons/macros/card.html | 6 +- 22 files changed, 120 insertions(+), 105 deletions(-) diff --git a/community/hooks.py b/community/hooks.py index e6916c0b..150c88bc 100644 --- a/community/hooks.py +++ b/community/hooks.py @@ -136,15 +136,15 @@ primary_rules = [ {"from_route": "/hackathons//", "to_route": "hackathons/project"}, {"from_route": "/dashboard", "to_route": ""}, {"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"}, - {"from_route": "/courses///home", "to_route": "batch/home"}, - {"from_route": "/courses///learn", "to_route": "batch/learn"}, - {"from_route": "/courses///learn/.", "to_route": "batch/learn"}, - {"from_route": "/courses///schedule", "to_route": "batch/schedule"}, - {"from_route": "/courses///members", "to_route": "batch/members"}, - {"from_route": "/courses///discuss", "to_route": "batch/discuss"}, - {"from_route": "/courses///about", "to_route": "batch/about"}, - {"from_route": "/courses///progress", "to_route": "batch/progress"}, - {"from_route": "/courses///join", "to_route": "batch/join"} + {"from_route": "/courses//home", "to_route": "batch/home"}, + {"from_route": "/courses//learn", "to_route": "batch/learn"}, + {"from_route": "/courses//learn/.", "to_route": "batch/learn"}, + {"from_route": "/courses//schedule", "to_route": "batch/schedule"}, + {"from_route": "/courses//members", "to_route": "batch/members"}, + {"from_route": "/courses//discuss", "to_route": "batch/discuss"}, + {"from_route": "/courses//about", "to_route": "batch/about"}, + {"from_route": "/courses//progress", "to_route": "batch/progress"}, + {"from_route": "/courses//join", "to_route": "batch/join"} ] # Any frappe default URL is blocked by profile-rules, add it here to unblock it diff --git a/community/lms/doctype/chapter/chapter.py b/community/lms/doctype/chapter/chapter.py index b616de2c..6c160455 100644 --- a/community/lms/doctype/chapter/chapter.py +++ b/community/lms/doctype/chapter/chapter.py @@ -12,4 +12,5 @@ class Chapter(Document): filters={"chapter": self.name}, fields='name', order_by="index_") + print("rows", rows) return [frappe.get_doc('Lesson', row['name']) for row in rows] diff --git a/community/lms/doctype/lesson/lesson.json b/community/lms/doctype/lesson/lesson.json index 4772b255..59df2394 100644 --- a/community/lms/doctype/lesson/lesson.json +++ b/community/lms/doctype/lesson/lesson.json @@ -12,7 +12,8 @@ "index_", "index_label", "body", - "sections" + "sections", + "include_in_preview" ], "fields": [ { @@ -59,11 +60,17 @@ "in_list_view": 1, "label": "Index Label", "read_only": 1 + }, + { + "default": "0", + "fieldname": "include_in_preview", + "fieldtype": "Check", + "label": "Include In Preview" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-06-01 05:30:48.127494", + "modified": "2021-06-10 10:06:39.176891", "modified_by": "Administrator", "module": "LMS", "name": "Lesson", diff --git a/community/lms/doctype/lms_batch/lms_batch.py b/community/lms/doctype/lms_batch/lms_batch.py index 185134ae..93ed20bd 100644 --- a/community/lms/doctype/lms_batch/lms_batch.py +++ b/community/lms/doctype/lms_batch/lms_batch.py @@ -83,7 +83,7 @@ class LMSBatch(Document): def get_learn_url(self, lesson_number): if not lesson_number: return - return f"/courses/{self.course}/{self.name}/learn/{lesson_number}" + return f"/courses/{self.course}/learn/{lesson_number}" @frappe.whitelist() def save_message(message, batch): diff --git a/community/lms/doctype/lms_batch_membership/lms_batch_membership.py b/community/lms/doctype/lms_batch_membership/lms_batch_membership.py index 7d714d46..cda7c53b 100644 --- a/community/lms/doctype/lms_batch_membership/lms_batch_membership.py +++ b/community/lms/doctype/lms_batch_membership/lms_batch_membership.py @@ -43,6 +43,9 @@ class LMSBatchMembership(Document): member_name = frappe.db.get_value("User", self.member, "full_name") frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch)) + def get_user_batch(course, user=frappe.session.user): + return frappe.db.get_value("LMS Batch Membership", {"member": user, "course": course}, "batch") + @frappe.whitelist() def create_membership(batch, member=None, member_type="Student", role="Member"): frappe.get_doc({ diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py index b3d08ef9..315a9092 100644 --- a/community/lms/doctype/lms_course/lms_course.py +++ b/community/lms/doctype/lms_course/lms_course.py @@ -8,6 +8,7 @@ from frappe.model.document import Document import json from ...utils import slugify from community.query import find, find_all +from frappe.utils import flt class LMSCourse(Document): @staticmethod @@ -112,7 +113,7 @@ class LMSCourse(Document): """Returns all chapters of this course. """ # TODO: chapters should have a way to specify the order - return find_all("Chapter", course=self.name, order_by="creation") + return find_all("Chapter", course=self.name, order_by="index_") def get_batch(self, batch_name): return find("LMS Batch", name=batch_name, course=self.name) @@ -197,6 +198,7 @@ class CourseOutline: self.lessons = self.get_lessons() def get_next(self, current): + current = flt(current) numbers = sorted(lesson['number'] for lesson in self.lessons) try: index = numbers.index(current) @@ -205,6 +207,7 @@ class CourseOutline: return None def get_prev(self, current): + current = flt(current) numbers = sorted(lesson['number'] for lesson in self.lessons) try: index = numbers.index(current) @@ -228,7 +231,7 @@ class CourseOutline: chapter_numbers = {c['name']: c['index_'] for c in self.chapters} for lesson in lessons: - lesson['number'] = "{}.{}".format(chapter_numbers[lesson['chapter']], lesson['index_']) + lesson['number'] = flt("{}.{}".format(chapter_numbers[lesson['chapter']], lesson['index_'])) return lessons @frappe.whitelist() diff --git a/community/lms/models.py b/community/lms/models.py index 00c910c3..2e7249d7 100644 --- a/community/lms/models.py +++ b/community/lms/models.py @@ -2,4 +2,4 @@ """ from .doctype.lms_course.lms_course import LMSCourse as Course from .doctype.lms_sketch.lms_sketch import LMSSketch as Sketch - +from .doctype.lms_batch_membership.lms_batch_membership import LMSBatchMembership as Membership diff --git a/community/lms/widgets/BatchTabs.html b/community/lms/widgets/BatchTabs.html index 48378660..983b5655 100644 --- a/community/lms/widgets/BatchTabs.html +++ b/community/lms/widgets/BatchTabs.html @@ -1,28 +1,30 @@
- Courses /{% if course.is_mentor(frappe.session.user) %} {{ course.title }} {% else %} {{ course.title }} {% endif %} + Courses /{% if course.is_mentor(frappe.session.user) %} {{ course.title }} {% else %} + {{ course.title }} {% endif %}
diff --git a/community/lms/widgets/ChapterTeaser.html b/community/lms/widgets/ChapterTeaser.html index 1678b1bb..fce2a11a 100644 --- a/community/lms/widgets/ChapterTeaser.html +++ b/community/lms/widgets/ChapterTeaser.html @@ -1,15 +1,15 @@
-

{{index}}. {{ chapter.title }}

+
{{index}}. {{ chapter.title }}
{{ chapter.description or "" }}
{% for lesson in chapter.get_lessons() %}
- {{ lesson.title }} + {{ lesson.title }} {% if show_progress and not course.is_mentor(frappe.session.user) and lesson.get_progress() %} - {{ lesson.get_progress() }} + {{ lesson.get_progress() }} {% endif %}
{% endfor %} diff --git a/community/lms/widgets/CourseOutline.html b/community/lms/widgets/CourseOutline.html index 249013ff..b4b5629c 100644 --- a/community/lms/widgets/CourseOutline.html +++ b/community/lms/widgets/CourseOutline.html @@ -1,5 +1,7 @@ -

Course Outline

+
+

Course Outline

-{% for chapter in course.get_chapters() %} -{{ widgets.ChapterTeaser(index=loop.index, chapter=chapter, course=course, batch=batch, show_link=show_link, show_progress=show_progress)}} -{% endfor %} + {% for chapter in course.get_chapters() %} + {{ widgets.ChapterTeaser(index=loop.index, chapter=chapter, course=course, batch=batch, show_link=show_link, show_progress=show_progress)}} + {% endfor %} +
diff --git a/community/lms/widgets/InstructorSection.html b/community/lms/widgets/InstructorSection.html index d7634b65..367148dd 100644 --- a/community/lms/widgets/InstructorSection.html +++ b/community/lms/widgets/InstructorSection.html @@ -1,5 +1,6 @@ -

Instructor

-
{{instructor.full_name}}
-
Created {{instructor.get_course_count()}} courses
+ {{ widgets.Avatar(member=instructor, avatar_class="avatar-medium") }} + {{ instructor.full_name }} +
Course Creator
+
diff --git a/community/public/css/style.css b/community/public/css/style.css index 699d8dfc..c1ff3462 100644 --- a/community/public/css/style.css +++ b/community/public/css/style.css @@ -82,6 +82,7 @@ body { border-radius: 10px; margin: 10px 0px; background: white; + box-shadow: 0px 5px 10px rgb(0 0 0 / 10%); border: 1px solid #ddc; } diff --git a/community/public/css/style.less b/community/public/css/style.less index c265dafe..9580e195 100644 --- a/community/public/css/style.less +++ b/community/public/css/style.less @@ -10,6 +10,7 @@ h2 { .teaser-body { padding: 20px; + box-shadow: 0px 5px 10px rgb(0 0 0 / 10%) } .teaser-footer { padding: 20px; @@ -162,7 +163,6 @@ section.lightgray { // } .instructor-title { - font-weight: bold; color: black; } diff --git a/community/www/batch/home.html b/community/www/batch/home.html index db439963..a1f6a4a9 100644 --- a/community/www/batch/home.html +++ b/community/www/batch/home.html @@ -11,26 +11,28 @@ {% set invite_link = frappe.utils.get_url() + "/courses/" + course.name + "/" + batch.name + "/join" %}
{{ widgets.BatchTabs(course=course, batch=batch) }} -
+ +
{{ widgets.CourseOutline(course=course, batch=batch, show_link=True, show_progress=True) }}
-

Batch Schedule

+

Batch Schedule

{{ widgets.RenderBatch(course=course, batch=batch) }}
{% if batch.description %} -

Batch Details

- {{ frappe.utils.md_to_html(batch.description) }} +
+

Batch Details

+ {{ frappe.utils.md_to_html(batch.description) }} +
{% endif %} {% if course.is_mentor(frappe.session.user) %} diff --git a/community/www/batch/learn.py b/community/www/batch/learn.py index 4f031eab..08ccb05e 100644 --- a/community/www/batch/learn.py +++ b/community/www/batch/learn.py @@ -1,6 +1,7 @@ from re import I import frappe from . import utils +from frappe.utils import cstr def get_context(context): utils.get_common_context(context) @@ -10,9 +11,10 @@ def get_context(context): lesson_number = f"{chapter_index}.{lesson_index}" course_name = context.course.name - + print(chapter_index, lesson_index) if not chapter_index or not lesson_index: index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1" + print(index_) frappe.local.flags.redirect_location = context.batch.get_learn_url(index_) raise frappe.Redirect @@ -33,8 +35,9 @@ def get_context(context): def get_chapter_title(course_name, lesson_number): if not lesson_number: return - chapter_index = lesson_number.split(".")[0] - lesson_index = lesson_number.split(".")[1] + lesson_split = cstr(lesson_number).split(".") + chapter_index = lesson_split[0] + lesson_index = lesson_split[1] chapter_name = frappe.db.get_value("Chapter", {"course": course_name, "index_": chapter_index}, "name") return frappe.db.get_value("Lesson", {"chapter": chapter_name, "index_": lesson_index}, "title") diff --git a/community/www/batch/members.html b/community/www/batch/members.html index 035e12dd..32baa20d 100644 --- a/community/www/batch/members.html +++ b/community/www/batch/members.html @@ -19,23 +19,19 @@ {% macro MembersList(members) %}
{% for member in members %} -
-
- {{ widgets.Avatar(member=member, avatar_class="avatar-large") }} -
-
-
- +
+ {{ widgets.Avatar(member=member, avatar_class="avatar-large") }} +
+
+

{{ member.full_name }}

{% if course.is_mentor(member.name) %} -
-
Mentor
-
+
Mentor
{% endif %}
{% if member.bio %} - {{member.bio}} + {{member.bio}} {% endif %}
diff --git a/community/www/batch/progress.html b/community/www/batch/progress.html index 983077b1..0762d835 100644 --- a/community/www/batch/progress.html +++ b/community/www/batch/progress.html @@ -26,7 +26,7 @@
{{ widgets.BatchTabs(course=course, batch=batch) }}
-

Batch Progress

+

Batch Progress

{% for exercise in report.exercises %}

Exercise {{exercise.index_label}}: {{exercise.title}}

diff --git a/community/www/batch/progress.py b/community/www/batch/progress.py index adfb72dd..13578ac1 100644 --- a/community/www/batch/progress.py +++ b/community/www/batch/progress.py @@ -14,12 +14,13 @@ def get_context(context): context.exercise = exercise context.report = BatchReport(context.course, context.batch) + print(context.report) class BatchReport: def __init__(self, course, batch): self.submissions = get_submissions(batch) self.exercises = self.get_exercises(course.name) - + print(self.submissions) self.submissions_by_exercise = defaultdict(list) for s in self.submissions: self.submissions_by_exercise[s.exercise].append(s) @@ -34,7 +35,7 @@ def get_submissions(batch): students = batch.get_students() students_map = {s.email: s for s in students} names, values = nparams("s", students_map.keys()) - + print(students, names, values) sql = """ select owner, exercise, name, solution, creation, image from ( @@ -45,7 +46,7 @@ def get_submissions(batch): """.format(names) data = frappe.db.sql(sql, values=values, as_dict=True) - + print(data) for row in data: row['owner'] = students_map[row['owner']] return data diff --git a/community/www/batch/utils.py b/community/www/batch/utils.py index 24b5dd32..76c47228 100644 --- a/community/www/batch/utils.py +++ b/community/www/batch/utils.py @@ -1,21 +1,20 @@ import frappe -from community.lms.models import Course +from community.lms.models import Course, Membership def get_common_context(context): context.no_cache = 1 course_name = frappe.form_dict["course"] - batch_name = frappe.form_dict["batch"] course = Course.find(course_name) if not course: context.template = "www/404.html" return - + batch_name = Membership.get_user_batch(course_name) batch = course.get_batch(batch_name) - if not batch or not batch.is_member(frappe.session.user): + """ if not batch or not batch.is_member(frappe.session.user): frappe.local.flags.redirect_location = "/courses/" + course_name - raise frappe.Redirect + raise frappe.Redirect """ context.course = course context.batch = batch diff --git a/community/www/courses/course.html b/community/www/courses/course.html index 0d4d7ccc..0963437f 100644 --- a/community/www/courses/course.html +++ b/community/www/courses/course.html @@ -12,28 +12,20 @@
Courses / {{ course.title }}
-

{{course.title}}

+

{{course.title}}

{{ course.short_introduction }}
-
-
+
+
{{ CourseVideo(course) }} - {{ CourseDescription(course) }} + {{ widgets.InstructorSection(instructor=course.get_instructor()) }} {{ BatchSection(course) }} {{ widgets.CourseOutline(course=course, show_link=False) }}
-
- - -
{% endblock %} @@ -49,28 +41,31 @@ {% endmacro %} {% macro CourseDescription(course) %} -

Course Description

+
+

Course Description

-
- {{ frappe.utils.md_to_html(course.description) }} +
+ {{ frappe.utils.md_to_html(course.description) }} +
{% endmacro %} {% macro BatchSection(course) %} -{% if course.is_mentor(frappe.session.user) %} -{{ BatchSectionForMentors(course, course.get_batches(mentor=frappe.session.user)) }} -{% else %} -{{ BatchSectionForStudents(course, course.get_upcoming_batches()) }} -{% endif %} +
+
+ {% if course.is_mentor(frappe.session.user) %} + {{ BatchSectionForMentors(course, course.get_batches(mentor=frappe.session.user)) }} + {% else %} + {{ BatchSectionForStudents(course, course.get_upcoming_batches()) }} + {% endif %} +
+
{% endmacro %} {% macro BatchSectionForMentors(course, mentor_batches) %}

Your Batches

{% if mentor_batches %} -
{% for batch in mentor_batches %} @@ -92,14 +87,15 @@ {% macro BatchSectionForStudents(course, upcoming_batches) %} {% if upcoming_batches %} -

Upcoming Batches

- -
- {% for batch in upcoming_batches %} -
- {{ widgets.RenderBatch(course=course, batch=batch, can_join=True) }} +
+

Upcoming Batches

+
+ {% for batch in upcoming_batches %} +
+ {{ widgets.RenderBatch(course=course, batch=batch, can_join=True) }} +
+ {% endfor %}
- {% endfor %} + {% endif %}
-{% endif %} {% endmacro %} diff --git a/community/www/courses/index.html b/community/www/courses/index.html index 6a69235c..2533c6b0 100644 --- a/community/www/courses/index.html +++ b/community/www/courses/index.html @@ -10,19 +10,17 @@ {% block content %}
-
-

{{ 'Courses' }}

-
+

{{ 'All Courses' }}

{% for course in courses %} {{ course_card(course) }} {% endfor %} - {% if courses %} +
@@ -32,7 +30,7 @@ {% macro course_card(course) %}