diff --git a/community/community/doctype/community_member/community_member.py b/community/community/doctype/community_member/community_member.py
index d90fe498..333771f0 100644
--- a/community/community/doctype/community_member/community_member.py
+++ b/community/community/doctype/community_member/community_member.py
@@ -42,7 +42,7 @@ class CommunityMember(Document):
return frappe.db.count(
'LMS Batch Membership', {
'member': self.name,
- 'member_role': 'Mentor'
+ 'member_type': 'Mentor'
})
def __repr__(self):
diff --git a/community/lms/doctype/invite_request/invite_request.py b/community/lms/doctype/invite_request/invite_request.py
index 5b422643..12f08c88 100644
--- a/community/lms/doctype/invite_request/invite_request.py
+++ b/community/lms/doctype/invite_request/invite_request.py
@@ -11,7 +11,7 @@ from frappe.utils.password import get_decrypted_password
class InviteRequest(Document):
def on_update(self):
- if self.has_value_changed('status') and self.status == "Approved":
+ if self.has_value_changed("status") and self.status == "Approved":
self.send_email()
def create_user(self, password):
@@ -53,7 +53,7 @@ def create_invite_request(invite_email):
}).save(ignore_permissions=True)
return "OK"
except frappe.UniqueValidationError:
- frappe.throw(_("Email {0} has already been used to request an invite").format(invite_email))
+ frappe.throw(_("Email {0} has already been used to request an invitation").format(invite_email))
@frappe.whitelist(allow_guest=True)
def update_invite(data):
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 956d7df4..a9f963a3 100644
--- a/community/lms/doctype/lms_batch_membership/lms_batch_membership.py
+++ b/community/lms/doctype/lms_batch_membership/lms_batch_membership.py
@@ -29,7 +29,7 @@ class LMSBatchMembership(Document):
frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch))
@frappe.whitelist()
-def create_membership(batch, course, member=None, member_type="Student", role="Member"):
+def create_membership(batch, course=None, member=None, member_type="Student", role="Member"):
if not member:
member = frappe.db.get_value("Community Member", {"email": frappe.session.user}, "name")
frappe.get_doc({
@@ -39,5 +39,7 @@ def create_membership(batch, course, member=None, member_type="Student", role="M
"member_type": member_type,
"member": member
}).save(ignore_permissions=True)
- course_slug = frappe.db.get_value("LMS Course", {"title": course}, ["slug"])
- return course_slug
+ if course:
+ course_slug = frappe.db.get_value("LMS Course", {"title": course}, ["slug"])
+ return course_slug
+ return "OK"
diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py
index f53e2c03..6ff80f45 100644
--- a/community/lms/doctype/lms_course/lms_course.py
+++ b/community/lms/doctype/lms_course/lms_course.py
@@ -97,7 +97,7 @@ class LMSCourse(Document):
for mentor in mentors:
member = frappe.get_doc("Community Member", mentor.mentor)
# TODO: change this to count query
- member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member, "member_type": "Mentor"}))
+ member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"}))
course_mentors.append(member)
return course_mentors
@@ -108,9 +108,9 @@ class LMSCourse(Document):
return False
member = self.get_community_member(email)
return frappe.db.exists({
- 'doctype': 'LMS Course Mentor Mapping',
+ "doctype": "LMS Course Mentor Mapping",
"course": self.name,
- "member": member
+ "mentor": member
})
def get_instructor(self):
@@ -131,15 +131,30 @@ class LMSCourse(Document):
memberships = frappe.db.get_all(
"LMS Batch Membership",
{"member": member},
- ["name"], as_dict=1)
+ ["batch"])
batch_names = {m.batch for m in memberships}
- return [b for b in batches if b.name in batch_names]
+ mentor_batches = [b for b in batches if b.name in batch_names]
+ return self.get_batch_mentors(mentor_batches)
def get_upcoming_batches(self):
now = frappe.utils.nowdate()
- return find_all("LMS Batch",
+ batches = find_all("LMS Batch",
course=self.name,
start_date=[">", now])
+ batches = self.get_batch_mentors(batches)
+ return batches
+
+ def get_batch_mentors(self, batches):
+ for batch in batches:
+ batch.mentors = []
+ mentors = frappe.get_all(
+ "LMS Batch Membership",
+ {"batch": batch.name, "member_type": "Mentor"},
+ ["member"])
+ for mentor in mentors:
+ member = frappe.db.get_value("Community Member", mentor.member, ["full_name", "photo", "abbr"], as_dict=1)
+ batch.mentors.append(member)
+ return batches
def find_all(doctype, order_by=None, **filters):
"""Queries the database for documents of a doctype matching given filters.
diff --git a/community/public/css/style.css b/community/public/css/style.css
index f6ccce78..0038f26d 100644
--- a/community/public/css/style.css
+++ b/community/public/css/style.css
@@ -287,6 +287,7 @@ img.profile-photo {
}
.message-section {
- margin-left: 5%;
+ margin-left: 3%;
display: inline-block;
+ width: 95%;
}
diff --git a/community/www/courses/about/index.html b/community/www/courses/about/index.html
index 1b17616c..ef417228 100644
--- a/community/www/courses/about/index.html
+++ b/community/www/courses/about/index.html
@@ -16,7 +16,7 @@
{% if batch.description %}
{{ BatchDetails(batch.description) }}
{% endif %}
- {{ MentorsSection(mentors, True) }}
+ {{ MentorsSection(mentors, True, course.name) }}
{% endblock %}
@@ -43,4 +43,4 @@
{{ frappe.utils.md_to_html(description) }}
-{% endmacro %}
\ No newline at end of file
+{% endmacro %}
diff --git a/community/www/courses/about/index.py b/community/www/courses/about/index.py
index 238177a6..780fee44 100644
--- a/community/www/courses/about/index.py
+++ b/community/www/courses/about/index.py
@@ -11,13 +11,11 @@ def get_context(context):
context.instructor = get_instructor(context.course.owner)
context.batch = get_batch(context.batch_code)
context.mentors = get_mentors(context.batch.name)
- print(context.mentors)
def get_mentors(batch):
mentors = []
memberships = frappe.get_all("LMS Batch Membership", {"batch": batch, "member_type": "Mentor"}, ["member"])
for membership in memberships:
- member = frappe.db.get_value("Community Member", membership.member, ["name","full_name"], as_dict=True)
- member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"}))
+ member = frappe.get_doc("Community Member", membership.member)
mentors.append(member)
- return mentors
\ No newline at end of file
+ return mentors
diff --git a/community/www/courses/course.html b/community/www/courses/course.html
index 88f60111..23e82643 100644
--- a/community/www/courses/course.html
+++ b/community/www/courses/course.html
@@ -10,7 +10,7 @@
@@ -86,9 +86,9 @@
{% if can_manage %}
- Manage
+ Manage
{% else %}
- Join this Batch
+ Join this Batch
{% endif %}
@@ -123,11 +123,13 @@
{% macro BatchSectionForStudents(course, upcoming_batches) %}
Upcoming Batches
- {% for batch in upcoming_batches %}
-
- {{ RenderBatch(batch, can_manage=False) }}
+
+ {% for batch in upcoming_batches %}
+
+ {{ RenderBatch(batch, can_manage=False) }}
+
+ {% endfor %}
- {% endfor %}
{% endmacro %}
{% macro CourseOutline(course) %}
diff --git a/community/www/courses/course.js b/community/www/courses/course.js
index 79683fde..ce08b2e0 100644
--- a/community/www/courses/course.js
+++ b/community/www/courses/course.js
@@ -3,18 +3,19 @@ frappe.ready(() => {
frappe.call({
'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested',
'args': {
- course: decodeURIComponent($(".course-title").attr("data-course")),
+ course: decodeURIComponent($("#course-title").attr("data-course")),
},
'callback': (data) => {
if (data.message) {
- $(".mentor-request").addClass("hide");
- $(".already-applied").removeClass("hide")
+ $("#mentor-request").addClass("hide");
+ $("#already-applied").removeClass("hide")
}
}
})
}
- $(".apply-now").click((e) => {
+ $("#apply-now").click((e) => {
+ e.preventDefault();
if (frappe.session.user == "Guest") {
window.location.href = "/login";
return;
@@ -26,14 +27,15 @@ frappe.ready(() => {
},
"callback": (data) => {
if (data.message == "OK") {
- $(".mentor-request").addClass("hide");
- $(".already-applied").removeClass("hide")
+ $("#mentor-request").addClass("hide");
+ $("#already-applied").removeClass("hide")
}
}
})
})
- $(".cancel-request").click((e) => {
+ $("#cancel-request").click((e) => {
+ e.preventDefault()
frappe.call({
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.cancel_request",
"args": {
@@ -41,14 +43,15 @@ frappe.ready(() => {
},
"callback": (data) => {
if (data.message == "OK") {
- $(".mentor-request").removeClass("hide");
- $(".already-applied").addClass("hide")
+ $("#mentor-request").removeClass("hide");
+ $("#already-applied").addClass("hide")
}
}
})
})
$(".join-batch").click((e) => {
+ e.preventDefault()
if (frappe.session.user == "Guest") {
window.location.href = "/login";
return;
@@ -62,7 +65,6 @@ frappe.ready(() => {
"callback": (data) => {
if (data.message == "OK") {
frappe.msgprint(__("You are now a student of this course."))
- $(".upcoming-batches").addClass("hide")
}
}
})
diff --git a/community/www/dashboard/index.py b/community/www/dashboard/index.py
index 9ca3df4f..1172b77a 100644
--- a/community/www/dashboard/index.py
+++ b/community/www/dashboard/index.py
@@ -1,38 +1,42 @@
import frappe
-from ...lms.doctype.lms_sketch.lms_sketch import get_recent_sketches
+from community.lms.models import Sketch
+
def get_context(context):
- context.no_cache = 1
- context.member = frappe.get_all("Community Member", {"email": frappe.session.user}, ["name", "email", "photo", "full_name", "abbr"])[0]
- context.memberships = get_memberships(context.member.name)
- context.courses = get_courses(context.memberships)
- context.activity = get_activity(context.memberships)
- context.sketches = list(filter(lambda x: x.owner == frappe.session.user, get_recent_sketches()))
+ context.no_cache = 1
+ if frappe.session.user == "Guest":
+ frappe.local.flags.redirect_location = "/login"
+ raise frappe.Redirect
+ context.member = frappe.get_all("Community Member", {"email": frappe.session.user}, ["name", "email", "photo", "full_name", "abbr"])[0]
+ context.memberships = get_memberships(context.member.name)
+ context.courses = get_courses(context.memberships)
+ context.activity = get_activity(context.memberships)
+ context.sketches = list(filter(lambda x: x.owner == frappe.session.user, Sketch.get_recent_sketches(owner=context.member.email)))
def get_memberships(member):
- return frappe.get_all("LMS Batch Membership", {"member": member}, ["batch", "member_type", "creation"])
+ return frappe.get_all("LMS Batch Membership", {"member": member}, ["batch", "member_type", "creation"])
def get_courses(memberships):
- courses = []
- for membership in memberships:
- course = frappe.db.get_value("LMS Batch", membership.batch, "course")
- course_details = frappe.get_doc("LMS Course", course)
- course_in_list = list(filter(lambda x: x.name == course_details.name, courses))
- if not len(course_in_list):
- course_details.description = course_details.description[0:100] + "..."
- course_details.joining = membership.creation
- if membership.member_type != "Student":
- course_details.member_type = membership.member_type
- courses.append(course_details)
- return courses
+ courses = []
+ for membership in memberships:
+ course = frappe.db.get_value("LMS Batch", membership.batch, "course")
+ course_details = frappe.get_doc("LMS Course", course)
+ course_in_list = list(filter(lambda x: x.name == course_details.name, courses))
+ if not len(course_in_list):
+ course_details.description = course_details.description[0:100] + "..."
+ course_details.joining = membership.creation
+ if membership.member_type != "Student":
+ course_details.member_type = membership.member_type
+ courses.append(course_details)
+ return courses
def get_activity(memberships):
- messages, courses = [], {}
- batches = [x.batch for x in memberships]
- for batch in batches:
- courses[batch] = frappe.db.get_value("LMS Batch", batch, "course")
- messages = frappe.get_all("LMS Message", {"batch": ["in", ",".join(batches)]}, ["message", "author", "creation", "batch"], order_by='creation desc')
- for message in messages:
- message.course = courses[message.batch]
- message.profile, message.full_name, message.abbr = frappe.db.get_value("Community Member", message.author, ["photo", "full_name", "abbr"])
- return messages
\ No newline at end of file
+ messages, courses = [], {}
+ batches = [x.batch for x in memberships]
+ for batch in batches:
+ courses[batch] = frappe.db.get_value("LMS Batch", batch, "course")
+ messages = frappe.get_all("LMS Message", {"batch": ["in", ",".join(batches)]}, ["message", "author", "creation", "batch"], order_by='creation desc')
+ for message in messages:
+ message.course = courses[message.batch]
+ message.profile, message.full_name, message.abbr = frappe.db.get_value("Community Member", message.author, ["photo", "full_name", "abbr"])
+ return messages
diff --git a/community/www/macros/common_macro.html b/community/www/macros/common_macro.html
index ab21effd..85e7d6b5 100644
--- a/community/www/macros/common_macro.html
+++ b/community/www/macros/common_macro.html
@@ -6,7 +6,7 @@
{% endmacro %}
-{% macro MentorsSection(mentors, is_mentor) %}
+{% macro MentorsSection(mentors, is_mentor, course_name) %}
Mentors
{% for m in mentors %}
@@ -15,10 +15,15 @@
{% endfor %}
{% if not is_mentor %}
-
+
Interested to become a mentor?
-
+
+
+
+ You've applied to become a mentor for this course. Your request is currently under review.
+
+ If you are not any more interested to mentor this course, you can
cancel your application .
{% endif %}
{% endmacro %}
@@ -26,7 +31,7 @@
{% macro BatchHearder(course_name, member_count) %}
-
{{course_name}}
-
{{member_count}} members
+
{{course_name}}
+
{{member_count}} members
{% endmacro %}
diff --git a/community/www/profiles/profile.py b/community/www/profiles/profile.py
index 9fb6b74b..d4229a30 100644
--- a/community/www/profiles/profile.py
+++ b/community/www/profiles/profile.py
@@ -8,7 +8,7 @@ def get_context(context):
if not context.member:
context.template = "www/404.html"
else:
- context.sketches = Sketch.get_recent_sketches(context.member.email)
+ context.sketches = Sketch.get_recent_sketches(owner=context.member.email)
def get_member(username):
try: