diff --git a/community/hooks.py b/community/hooks.py index 535a2793..fba4d694 100644 --- a/community/hooks.py +++ b/community/hooks.py @@ -137,7 +137,12 @@ primary_rules = [ {"from_route": "/hackathons/", "to_route": "hackathons/hackathon"}, {"from_route": "/hackathons//", "to_route": "hackathons/project"}, {"from_route": "/dashboard", "to_route": ""}, - {"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"} + {"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"}, + {"from_route": "/courses///learn", "to_route": "courses/learn"}, + {"from_route": "/courses///schedule", "to_route": "courses/schedule"}, + {"from_route": "/courses///members", "to_route": "courses/members"}, + {"from_route": "/courses///discuss", "to_route": "courses/discuss"}, + {"from_route": "/courses///about", "to_route": "courses/about"} ] # Any frappe default URL is blocked by profile-rules, add it here to unblock it diff --git a/community/lms/doctype/lms_batch_membership/lms_batch_membership.json b/community/lms/doctype/lms_batch_membership/lms_batch_membership.json index 1b339282..8bd1c68b 100644 --- a/community/lms/doctype/lms_batch_membership/lms_batch_membership.json +++ b/community/lms/doctype/lms_batch_membership/lms_batch_membership.json @@ -17,6 +17,7 @@ "fieldname": "batch", "fieldtype": "Link", "in_list_view": 1, + "in_standard_filter": 1, "label": "Batch", "options": "LMS Batch" }, @@ -24,6 +25,7 @@ "fieldname": "member", "fieldtype": "Link", "in_list_view": 1, + "in_standard_filter": 1, "label": "Member", "options": "Community Member" }, @@ -38,6 +40,7 @@ "fieldname": "role", "fieldtype": "Select", "in_list_view": 1, + "in_standard_filter": 1, "label": "Role", "options": "\nMember\nAdmin" }, @@ -56,7 +59,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-04-16 09:57:52.926943", + "modified": "2021-04-22 15:30:00.069946", "modified_by": "Administrator", "module": "LMS", "name": "LMS Batch Membership", diff --git a/community/public/css/style.css b/community/public/css/style.css index f874bbf3..a3c6296d 100644 --- a/community/public/css/style.css +++ b/community/public/css/style.css @@ -1,4 +1,5 @@ @import url("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.1/font/bootstrap-icons.css"); +@import url("https://use.fontawesome.com/releases/v5.13.0/css/all.css"); :root { --c1: #fefae0; @@ -61,6 +62,19 @@ body { color: var(--c2); } +.sidebar-batch { + background: var(--sidebar-bg); + color: var(--text-color); + position: fixed; + left: 0; + height: 100%; +} + +.sidebar-batch a { + padding: 16px 8px 8px 16px; + display: block; +} + .instructor { padding: 10px; } @@ -193,3 +207,29 @@ nav.navbar { padding: 20px; border-radius: 10px; } + +.dashboard__profile { + width: 150px; + height: 155px; + border-radius: 50%; +} + +.dashboard__profileSmall { + width: 59px; + height: 57px; + border-radius: 50%; +} + +.dashboard__abbr { + font-size: 50px; + width: 155px; + height: 155px; + border-radius: 50%; +} + +.dashboard__abbrSmall { + font-size: 20px; + width: 59px; + height: 57px; + border-radius: 50%; +} \ No newline at end of file diff --git a/community/www/courses/about/index.html b/community/www/courses/about/index.html new file mode 100644 index 00000000..ecfbafbf --- /dev/null +++ b/community/www/courses/about/index.html @@ -0,0 +1,13 @@ +{% extends "templates/base.html" %} +{% from "www/macros/sidebar.html" import Sidebar %} +{% block title %}About{% endblock %} +{% block head_include %} + + +{% endblock %} + +{% block content %} +{{ Sidebar(course, batch_code) }} +
+
+{% endblock %} diff --git a/community/www/courses/about/index.py b/community/www/courses/about/index.py new file mode 100644 index 00000000..03180785 --- /dev/null +++ b/community/www/courses/about/index.py @@ -0,0 +1,8 @@ +import frappe +from community.www.courses.utils import redirect_if_not_a_member + +def get_context(context): + context.no_cache = 1 + context.course = frappe.form_dict["course"] + context.batch_code = frappe.form_dict["batch"] + redirect_if_not_a_member(context.course, context.batch_code) \ No newline at end of file diff --git a/community/www/courses/course.html b/community/www/courses/course.html index 4f1e2467..c1ee4c76 100644 --- a/community/www/courses/course.html +++ b/community/www/courses/course.html @@ -110,7 +110,7 @@ {% endfor %} - Add a new batch + Add a new batch {% else %}

