diff --git a/community/community/doctype/community_member/community_member.py b/community/community/doctype/community_member/community_member.py
index 7661b733..294ca812 100644
--- a/community/community/doctype/community_member/community_member.py
+++ b/community/community/doctype/community_member/community_member.py
@@ -35,7 +35,7 @@ def create_member_from_user(doc, method):
member = frappe.get_doc({
"doctype": "Community Member",
"full_name": doc.full_name,
- "username": doc.username if len(doc.username) > 3 else doc.username + "_community",
+ "username": doc.username if len(doc.username) > 3 else ("").join([ s for s in doc.full_name.split() ]),
"email": doc.email,
"route": doc.username,
"owner": doc.email
diff --git a/community/community/utils.py b/community/community/utils.py
index 6da13fbf..28293d3a 100644
--- a/community/community/utils.py
+++ b/community/community/utils.py
@@ -1 +1,18 @@
-import frappe
\ No newline at end of file
+import frappe
+
+def create_members_from_users():
+ users = frappe.get_all("User", ["email"])
+ for user in users:
+ if not frappe.db.get_value("Community Member", {"email": user.email}, "name"):
+ doc = frappe.get_doc("User", {"email": user.email})
+ username = doc.username if doc.username and len(doc.username) > 3 else ("").join([ s for s in doc.full_name.split() ])
+ if not frappe.db.exists("Community Member", username):
+ member = frappe.get_doc({
+ "doctype": "Community Member",
+ "full_name": doc.full_name,
+ "username": username,
+ "email": doc.email,
+ "route": doc.username,
+ "owner": doc.email
+ })
+ member.save(ignore_permissions=True)
\ No newline at end of file
diff --git a/community/lms/doctype/lms_message/lms_message.json b/community/lms/doctype/lms_message/lms_message.json
index e1562c85..df6a85b3 100644
--- a/community/lms/doctype/lms_message/lms_message.json
+++ b/community/lms/doctype/lms_message/lms_message.json
@@ -14,18 +14,21 @@
{
"fieldname": "batch",
"fieldtype": "Link",
+ "in_list_view": 1,
"label": "Batch",
"options": "LMS Batch"
},
{
"fieldname": "author",
"fieldtype": "Link",
+ "in_list_view": 1,
"label": "Author",
"options": "Community Member"
},
{
"fieldname": "message",
"fieldtype": "Markdown Editor",
+ "in_list_view": 1,
"label": "Message"
},
{
@@ -37,7 +40,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2021-03-22 13:57:50.500746",
+ "modified": "2021-03-23 18:06:25.086377",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Message",
diff --git a/community/lms/web_form/add_messages/add_messages.json b/community/lms/web_form/add_messages/add_messages.json
index 80c36fee..b78ba8b8 100644
--- a/community/lms/web_form/add_messages/add_messages.json
+++ b/community/lms/web_form/add_messages/add_messages.json
@@ -19,13 +19,13 @@
"is_standard": 1,
"login_required": 1,
"max_attachment_size": 0,
- "modified": "2021-03-23 15:10:24.681090",
+ "modified": "2021-03-23 19:25:54.984968",
"modified_by": "Administrator",
"module": "LMS",
"name": "add-messages",
"owner": "Administrator",
"payment_button_label": "Buy Now",
- "published": 1,
+ "published": 0,
"route": "add-messages",
"route_to_success_link": 0,
"show_attachments": 0,
diff --git a/community/www/courses/course.html b/community/www/courses/course.html
index 4a70f82c..9dc74046 100644
--- a/community/www/courses/course.html
+++ b/community/www/courses/course.html
@@ -39,11 +39,21 @@
{{ frappe.utils.md_to_html(course.description) }}
+
+
+ {% for topic in course.topics %}
+
+
+
{{topic.preview | markdown }}
+
+ {% endfor %}
+
+
{% if batches %}
-
+
{% endif %}
+
+
+
+
{% if discussions %}
-
- Add Message
-
{% for message in discussions %}
@@ -68,15 +79,5 @@
-
-
- {% for topic in course.topics %}
-
-
-
{{topic.preview | markdown }}
-
- {% endfor %}
-
-
{% endblock %}
diff --git a/community/www/courses/course.js b/community/www/courses/course.js
index 787204f7..667016f6 100644
--- a/community/www/courses/course.js
+++ b/community/www/courses/course.js
@@ -1,25 +1,48 @@
frappe.ready(() => {
- var dropdown = document.getElementById("batches-dropdown")
+ var dropdown = document.getElementById("batches-dropdown");
if (dropdown) {
dropdown.onchange = () => {
- frappe.call("community.www.courses.course.get_messages", {batch: dropdown.value}, (data) => {
- var href_params = new URLSearchParams($(".add-message").children("a")[0].href)
- $(".add-message").children("a")[0].href = `/add-messages?new=1&batch=${dropdown.value}&author=${href_params.get("author")}&course=${href_params.get("course")}`
- if(data.message){
- $(".discussions").children().remove()
+ $(".send-message").attr("data-batch", dropdown.value)
+ frappe.call("community.www.courses.course.get_messages", { batch: dropdown.value }, (data) => {
+ if (data.message) {
+ $(".discussions").children().remove();
for (var i = 0; i < data.message.length; i++) {
- var message = data.message[i]
- var element = `
-
${message.author}
- ${ message.message }
-
${ message.creation }
-
`
- $(".discussions").append(element)
+ var element = add_message(data.message[i])
+ $(".discussions").append(element);
}
}
})
}
}
+ $(".send-message").click((e) => {
+ var message = $(".message-text").val().trim();
+ if (message) {
+ frappe.call({
+ "method": "community.www.courses.course.save_message",
+ "args": {
+ "batch": decodeURIComponent($(e.target).attr("data-batch")),
+ "author": decodeURIComponent($(e.target).attr("data-author")),
+ "message": message
+ },
+ "callback": (data) => {
+ $(".message-text").val("");
+ var element = add_message(data.message, true)
+ $(".discussions").prepend(element);
+ }
+ })
+ }
+ else {
+ $(".message-text").val("");
+ }
+ })
+ var add_message = (message, session_user=false) => {
+ var author = session_user ? "You" : message.author
+ return `
+
${author}
+ ${message.message}
+
${message.creation}
+
`;
+ }
/* if(frappe.session.user != "Guest"){
frappe.call('community.www.courses.course.has_enrolled', { course: get_search_params().get("course") }, (data) => {
if (data.message) {
@@ -28,7 +51,7 @@ frappe.ready(() => {
})
} */
})
-/*
+/*
var show_enrollment_badge = () => {
$(".btn-enroll").addClass("hide");
$(".enrollment-badge").removeClass("hide");
diff --git a/community/www/courses/course.py b/community/www/courses/course.py
index db0a30b7..d9f6e5f6 100644
--- a/community/www/courses/course.py
+++ b/community/www/courses/course.py
@@ -66,3 +66,14 @@ def enroll(course):
"user": frappe.session.user
}).save()
+@frappe.whitelist()
+def save_message(message, author, batch):
+ doc = frappe.get_doc({
+ "doctype": "LMS Message",
+ "author": author,
+ "batch": batch,
+ "message": message
+ })
+ doc.save(ignore_permissions=True)
+ return doc
+
diff --git a/community/www/hackathons/project.js b/community/www/hackathons/project.js
index f4b71f6a..4fd14653 100644
--- a/community/www/hackathons/project.js
+++ b/community/www/hackathons/project.js
@@ -13,15 +13,17 @@ var set_likes = function (liked, likes) {
// set initial likes
frappe.ready(() => {
- var url_params = new URLSearchParams(window.location.search);
- frappe.call('community.www.hackathons.project.like', { project: url_params.get("project"), initial: true }, (data) => {
+ frappe.call('community.www.hackathons.project.like', { project: get_url_arg().get("project"), initial: true }, (data) => {
set_likes(data.message.action == "Liked", data.message.likes)
})
})
+var get_url_arg = () => {
+ return new URLSearchParams(window.location.search);
+}
// like - unlike
$('.btn-like').on('click', (e) => {
- frappe.call('community.www.hackathons.project.like', { project: $(e.target).attr("data-project") }, (data) => {
+ frappe.call('community.www.hackathons.project.like', { project: get_url_arg().get("project") }, (data) => {
set_likes(data.message.action == "Liked", data.message.likes);
});
});