feat: zoom attendance
This commit is contained in:
@@ -116,6 +116,7 @@ scheduler_events = {
|
||||
"lms.lms.doctype.lms_certificate_request.lms_certificate_request.schedule_evals",
|
||||
"lms.lms.api.update_course_statistics",
|
||||
"lms.lms.doctype.lms_certificate_request.lms_certificate_request.mark_eval_as_completed",
|
||||
"lms.lms.doctype.lms_live_class.lms_live_class.update_attendance",
|
||||
],
|
||||
"daily": [
|
||||
"lms.job.doctype.job_opportunity.job_opportunity.update_job_openings",
|
||||
|
||||
@@ -183,6 +183,8 @@ def create_live_class(
|
||||
"doctype": "LMS Live Class",
|
||||
"start_url": data.get("start_url"),
|
||||
"join_url": data.get("join_url"),
|
||||
"meeting_id": data.get("id"),
|
||||
"uuid": data.get("uuid"),
|
||||
"title": title,
|
||||
"host": frappe.session.user,
|
||||
"date": date,
|
||||
|
||||
@@ -20,8 +20,13 @@
|
||||
"description",
|
||||
"column_break_spvt",
|
||||
"event",
|
||||
"password",
|
||||
"auto_recording",
|
||||
"section_break_fhet",
|
||||
"meeting_id",
|
||||
"uuid",
|
||||
"column_break_aony",
|
||||
"attendees",
|
||||
"password",
|
||||
"section_break_yrpq",
|
||||
"start_url",
|
||||
"column_break_yokr",
|
||||
@@ -137,13 +142,42 @@
|
||||
"label": "Zoom Account",
|
||||
"options": "LMS Zoom Settings",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "meeting_id",
|
||||
"fieldtype": "Data",
|
||||
"label": "Meeting ID"
|
||||
},
|
||||
{
|
||||
"fieldname": "attendees",
|
||||
"fieldtype": "Int",
|
||||
"label": "Attendees",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_fhet",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "uuid",
|
||||
"fieldtype": "Data",
|
||||
"label": "UUID"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_aony",
|
||||
"fieldtype": "Column Break"
|
||||
}
|
||||
],
|
||||
"grid_page_length": 50,
|
||||
"in_create": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2025-05-26 13:23:38.209187",
|
||||
"links": [
|
||||
{
|
||||
"link_doctype": "LMS Live Class Participant",
|
||||
"link_fieldname": "live_class"
|
||||
}
|
||||
],
|
||||
"modified": "2025-05-27 14:44:35.679712",
|
||||
"modified_by": "sayali@frappe.io",
|
||||
"module": "LMS",
|
||||
"name": "LMS Live Class",
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
import requests
|
||||
import json
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from datetime import timedelta
|
||||
from frappe.utils import cint, get_datetime, format_date, nowdate, format_time
|
||||
from lms.lms.doctype.lms_batch.lms_batch import authenticate
|
||||
|
||||
|
||||
class LMSLiveClass(Document):
|
||||
@@ -102,3 +105,56 @@ def send_mail(live_class, student):
|
||||
args=args,
|
||||
header=[_(f"Class Reminder: {live_class.title}"), "orange"],
|
||||
)
|
||||
|
||||
|
||||
def update_attendance():
|
||||
past_live_classes = frappe.get_all(
|
||||
"LMS Live Class",
|
||||
{
|
||||
"uuid": ["is", "set"],
|
||||
"attendees": ["is", "not set"],
|
||||
},
|
||||
["name", "uuid", "zoom_account"],
|
||||
)
|
||||
|
||||
for live_class in past_live_classes:
|
||||
attendance_data = get_attendance(live_class)
|
||||
create_attendance(live_class, attendance_data)
|
||||
update_attendees_count(live_class, attendance_data)
|
||||
|
||||
|
||||
def get_attendance(live_class):
|
||||
headers = {
|
||||
"Authorization": "Bearer " + authenticate(live_class.zoom_account),
|
||||
"content-type": "application/json",
|
||||
}
|
||||
|
||||
encoded_uuid = requests.utils.quote(live_class.uuid, safe="")
|
||||
response = requests.get(
|
||||
f"https://api.zoom.us/v2/past_meetings/{encoded_uuid}/participants", headers=headers
|
||||
)
|
||||
|
||||
if response.status_code != 200:
|
||||
frappe.throw(
|
||||
_("Failed to fetch attendance data from Zoom for class {0}: {1}").format(
|
||||
live_class, response.text
|
||||
)
|
||||
)
|
||||
|
||||
data = response.json()
|
||||
return data.get("participants", [])
|
||||
|
||||
|
||||
def create_attendance(live_class, data):
|
||||
for participant in data:
|
||||
doc = frappe.new_doc("LMS Live Class Participant")
|
||||
doc.live_class = live_class.name
|
||||
doc.member = participant.get("user_email")
|
||||
doc.joined_at = participant.get("join_time")
|
||||
doc.left_at = participant.get("leave_time")
|
||||
doc.duration = participant.get("duration")
|
||||
doc.insert()
|
||||
|
||||
|
||||
def update_attendees_count(live_class, data):
|
||||
frappe.db.set_value("LMS Live Class", live_class.name, "attendees", len(data))
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2025, Frappe and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("LMS Live Class Participant", {
|
||||
// refresh(frm) {
|
||||
|
||||
// },
|
||||
// });
|
||||
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"creation": "2025-05-27 12:09:57.712221",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"live_class",
|
||||
"joined_at",
|
||||
"column_break_dwbm",
|
||||
"duration",
|
||||
"left_at",
|
||||
"section_break_xczy",
|
||||
"member",
|
||||
"member_name",
|
||||
"column_break_bpjn",
|
||||
"member_image",
|
||||
"member_username"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "live_class",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Live Class",
|
||||
"options": "LMS Live Class",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "member",
|
||||
"fieldtype": "Link",
|
||||
"in_standard_filter": 1,
|
||||
"label": "Member",
|
||||
"options": "User",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "member.full_name",
|
||||
"fieldname": "member_name",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Member Name"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_dwbm",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "duration",
|
||||
"fieldtype": "Int",
|
||||
"in_list_view": 1,
|
||||
"label": "Duration",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "joined_at",
|
||||
"fieldtype": "Datetime",
|
||||
"label": "Joined At",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "left_at",
|
||||
"fieldtype": "Datetime",
|
||||
"label": "Left At",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_xczy",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_bpjn",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fetch_from": "member.user_image",
|
||||
"fieldname": "member_image",
|
||||
"fieldtype": "Attach Image",
|
||||
"label": "Member Image"
|
||||
},
|
||||
{
|
||||
"fetch_from": "member.username",
|
||||
"fieldname": "member_username",
|
||||
"fieldtype": "Data",
|
||||
"label": "Member Username"
|
||||
}
|
||||
],
|
||||
"grid_page_length": 50,
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2025-05-27 22:32:24.196643",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Live Class Participant",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"row_format": "Dynamic",
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"title_field": "member_name"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2025, Frappe and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class LMSLiveClassParticipant(Document):
|
||||
pass
|
||||
@@ -0,0 +1,30 @@
|
||||
# Copyright (c) 2025, Frappe and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
|
||||
# On IntegrationTestCase, the doctype test records and all
|
||||
# link-field test record dependencies are recursively loaded
|
||||
# Use these module variables to add/remove to/from that list
|
||||
EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
|
||||
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
|
||||
|
||||
|
||||
class UnitTestLMSLiveClassParticipant(UnitTestCase):
|
||||
"""
|
||||
Unit tests for LMSLiveClassParticipant.
|
||||
Use this class for testing individual functions and methods.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class IntegrationTestLMSLiveClassParticipant(IntegrationTestCase):
|
||||
"""
|
||||
Integration tests for LMSLiveClassParticipant.
|
||||
Use this class for testing interactions between multiple components.
|
||||
"""
|
||||
|
||||
pass
|
||||
Reference in New Issue
Block a user