From e7d116f31c0c5cb90c0ec2644ddc0fb7b68d18d2 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Thu, 20 May 2021 16:52:51 +0530 Subject: [PATCH] chore: removed obsolete doctype LMS Topic It has been replaced by Chapter and Lesson. Moved the section_parser from lms_topic directory to the lms. --- community/lms/doctype/lesson/lesson.py | 2 +- .../lms/doctype/lms_course/lms_course.py | 11 -- community/lms/doctype/lms_topic/__init__.py | 0 community/lms/doctype/lms_topic/lms_topic.js | 8 -- .../lms/doctype/lms_topic/lms_topic.json | 89 --------------- community/lms/doctype/lms_topic/lms_topic.py | 43 ------- .../lms/doctype/lms_topic/test_lms_topic.py | 10 -- .../{doctype/lms_topic => }/section_parser.py | 0 community/www/courses/topic.html | 108 ------------------ community/www/courses/topic.py | 33 ------ 10 files changed, 1 insertion(+), 303 deletions(-) delete mode 100644 community/lms/doctype/lms_topic/__init__.py delete mode 100644 community/lms/doctype/lms_topic/lms_topic.js delete mode 100644 community/lms/doctype/lms_topic/lms_topic.json delete mode 100644 community/lms/doctype/lms_topic/lms_topic.py delete mode 100644 community/lms/doctype/lms_topic/test_lms_topic.py rename community/lms/{doctype/lms_topic => }/section_parser.py (100%) delete mode 100644 community/www/courses/topic.html delete mode 100644 community/www/courses/topic.py diff --git a/community/lms/doctype/lesson/lesson.py b/community/lms/doctype/lesson/lesson.py index c544f774..979515ea 100644 --- a/community/lms/doctype/lesson/lesson.py +++ b/community/lms/doctype/lesson/lesson.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document -from ..lms_topic.section_parser import SectionParser +from ...section_parser import SectionParser class Lesson(Document): def before_save(self): diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py index 914e5c90..07e29145 100644 --- a/community/lms/doctype/lms_course/lms_course.py +++ b/community/lms/doctype/lms_course/lms_course.py @@ -35,17 +35,6 @@ class LMSCourse(Document): def __repr__(self): return f"" - def get_topic(self, slug): - """Returns the topic with given slug in this course as a Document. - """ - result = frappe.get_all( - "LMS Topic", - filters={"course": self.name, "slug": slug}) - - if result: - row = result[0] - return frappe.get_doc('LMS Topic', row['name']) - def has_mentor(self, email): """Checks if this course has a mentor with given email. """ diff --git a/community/lms/doctype/lms_topic/__init__.py b/community/lms/doctype/lms_topic/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/community/lms/doctype/lms_topic/lms_topic.js b/community/lms/doctype/lms_topic/lms_topic.js deleted file mode 100644 index 36c3fee7..00000000 --- a/community/lms/doctype/lms_topic/lms_topic.js +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2021, FOSS United and contributors -// For license information, please see license.txt - -frappe.ui.form.on('LMS Topic', { - // refresh: function(frm) { - - // } -}); diff --git a/community/lms/doctype/lms_topic/lms_topic.json b/community/lms/doctype/lms_topic/lms_topic.json deleted file mode 100644 index 81cc6477..00000000 --- a/community/lms/doctype/lms_topic/lms_topic.json +++ /dev/null @@ -1,89 +0,0 @@ -{ - "actions": [], - "allow_guest_to_view": 1, - "creation": "2021-03-02 07:20:41.686573", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "course", - "title", - "slug", - "preview", - "description", - "order", - "sections" - ], - "fields": [ - { - "fieldname": "title", - "fieldtype": "Data", - "in_list_view": 1, - "label": "Title", - "reqd": 1 - }, - { - "fieldname": "description", - "fieldtype": "Markdown Editor", - "label": "Description" - }, - { - "fieldname": "course", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Course", - "options": "LMS Course", - "reqd": 1 - }, - { - "fieldname": "order", - "fieldtype": "Int", - "label": "Order" - }, - { - "fieldname": "preview", - "fieldtype": "Markdown Editor", - "label": "Preview" - }, - { - "fieldname": "sections", - "fieldtype": "Table", - "label": "Sections", - "options": "LMS Section" - }, - { - "description": "The slug of the topic. Autogenerated from the title if not specified.", - "fieldname": "slug", - "fieldtype": "Data", - "label": "Slug" - } - ], - "index_web_pages_for_search": 1, - "links": [], - "modified": "2021-04-06 14:12:48.514062", - "modified_by": "Administrator", - "module": "LMS", - "name": "LMS Topic", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "share": 1, - "write": 1 - } - ], - "search_fields": "title", - "sort_field": "creation", - "sort_order": "ASC", - "title_field": "title", - "track_changes": 1, - "track_seen": 1, - "track_views": 1 -} \ No newline at end of file diff --git a/community/lms/doctype/lms_topic/lms_topic.py b/community/lms/doctype/lms_topic/lms_topic.py deleted file mode 100644 index fec5e261..00000000 --- a/community/lms/doctype/lms_topic/lms_topic.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2021, FOSS United and contributors -# For license information, please see license.txt - -from __future__ import unicode_literals -import frappe -from frappe.model.document import Document -from .section_parser import SectionParser -from ...utils import slugify - -class LMSTopic(Document): - def before_save(self): - course = self.get_course() - if not self.slug: - self.slug = self.generate_slug(title=self.title) - - sections = SectionParser().parse(self.description or "") - self.sections = [self.make_lms_section(i, s) for i, s in enumerate(sections)] - - def get_course(self): - return frappe.get_doc("LMS Course", self.course) - - def generate_slug(self, title): - result = frappe.get_all( - 'LMS Topic', - filters={'course': self.course}, - fields=['slug']) - slugs = set([row['slug'] for row in result]) - return slugify(title, used_slugs=slugs) - - def get_sections(self): - return sorted(self.sections, key=lambda s: s.index) - - def make_lms_section(self, index, section): - s = frappe.new_doc('LMS Section', parent_doc=self, parentfield='sections') - s.type = section.type - s.label = section.label - s.contents = section.contents - s.index = index - return s - - - diff --git a/community/lms/doctype/lms_topic/test_lms_topic.py b/community/lms/doctype/lms_topic/test_lms_topic.py deleted file mode 100644 index b930c8cd..00000000 --- a/community/lms/doctype/lms_topic/test_lms_topic.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2021, FOSS United and Contributors -# See license.txt -from __future__ import unicode_literals - -# import frappe -import unittest - -class TestLMSTopic(unittest.TestCase): - pass diff --git a/community/lms/doctype/lms_topic/section_parser.py b/community/lms/section_parser.py similarity index 100% rename from community/lms/doctype/lms_topic/section_parser.py rename to community/lms/section_parser.py diff --git a/community/www/courses/topic.html b/community/www/courses/topic.html deleted file mode 100644 index e9ec070c..00000000 --- a/community/www/courses/topic.html +++ /dev/null @@ -1,108 +0,0 @@ -{% extends "templates/base.html" %} -{% from "www/macros/livecode.html" import LiveCodeEditor with context %} -{% block title %}{{topic.title}} ({{course.title}}){% endblock %} -{% block head_include %} - - - - - - - - - - - - - -{% endblock %} - -{% block content %} -
-
- - -

