Merge pull request #281 from pateljannat/rating-field
This commit is contained in:
@@ -312,8 +312,15 @@ class LMSCourse(Document):
|
|||||||
},
|
},
|
||||||
["review", "rating", "owner"],
|
["review", "rating", "owner"],
|
||||||
order_by= "creation desc")
|
order_by= "creation desc")
|
||||||
|
out_of_ratings = frappe.db.get_all("DocField",
|
||||||
|
{
|
||||||
|
"parent": "LMS Course Review",
|
||||||
|
"fieldtype": "Rating"
|
||||||
|
},
|
||||||
|
["options"])
|
||||||
|
out_of_ratings = (len(out_of_ratings) and out_of_ratings[0].options) or 5
|
||||||
for review in reviews:
|
for review in reviews:
|
||||||
|
review.rating = review.rating * out_of_ratings
|
||||||
review.owner_details = frappe.get_doc("User", review.owner)
|
review.owner_details = frappe.get_doc("User", review.owner)
|
||||||
|
|
||||||
return reviews
|
return reviews
|
||||||
|
|||||||
@@ -3,12 +3,21 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.utils import cint
|
||||||
|
|
||||||
class LMSCourseReview(Document):
|
class LMSCourseReview(Document):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def submit_review(rating, review, course):
|
def submit_review(rating, review, course):
|
||||||
|
out_of_ratings = frappe.db.get_all("DocField",
|
||||||
|
{
|
||||||
|
"parent": "LMS Course Review",
|
||||||
|
"fieldtype": "Rating"
|
||||||
|
},
|
||||||
|
["options"])
|
||||||
|
out_of_ratings = (len(out_of_ratings) and out_of_ratings[0].options) or 5
|
||||||
|
rating = cint(rating)/out_of_ratings
|
||||||
frappe.get_doc({
|
frappe.get_doc({
|
||||||
"doctype": "LMS Course Review",
|
"doctype": "LMS Course Review",
|
||||||
"rating": rating,
|
"rating": rating,
|
||||||
|
|||||||
@@ -192,10 +192,7 @@ var submit_review = (e) => {
|
|||||||
callback: (data) => {
|
callback: (data) => {
|
||||||
if (data.message == "OK") {
|
if (data.message == "OK") {
|
||||||
$(".review-modal").modal("hide");
|
$(".review-modal").modal("hide");
|
||||||
frappe.msgprint("Thanks for providing your feedback!");
|
window.location.reload();
|
||||||
setTimeout(() => {
|
|
||||||
window.location.reload();
|
|
||||||
}, 2000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user