From 7a9039090d898202d70e37fa287cce1e657656c1 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Mon, 30 Aug 2021 12:46:08 +0530 Subject: [PATCH] fix: discussions structure --- .../__init__.py | 0 .../discussion_reply.js} | 2 +- .../discussion_reply.json} | 36 ++---- .../discussion_reply.py} | 16 +-- .../test_discussion_reply.py} | 2 +- .../discussion_thread/discussion_thread.py | 48 -------- .../__init__.py | 0 .../discussion_topic.js} | 2 +- .../discussion_topic.json} | 4 +- .../discussion_topic/discussion_topic.py | 31 ++++++ .../test_discussion_topic.py} | 2 +- .../web_template/discussions/__init__.py | 0 .../web_template/discussions/discussions.html | 1 + .../web_template/discussions/discussions.json | 17 +++ .../community/widgets/DiscussionComment.html | 94 +++++++++------- .../community/widgets/DiscussionMessage.html | 103 +++++++++--------- community/patches.txt | 2 + community/public/css/style.css | 14 +-- community/templates/message_card.html | 12 -- community/templates/reply_card.html | 14 +++ community/www/batch/learn.html | 2 +- community/www/discussions/index.html | 16 +-- 22 files changed, 201 insertions(+), 217 deletions(-) rename community/community/doctype/{discussion_message => discussion_reply}/__init__.py (100%) rename community/community/doctype/{discussion_thread/discussion_thread.js => discussion_reply/discussion_reply.js} (77%) rename community/community/doctype/{discussion_message/discussion_message.json => discussion_reply/discussion_reply.json} (54%) rename community/community/doctype/{discussion_message/discussion_message.py => discussion_reply/discussion_reply.py} (51%) rename community/community/doctype/{discussion_thread/test_discussion_thread.py => discussion_reply/test_discussion_reply.py} (69%) delete mode 100644 community/community/doctype/discussion_thread/discussion_thread.py rename community/community/doctype/{discussion_thread => discussion_topic}/__init__.py (100%) rename community/community/doctype/{discussion_message/discussion_message.js => discussion_topic/discussion_topic.js} (77%) rename community/community/doctype/{discussion_thread/discussion_thread.json => discussion_topic/discussion_topic.json} (97%) create mode 100644 community/community/doctype/discussion_topic/discussion_topic.py rename community/community/doctype/{discussion_message/test_discussion_message.py => discussion_topic/test_discussion_topic.py} (69%) create mode 100644 community/community/web_template/discussions/__init__.py create mode 100644 community/community/web_template/discussions/discussions.html create mode 100644 community/community/web_template/discussions/discussions.json delete mode 100644 community/templates/message_card.html create mode 100644 community/templates/reply_card.html diff --git a/community/community/doctype/discussion_message/__init__.py b/community/community/doctype/discussion_reply/__init__.py similarity index 100% rename from community/community/doctype/discussion_message/__init__.py rename to community/community/doctype/discussion_reply/__init__.py diff --git a/community/community/doctype/discussion_thread/discussion_thread.js b/community/community/doctype/discussion_reply/discussion_reply.js similarity index 77% rename from community/community/doctype/discussion_thread/discussion_thread.js rename to community/community/doctype/discussion_reply/discussion_reply.js index 93fdaaa4..1c72808d 100644 --- a/community/community/doctype/discussion_thread/discussion_thread.js +++ b/community/community/doctype/discussion_reply/discussion_reply.js @@ -1,7 +1,7 @@ // Copyright (c) 2021, FOSS United and contributors // For license information, please see license.txt -frappe.ui.form.on('Discussion Thread', { +frappe.ui.form.on('Discussion Reply', { // refresh: function(frm) { // } diff --git a/community/community/doctype/discussion_message/discussion_message.json b/community/community/doctype/discussion_reply/discussion_reply.json similarity index 54% rename from community/community/doctype/discussion_message/discussion_message.json rename to community/community/doctype/discussion_reply/discussion_reply.json index 4a7d653d..f8eb7632 100644 --- a/community/community/doctype/discussion_message/discussion_message.json +++ b/community/community/doctype/discussion_reply/discussion_reply.json @@ -5,49 +5,31 @@ "editable_grid": 1, "engine": "InnoDB", "field_order": [ - "thread", - "column_break_2", - "parent_message", - "section_break_4", - "message" + "topic", + "reply" ], "fields": [ { - "fieldname": "message", + "fieldname": "reply", "fieldtype": "Long Text", "in_list_view": 1, - "label": "Message" + "label": "Reply" }, { - "fieldname": "thread", + "fieldname": "topic", "fieldtype": "Link", "in_list_view": 1, "in_standard_filter": 1, - "label": "Thread", - "options": "Discussion Thread" - }, - { - "fieldname": "column_break_2", - "fieldtype": "Column Break" - }, - { - "fieldname": "parent_message", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Parent Message", - "options": "Discussion Message" - }, - { - "fieldname": "section_break_4", - "fieldtype": "Section Break" + "label": "Topic", + "options": "Discussion Topic" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-08-12 15:59:04.811286", + "modified": "2021-08-27 15:06:51.362714", "modified_by": "Administrator", "module": "Community", - "name": "Discussion Message", + "name": "Discussion Reply", "owner": "Administrator", "permissions": [ { diff --git a/community/community/doctype/discussion_message/discussion_message.py b/community/community/doctype/discussion_reply/discussion_reply.py similarity index 51% rename from community/community/doctype/discussion_message/discussion_message.py rename to community/community/doctype/discussion_reply/discussion_reply.py index 3a9e672d..2ba1f1ed 100644 --- a/community/community/doctype/discussion_message/discussion_message.py +++ b/community/community/doctype/discussion_reply/discussion_reply.py @@ -3,20 +3,22 @@ import frappe from frappe.model.document import Document -from community.widgets import Widget, Widgets +from community.widgets import Widgets -class DiscussionMessage(Document): +class DiscussionReply(Document): def after_insert(self): data = { - "message": self, + "reply": self, + "topic": { + "name": self.topic + }, "widgets": Widgets() } - template = frappe.render_template("community/templates/message_card.html", data) - thread_info = frappe.db.get_value("Discussion Thread", self.thread, ["reference_doctype", "reference_docname"], as_dict=True) + template = frappe.render_template("community/templates/reply_card.html", data) + topic_info = frappe.db.get_value("Discussion Topic", self.topic, ["reference_doctype", "reference_docname", "name", "title"], as_dict=True) frappe.publish_realtime(event="publish_message", message = { - "thread": self.thread, "template": template, - "thread_info": thread_info + "topic_info": topic_info }, after_commit=True) diff --git a/community/community/doctype/discussion_thread/test_discussion_thread.py b/community/community/doctype/discussion_reply/test_discussion_reply.py similarity index 69% rename from community/community/doctype/discussion_thread/test_discussion_thread.py rename to community/community/doctype/discussion_reply/test_discussion_reply.py index b692f56e..45485242 100644 --- a/community/community/doctype/discussion_thread/test_discussion_thread.py +++ b/community/community/doctype/discussion_reply/test_discussion_reply.py @@ -4,5 +4,5 @@ # import frappe import unittest -class TestDiscussionThread(unittest.TestCase): +class TestDiscussionReply(unittest.TestCase): pass diff --git a/community/community/doctype/discussion_thread/discussion_thread.py b/community/community/doctype/discussion_thread/discussion_thread.py deleted file mode 100644 index cef7ef57..00000000 --- a/community/community/doctype/discussion_thread/discussion_thread.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (c) 2021, FOSS United and contributors -# For license information, please see license.txt - -import frappe -from frappe.model.document import Document - -class DiscussionThread(Document): - pass - -@frappe.whitelist() -def submit_discussion(doctype, docname, message, title=None, thread_name=None): - thread = [] - filters = {} - if doctype and docname: - filters = { - "reference_doctype": doctype, - "reference_docname": docname - } - - elif thread_name: - filters = { - "name": thread_name - } - - if filters: - thread = frappe.get_all("Discussion Thread",filters) - if len(thread): - thread = thread[0] - save_message(message, thread) - - else: - thread = frappe.get_doc({ - "doctype": "Discussion Thread", - "title": title, - "reference_doctype": doctype, - "reference_docname": docname - }) - thread.save(ignore_permissions=True) - save_message(message, thread) - - return thread.name - -def save_message(message, thread): - frappe.get_doc({ - "doctype": "Discussion Message", - "message": message, - "thread": thread.name - }).save(ignore_permissions=True) diff --git a/community/community/doctype/discussion_thread/__init__.py b/community/community/doctype/discussion_topic/__init__.py similarity index 100% rename from community/community/doctype/discussion_thread/__init__.py rename to community/community/doctype/discussion_topic/__init__.py diff --git a/community/community/doctype/discussion_message/discussion_message.js b/community/community/doctype/discussion_topic/discussion_topic.js similarity index 77% rename from community/community/doctype/discussion_message/discussion_message.js rename to community/community/doctype/discussion_topic/discussion_topic.js index 6044a179..2eebd44c 100644 --- a/community/community/doctype/discussion_message/discussion_message.js +++ b/community/community/doctype/discussion_topic/discussion_topic.js @@ -1,7 +1,7 @@ // Copyright (c) 2021, FOSS United and contributors // For license information, please see license.txt -frappe.ui.form.on('Discussion Message', { +frappe.ui.form.on('Discussion Topic', { // refresh: function(frm) { // } diff --git a/community/community/doctype/discussion_thread/discussion_thread.json b/community/community/doctype/discussion_topic/discussion_topic.json similarity index 97% rename from community/community/doctype/discussion_thread/discussion_thread.json rename to community/community/doctype/discussion_topic/discussion_topic.json index 5442c60b..c82eca04 100644 --- a/community/community/doctype/discussion_thread/discussion_thread.json +++ b/community/community/doctype/discussion_topic/discussion_topic.json @@ -33,7 +33,7 @@ "modified": "2021-08-11 12:29:43.564123", "modified_by": "Administrator", "module": "Community", - "name": "Discussion Thread", + "name": "Discussion Topic", "owner": "Administrator", "permissions": [ { @@ -54,4 +54,4 @@ "sort_order": "DESC", "title_field": "title", "track_changes": 1 -} \ No newline at end of file +} diff --git a/community/community/doctype/discussion_topic/discussion_topic.py b/community/community/doctype/discussion_topic/discussion_topic.py new file mode 100644 index 00000000..a340f837 --- /dev/null +++ b/community/community/doctype/discussion_topic/discussion_topic.py @@ -0,0 +1,31 @@ +# Copyright (c) 2021, FOSS United and contributors +# For license information, please see license.txt + +import frappe +from frappe.model.document import Document + +class DiscussionTopic(Document): + pass + +@frappe.whitelist() +def submit_discussion(doctype, docname, reply, title, topic_name=None): + if topic_name: + save_message(reply, topic_name) + return topic_name + + topic = frappe.get_doc({ + "doctype": "Discussion Topic", + "title": title, + "reference_doctype": doctype, + "reference_docname": docname + }) + topic.save(ignore_permissions=True) + save_message(reply, topic.name) + return topic.name + +def save_message(reply, topic): + frappe.get_doc({ + "doctype": "Discussion Reply", + "reply": reply, + "topic": topic + }).save(ignore_permissions=True) diff --git a/community/community/doctype/discussion_message/test_discussion_message.py b/community/community/doctype/discussion_topic/test_discussion_topic.py similarity index 69% rename from community/community/doctype/discussion_message/test_discussion_message.py rename to community/community/doctype/discussion_topic/test_discussion_topic.py index 7d7145a8..56eaec14 100644 --- a/community/community/doctype/discussion_message/test_discussion_message.py +++ b/community/community/doctype/discussion_topic/test_discussion_topic.py @@ -4,5 +4,5 @@ # import frappe import unittest -class TestDiscussionMessage(unittest.TestCase): +class TestDiscussionTopic(unittest.TestCase): pass diff --git a/community/community/web_template/discussions/__init__.py b/community/community/web_template/discussions/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/community/community/web_template/discussions/discussions.html b/community/community/web_template/discussions/discussions.html new file mode 100644 index 00000000..c738992d --- /dev/null +++ b/community/community/web_template/discussions/discussions.html @@ -0,0 +1 @@ +{{ widgets.DiscussionMessage }} diff --git a/community/community/web_template/discussions/discussions.json b/community/community/web_template/discussions/discussions.json new file mode 100644 index 00000000..d87fa90d --- /dev/null +++ b/community/community/web_template/discussions/discussions.json @@ -0,0 +1,17 @@ +{ + "__islocal": true, + "__unsaved": 1, + "creation": "2021-08-30 12:42:31.550200", + "docstatus": 0, + "doctype": "Web Template", + "fields": [], + "idx": 0, + "modified": "2021-08-30 12:42:31.550200", + "modified_by": "Administrator", + "module": "Community", + "name": "Discussions", + "owner": "Administrator", + "standard": 1, + "template": "", + "type": "Section" +} \ No newline at end of file diff --git a/community/community/widgets/DiscussionComment.html b/community/community/widgets/DiscussionComment.html index d5c8e6b9..a1126de7 100644 --- a/community/community/widgets/DiscussionComment.html +++ b/community/community/widgets/DiscussionComment.html @@ -1,36 +1,49 @@ -
+ - + {% endblock %}