{{ topic.title }}

- - {% for s in topic.get_sections() %} -
- {{ render_section(s) }} -
- {% endfor %} - -
-
-{% endblock %} - -{% macro render_section(s) %} - {% if s.type == "text" %} - {{ render_section_text(s) }} - {% elif s.type == "example" or s.type == "code" %} - {{ LiveCodeEditor(s.name, s.get_latest_code_for_user()) }} - {% else %} -
Unknown section type: {{s.type}}
- {% endif %} -{% endmacro %} - -{% macro render_section_text(s) %} -
-
- {{ frappe.utils.md_to_html(s.contents) }} -
-
-{% endmacro %} - -{%- block script %} - {{ super() }} - - -{%- endblock %} diff --git a/community/www/courses/topic.py b/community/www/courses/topic.py deleted file mode 100644 index 7abaabcb..00000000 --- a/community/www/courses/topic.py +++ /dev/null @@ -1,33 +0,0 @@ -import frappe - -def get_context(context): - context.no_cache = 1 - - try: - course_slug = frappe.form_dict['course'] - topic_slug = frappe.form_dict['topic'] - except KeyError: - context.template = 'www/404.html' - return - - course = get_course(course_slug) - topic = course and course.get_topic(topic_slug) - - if not topic: - context.template = 'www/404.html' - return - - context.course = course - context.topic = topic - context.livecode_url = get_livecode_url() - -def notfound(context): - context.template = 'www/404.html' - -def get_livecode_url(): - doc = frappe.get_doc("LMS Settings") - return doc.livecode_url - -def get_course(slug): - course = frappe.db.get_value('LMS Course', {"slug": slug}, ["name"], as_dict=1) - return course and frappe.get_doc('LMS Course', course['name'])