From 258ccb16429bf126bea81b964f12b015f8dd7066 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Mon, 12 Apr 2021 14:05:02 +0530 Subject: [PATCH] feat: dashboard --- .../community_member/community_member.json | 4 +- community/hooks.py | 3 +- community/www/conferences/index.html | 41 ---- community/www/conferences/index.py | 8 - community/www/dashboard/index.html | 221 ++++++++++++++++++ community/www/dashboard/index.py | 41 ++++ 6 files changed, 266 insertions(+), 52 deletions(-) delete mode 100644 community/www/conferences/index.html delete mode 100644 community/www/conferences/index.py create mode 100644 community/www/dashboard/index.html create mode 100644 community/www/dashboard/index.py diff --git a/community/community/doctype/community_member/community_member.json b/community/community/doctype/community_member/community_member.json index 1b45eeb6..234bcecd 100644 --- a/community/community/doctype/community_member/community_member.json +++ b/community/community/doctype/community_member/community_member.json @@ -2,7 +2,7 @@ "actions": [], "allow_guest_to_view": 1, "allow_rename": 1, - "autoname": "field:username", + "autoname": "field:email", "creation": "2021-02-12 15:47:23.591567", "doctype": "DocType", "editable_grid": 1, @@ -108,7 +108,7 @@ "has_web_view": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2021-03-30 17:25:57.075151", + "modified": "2021-04-12 13:34:41.573486", "modified_by": "Administrator", "module": "Community", "name": "Community Member", diff --git a/community/hooks.py b/community/hooks.py index 048b98b5..5a26ac85 100644 --- a/community/hooks.py +++ b/community/hooks.py @@ -134,7 +134,8 @@ primary_rules = [ {"from_route": "/courses//", "to_route": "courses/topic"}, {"from_route": "/hackathons", "to_route": "hackathons"}, {"from_route": "/hackathons/", "to_route": "hackathons/hackathon"}, - {"from_route": "/hackathons//", "to_route": "hackathons/project"} + {"from_route": "/hackathons//", "to_route": "hackathons/project"}, + {"from_route": "/dashboard", "to_route": ""} ] # Any frappe default URL is blocked by profile-rules, add it here to unblock it diff --git a/community/www/conferences/index.html b/community/www/conferences/index.html deleted file mode 100644 index d30d4018..00000000 --- a/community/www/conferences/index.html +++ /dev/null @@ -1,41 +0,0 @@ -{% extends "templates/base.html" %} -{% block title %}{{ 'Hackathons' }}{% endblock %} -{% from "www/hackathons/macros/card.html" import hackathon_card %} -{% from "www/hackathons/macros/card.html" import null_card %} -{% block head_include %} - - - -{% endblock %} - -{% block content %} -
-
-

{{ 'Conferences' }}

-
-
-
- {% for conference in conferences %} - - {% endfor %} - {% if conferences %} - {% for n in range( (3 - (conferences|length)) %3) %} - {{ null_card() }} - {% endfor %} - {% endif %} -
-
-
-{% endblock %} \ No newline at end of file diff --git a/community/www/conferences/index.py b/community/www/conferences/index.py deleted file mode 100644 index dde65467..00000000 --- a/community/www/conferences/index.py +++ /dev/null @@ -1,8 +0,0 @@ -import frappe - -def get_context(context): - context.no_cache = 1 - context.conferences = get_conferences() - -def get_conferences(): - return frappe.get_all("Community Conference", fields=["name", "live_stream_url"]) \ No newline at end of file diff --git a/community/www/dashboard/index.html b/community/www/dashboard/index.html new file mode 100644 index 00000000..7c10462a --- /dev/null +++ b/community/www/dashboard/index.html @@ -0,0 +1,221 @@ +{% extends "templates/base.html" %} +{% block title %}{{ _("Community") }}{% endblock %} +{% block head_include %} + + + +{% endblock %} + +{% macro profile(photo, full_name, abbr, icon) %} +{% if photo %} +{{ full_name }} +{% else %} +
+
+ {{ abbr }} +
+
+{% endif %} +{% endmacro %} + +{% block content %} +
+
+
+ {{ profile(member.photo, member.full_name, abbr, "large")}} +
+
+
+ {{member.full_name}} +
+
+ +
+
+
+
+
+ {% if activity %} + {% for message in activity %} +
+
+ {{ message.course }} ({{message.batch}}) +
+
+
+ {{ profile(message.profile, message.full_name, message.abbr, "small")}} +
+
{{ frappe.utils.md_to_html(message.message) }}
+
+
+
+ {{message.full_name}} +
+
+ {{ frappe.utils.pretty_date(message.creation) }} +
+
+
+ {% endfor %} + {% else %} +

You have not received any messages yet.

+ {% endif %} +
+
+
+
+ Create a New Sketch +
+ {% if sketches %} + {% for sketch in sketches %} +
+
+ + +
+
+ {% endfor %} + {% else %} +

You have not created any sketches.

+ {% endif %} +
+
+
+
+ {% if courses %} +

Your Courses

+
+ {% for course in courses %} +
+
+
{{ course.name }}
+ {% if course.member_type %} +
+ {{ course.member_type }} +
+ {% endif %} +
+
+ {{ frappe.utils.md_to_html(course.description) }} +
+
Joined {{ frappe.utils.pretty_date(course.joining) }}
+
+ {% endfor %} + {% else %} +

You are not a member of any course yet. Checkout our Courses.

+ {% endif %} +
+
+
+
+
+
+ +
+{% endblock %} \ No newline at end of file diff --git a/community/www/dashboard/index.py b/community/www/dashboard/index.py new file mode 100644 index 00000000..4e8a0076 --- /dev/null +++ b/community/www/dashboard/index.py @@ -0,0 +1,41 @@ +import frappe +from ...lms.doctype.lms_sketch.lms_sketch import get_recent_sketches + +def get_context(context): + context.no_cache = 1 + context.member = frappe.get_all("Community Member", {"email": frappe.session.user}, ["name", "email", "photo", "full_name"])[0] + context.abbr = "".join([s[0] for s in context.member.full_name.split()]) + 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())) + print(context) +def get_memberships(member): + 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 + +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 = frappe.db.get_value("Community Member", message.author, ["photo", "full_name"]) + if not message.profile: + message.abbr = "".join([s[0] for s in message.full_name.split()]) + return messages \ No newline at end of file