You are a mentor for this course.

diff --git a/community/www/courses/course.py b/community/www/courses/course.py index 57f8a9d0..c154477a 100644 --- a/community/www/courses/course.py +++ b/community/www/courses/course.py @@ -12,11 +12,14 @@ def get_context(context): context.course = get_course(course_id) context.batches = get_course_batches(context.course.name) + context.is_mentor = is_mentor(context.course.name) context.memberships = get_membership(context.batches) - context.upcoming_batches = [] if len(context.memberships) else get_upcoming_batches(context.course.name) + if len(context.memberships) and not context.is_mentor: + frappe.local.flags.redirect_location = "/courses/" + course_id + "/" + context.memberships[0].code + "/learn" + raise frappe.Redirect + context.upcoming_batches = get_upcoming_batches(context.course.name) context.instructor = get_instructor(context.course.owner) context.mentors = get_mentors(context.course.name) - context.is_mentor = is_mentor(context.course.name) if context.is_mentor: context.mentor_batches = get_mentor_batches(context.memberships) # Your Bacthes for mentor @@ -48,19 +51,13 @@ def get_batch_mentors(batches): batch.mentors.append(member) return batches -def get_discussions(batches): - messages = [] - memberships = get_membership(batches) - if len(memberships): - messages = get_messages(memberships[0].batch) - return messages, memberships - def get_membership(batches): memberships = [] member = frappe.db.get_value("Community Member", {"email": frappe.session.user}, "name") for batch in batches: membership = frappe.db.get_value("LMS Batch Membership", {"member": member, "batch": batch.name}, ["batch", "member", "member_type"], as_dict=1) if membership: + membership.code = batch.code memberships.append(membership) return memberships @@ -84,7 +81,7 @@ def get_mentors(course): return course_mentors def get_course_batches(course): - return frappe.get_all("LMS Batch", {"course": course}, ["name"]) + return frappe.get_all("LMS Batch", {"course": course}, ["name", "code"]) def get_mentor_batches(memberships): mentor_batches = [] diff --git a/community/www/courses/discuss/index.html b/community/www/courses/discuss/index.html new file mode 100644 index 00000000..c1695192 --- /dev/null +++ b/community/www/courses/discuss/index.html @@ -0,0 +1,13 @@ +{% extends "templates/base.html" %} +{% from "www/macros/sidebar.html" import Sidebar %} +{% block title %}Discuss{% endblock %} +{% block head_include %} + + +{% endblock %} + +{% block content %} +{{ Sidebar(course, batch_code) }} +
+
+{% endblock %} diff --git a/community/www/courses/discuss/index.py b/community/www/courses/discuss/index.py new file mode 100644 index 00000000..03180785 --- /dev/null +++ b/community/www/courses/discuss/index.py @@ -0,0 +1,8 @@ +import frappe +from community.www.courses.utils import redirect_if_not_a_member + +def get_context(context): + context.no_cache = 1 + context.course = frappe.form_dict["course"] + context.batch_code = frappe.form_dict["batch"] + redirect_if_not_a_member(context.course, context.batch_code) \ No newline at end of file diff --git a/community/www/courses/learn/index.html b/community/www/courses/learn/index.html new file mode 100644 index 00000000..61321fde --- /dev/null +++ b/community/www/courses/learn/index.html @@ -0,0 +1,13 @@ +{% extends "templates/base.html" %} +{% from "www/macros/sidebar.html" import Sidebar %} +{% block title %}Learn{% endblock %} +{% block head_include %} + + +{% endblock %} + +{% block content %} +{{ Sidebar(course, batch_code) }} +
+
+{% endblock %} diff --git a/community/www/courses/learn/index.js b/community/www/courses/learn/index.js new file mode 100644 index 00000000..0a6799eb --- /dev/null +++ b/community/www/courses/learn/index.js @@ -0,0 +1,3 @@ +frappe.ready(() => { + +}) \ No newline at end of file diff --git a/community/www/courses/learn/index.py b/community/www/courses/learn/index.py new file mode 100644 index 00000000..b69083d4 --- /dev/null +++ b/community/www/courses/learn/index.py @@ -0,0 +1,10 @@ +import frappe +from community.www.courses.utils import redirect_if_not_a_member + +def get_context(context): + context.no_cache = 1 + context.course = frappe.form_dict["course"] + context.batch_code = frappe.form_dict["batch"] + redirect_if_not_a_member(context.course, context.batch_code) + + print(context) \ No newline at end of file diff --git a/community/www/courses/members/index.html b/community/www/courses/members/index.html new file mode 100644 index 00000000..651b3aa8 --- /dev/null +++ b/community/www/courses/members/index.html @@ -0,0 +1,35 @@ +{% extends "templates/base.html" %} +{% from "www/macros/sidebar.html" import Sidebar %} +{% from "www/macros/profile.html" import Profile %} +{% block title %}Members{% endblock %} +{% block head_include %} + + +{% endblock %} + +{% block content %} +{{ Sidebar(course, batch_code) }} +
+
+

{{course.name}}

+
{{member_count}} members
+
+ +
+ {% for member in members %} +
+
+ {{ Profile(member.photo, member.full_name, member.abbr, "small") }} +
+
+ {{member.full_name}} +
+ {% if member.is_mentor %} +
Mentor
+ {% endif %} +
+
+ {% endfor %} +
+
+{% endblock %} \ No newline at end of file diff --git a/community/www/courses/members/index.py b/community/www/courses/members/index.py new file mode 100644 index 00000000..1ae3e266 --- /dev/null +++ b/community/www/courses/members/index.py @@ -0,0 +1,23 @@ +import frappe +from community.www.courses.utils import redirect_if_not_a_member, get_batch, get_member_with_name, get_course + +def get_context(context): + context.no_cache = 1 + context.course_slug = frappe.form_dict["course"] + context.course = get_course(context.course_slug) + context.batch_code = frappe.form_dict["batch"] + redirect_if_not_a_member(context.course_slug, context.batch_code) + context.batch = get_batch(context.batch_code) + context.members = get_members(context.batch) + context.member_count = len(context.members) + +def get_members(batch): + members = [] + memberships = frappe.get_all("LMS Batch Membership", {"batch": batch}, ["member", "member_type"]) + + for membership in memberships: + member = get_member_with_name(membership.member) + if membership.member_type == "Mentor": + member.is_mentor = True + members.append(member) + return members \ No newline at end of file diff --git a/community/www/courses/schedule/index.html b/community/www/courses/schedule/index.html new file mode 100644 index 00000000..8f3cff12 --- /dev/null +++ b/community/www/courses/schedule/index.html @@ -0,0 +1,13 @@ +{% extends "templates/base.html" %} +{% from "www/macros/sidebar.html" import Sidebar %} +{% block title %}Schedule{% endblock %} +{% block head_include %} + + +{% endblock %} + +{% block content %} +{{ Sidebar(course, batch_code) }} +
+
+{% endblock %} diff --git a/community/www/courses/schedule/index.py b/community/www/courses/schedule/index.py new file mode 100644 index 00000000..03180785 --- /dev/null +++ b/community/www/courses/schedule/index.py @@ -0,0 +1,8 @@ +import frappe +from community.www.courses.utils import redirect_if_not_a_member + +def get_context(context): + context.no_cache = 1 + context.course = frappe.form_dict["course"] + context.batch_code = frappe.form_dict["batch"] + redirect_if_not_a_member(context.course, context.batch_code) \ No newline at end of file diff --git a/community/www/courses/utils.py b/community/www/courses/utils.py new file mode 100644 index 00000000..424b88e1 --- /dev/null +++ b/community/www/courses/utils.py @@ -0,0 +1,36 @@ +import frappe + +def get_member_with_email(): + try: + return frappe.db.get_value("Community Member", {"email": frappe.session.user}, "name") + except frappe.DoesNotExistError: + return + +def get_member_with_name(name): + try: + return frappe.get_doc("Community Member", name) + except frappe.DoesNotExistError: + return + +def get_batch(code): + try: + return frappe.db.get_value("LMS Batch", {"code": code}, "name") + except frappe.DoesNotExistError: + return + +def is_member_of_batch(batch_code): + membership = frappe.get_all("LMS Batch Membership", {"batch": get_batch(batch_code), "member": get_member_with_email()}) + if len(membership): + return True + return False + +def redirect_if_not_a_member(course,batch_code): + if not is_member_of_batch(batch_code): + frappe.local.flags.redirect_location = "/courses/" + course + raise frappe.Redirect + +def get_course(slug): + try: + return frappe.db.get_value("LMS Course", {"slug": slug}, "name", as_dict=True) + except frappe.DoesNotExistError: + return \ No newline at end of file diff --git a/community/www/dashboard/index.html b/community/www/dashboard/index.html index b9358fb3..d0e86d16 100644 --- a/community/www/dashboard/index.html +++ b/community/www/dashboard/index.html @@ -1,5 +1,5 @@ {% extends "templates/base.html" %} -{% from "www/macros/profile.html" import profile %} +{% from "www/macros/profile.html" import Profile %} {% block title %}{{ _("Community") }}{% endblock %} {% block head_include %} @@ -91,7 +91,7 @@
- {{ profile(member.photo, member.full_name, member.abbr, "large")}} + {{ Profile(member.photo, member.full_name, member.abbr, "large")}}
@@ -125,7 +125,7 @@
- {{ profile(message.profile, message.full_name, message.abbr, "small")}} + {{ Profile(message.profile, message.full_name, message.abbr, "small")}}
{{ frappe.utils.md_to_html(message.message) }}
diff --git a/community/www/macros/profile.html b/community/www/macros/profile.html index 3e9ff5cb..c608b59f 100644 --- a/community/www/macros/profile.html +++ b/community/www/macros/profile.html @@ -1,12 +1,10 @@ -{% macro profile(photo, full_name, abbr, icon) %} +{% macro Profile(photo, full_name, abbr, icon) %} {% if photo %} -{{ full_name }} {% else %} -
-
- {{ abbr }} -
+
+ {{ abbr }}
{% endif %} {% endmacro %} \ No newline at end of file diff --git a/community/www/macros/sidebar.html b/community/www/macros/sidebar.html new file mode 100644 index 00000000..d0922924 --- /dev/null +++ b/community/www/macros/sidebar.html @@ -0,0 +1,12 @@ +{% macro Sidebar(course, batch_code) %} + +{% endmacro %} \ No newline at end of file diff --git a/community/www/profiles/profile.html b/community/www/profiles/profile.html index 6631f039..a6969dd5 100644 --- a/community/www/profiles/profile.html +++ b/community/www/profiles/profile.html @@ -1,5 +1,5 @@ {% extends "templates/web.html" %} -{% from "www/macros/profile.html" import profile %} +{% from "www/macros/profile.html" import Profile %} {% block head_include %} @@ -89,7 +89,7 @@
- {{ profile(member.photo, member.full_name, member.abbr, "large")}} + {{ Profile(member.photo, member.full_name, member.abbr, "large")}}