นี่เป็นคำแนะนำแบบทีละขั้นที่ 5 ในชุดคำแนะนำแบบทีละขั้นเกี่ยวกับส่วนเสริมของ Classroom
ในคำแนะนำแบบทีละขั้นนี้ คุณได้แก้ไขตัวอย่างจากขั้นตอนก่อนหน้าแบบทีละขั้นเพื่อสร้างไฟล์แนบประเภทกิจกรรม ซึ่งเป็นไฟล์แนบที่นักเรียนต้องส่งงาน เช่น เป็นการเขียนตอบ แบบทดสอบ หรืออาร์ติแฟกต์อื่นๆ ที่นักเรียนสร้างขึ้น
ความแตกต่างระหว่างไฟล์แนบประเภทเนื้อหากับประเภทกิจกรรมเป็นสิ่งสำคัญ ไฟล์แนบประเภทกิจกรรมจะแตกต่างจากประเภทเนื้อหาดังนี้
- ปุ่ม "ส่ง" จะปรากฏขึ้นที่ด้านขวาบนของ iframe มุมมองของนักเรียน
- ซึ่งมีตัวระบุที่ไม่ซ้ำกันสำหรับงานของนักเรียน
- โดยการ์ดไฟล์แนบจะปรากฏใน UI ผู้ให้คะแนนของ Classroom
- โดยสามารถกำหนดคะแนนสำหรับงานที่ตนอยู่
ดูคำแนะนำแบบทีละขั้นถัดไปสำหรับการสนทนาเกี่ยวกับการให้คะแนน ระหว่างขั้นตอนวิธีการนี้ คุณได้ทำตามขั้นตอนต่อไปนี้
- แก้ไขคำขอสร้างไฟล์แนบก่อนหน้านี้ที่ส่งไปยัง Classroom API เพื่อสร้างไฟล์แนบประเภทกิจกรรม
- ใช้พื้นที่เก็บข้อมูลถาวรสำหรับงานที่นักเรียนส่ง
- แก้ไขเส้นทางมุมมองของนักเรียนก่อนหน้านี้เพื่อยอมรับข้อมูลที่นักเรียนป้อน
- ระบุเส้นทางที่จะแสดง iframe การตรวจสอบงานของนักเรียน
เมื่อเสร็จแล้ว คุณสามารถสร้างไฟล์แนบประเภทกิจกรรมในงานผ่าน UI ของ Google Classroom เมื่อเข้าสู่ระบบในฐานะครู นักเรียนในชั้นเรียนยังสามารถ ทำกิจกรรมใน iframe และส่งคำตอบ โดยครูจะดูงานที่นักเรียนส่งได้ใน UI การให้คะแนนของ Classroom
สำหรับวัตถุประสงค์ของตัวอย่างนี้ ให้นำเทมเพลตไฟล์แนบจากคำแนะนำแบบทีละขั้นที่แล้วไปใช้ซ้ำซึ่งแสดงภาพสถานที่สำคัญที่มีชื่อเสียงพร้อมคำอธิบายพร้อมชื่อของจุดสังเกต กิจกรรมดังกล่าวจะประกอบด้วยการแจ้งให้นักเรียน ระบุชื่อจุดสังเกต
แก้ไขคำขอสร้างไฟล์แนบ
ไปที่ส่วนของโค้ดที่คุณสร้างไฟล์แนบประเภทเนื้อหาในคำแนะนำแบบทีละขั้นก่อนหน้านี้ รายการคีย์ในที่นี้คืออินสแตนซ์ของออบเจ็กต์ AddOnAttach ซึ่งก่อนหน้านี้เราได้ระบุ teacherViewUri
, studentViewUri
และ title
สำหรับไฟล์แนบ
แม้ว่าไฟล์แนบของส่วนเสริมทั้งหมดจะต้องใช้ทั้ง 3 ช่อง แต่การมีหรือไม่มี studentWorkReviewUri
จะเป็นตัวกำหนดว่าไฟล์แนบนั้นเป็นประเภทกิจกรรมหรือประเภทเนื้อหา คำขอ CREATE
ที่มีการป้อนข้อมูล studentWorkReviewUri
จะกลายเป็นไฟล์แนบประเภทกิจกรรม ส่วนคำขอ CREATE
ที่ไม่มี studentWorkReviewUri
จะกลายเป็นไฟล์แนบประเภทเนื้อหา
การแก้ไขเพียงอย่างเดียวที่ทำกับคำขอนี้คือการป้อนข้อมูลในช่อง studentWorkReviewUri
เพิ่มเส้นทางที่มีชื่อเหมาะสมที่นี่
เพื่อนำไปใช้ในขั้นตอนถัดไป
Python
ในตัวอย่างที่ให้ไว้ ไฟล์นี้อยู่ในเมธอด create_attachments
ในไฟล์ webapp/attachment_routes.py
attachment = {
# Specifies the route for a teacher user.
"teacherViewUri": {
"uri":
flask.url_for(
"load_activity_attachment",
_scheme='https',
_external=True),
},
# Specifies the route for a student user.
"studentViewUri": {
"uri":
flask.url_for(
"load_activity_attachment",
_scheme='https',
_external=True)
},
# Specifies the route for a teacher user when the attachment is
# loaded in the Classroom grading view.
# The presence of this field marks this as an activity-type attachment.
"studentWorkReviewUri": {
"uri":
flask.url_for(
"view_submission", _scheme='https', _external=True)
},
# The title of the attachment.
"title": f"Attachment {attachment_count}",
}
เพิ่มพื้นที่เก็บข้อมูลถาวรสำหรับไฟล์แนบประเภทเนื้อหา
บันทึกคำตอบที่นักเรียนมีต่อกิจกรรมของเรา คุณจะดูงานได้ในภายหลัง เมื่อครูดูงานที่ส่งใน iframe งานของนักเรียน
ตั้งค่าสคีมาฐานข้อมูลสำหรับ Submission
ตัวอย่างที่ยกมานี้คาดหวังให้นักเรียนป้อนชื่อจุดสังเกตที่แสดงในรูปภาพ Submission
จึงมีแอตทริบิวต์ต่อไปนี้
attachment_id
: ตัวระบุที่ไม่ซ้ำกันสำหรับไฟล์แนบ Classroom มอบหมายและส่งคืนในคำตอบเมื่อสร้างไฟล์แนบsubmission_id
: ตัวระบุสำหรับงานที่นักเรียนส่ง Classroom มอบหมายและส่งคืนในคำตอบgetAddOnContext
ในมุมมองของนักเรียน
student_response
: คำตอบที่นักเรียนให้ไว้
Python
ขยายการใช้งาน SQLite และ flask_sqlalchemy
จากขั้นตอนก่อนหน้า
ไปยังไฟล์ที่คุณได้กำหนดตารางก่อนหน้าไว้
(models.py
หากคุณทำตามตัวอย่างที่ให้ไว้) เพิ่มโค้ดต่อไปนี้ที่ด้านล่างของไฟล์
# Database model to represent a student submission.
class Submission(db.Model):
# The attachmentId is the unique identifier for the attachment.
submission_id = db.Column(db.String(120), primary_key=True)
# The unique identifier for the student's submission.
attachment_id = db.Column(db.String(120), primary_key=True)
# The student's response to the question prompt.
student_response = db.Column(db.String(120))
ให้นำเข้าคลาส Submission
ใหม่ไปยังไฟล์เซิร์ฟเวอร์พร้อมเส้นทางการจัดการไฟล์แนบ
แก้ไขเส้นทางมุมมองของนักเรียน
จากนั้นแก้ไขเส้นทางมุมมองของนักเรียนก่อนหน้านี้เพื่อแสดงแบบฟอร์มขนาดเล็กและยอมรับข้อมูลจากนักเรียน คุณสามารถใช้โค้ดส่วนใหญ่จากคำแนะนำแบบทีละขั้นได้
ค้นหารหัสเซิร์ฟเวอร์ที่มีเส้นทางสำหรับมุมมองของนักเรียน นี่คือเส้นทางที่ระบุในช่อง studentViewUri
เมื่อสร้างไฟล์แนบ
การเปลี่ยนแปลงแรกที่ต้องทำคือการแยก submissionId
ออกจากการตอบกลับ getAddOnContext
Python
ในตัวอย่างที่ให้ไว้ ค่านี้อยู่ในเมธอด load_activity_attachment
ในไฟล์ webapp/attachment_routes.py
# Issue a request to the courseWork.getAddOnContext endpoint
addon_context_response = classroom_service.courses().courseWork(
).getAddOnContext(
courseId=flask.session["courseId"],
itemId=flask.session["itemId"]).execute()
# One of studentContext or teacherContext will be populated.
user_context = "student" if addon_context_response.get(
"studentContext") else "teacher"
# If the user is a student...
if user_context == "student":
# Extract the submissionId from the studentContext object.
# This value is provided by Google Classroom.
flask.session["submissionId"] = addon_context_response.get(
"studentContext").get("submissionId")
นอกจากนี้คุณอาจต้องการส่งคำขอรับสถานะการส่งงานของนักเรียน
คำตอบจะมีค่า SubmissionState
ซึ่งระบุสถานะต่างๆ เช่น นักเรียนได้เปิดไฟล์แนบหรือส่งไฟล์แนบแล้ว วิธีการนี้อาจเป็นประโยชน์ในกรณีที่คุณต้องการยกเลิกการอนุญาตให้แก้ไขงานที่ส่งไปแล้ว หรือหากต้องการให้ข้อมูลเชิงลึกแก่ครูเกี่ยวกับความคืบหน้าของนักเรียน
Python
ในตัวอย่างที่เราให้ไว้ นี่คือความต่อเนื่องของเมธอด load_activity_attachment
ด้านบน
# Issue a request to get the status of the student submission.
submission_response = classroom_service.courses().courseWork(
).addOnAttachments().studentSubmissions().get(
courseId=flask.session["courseId"],
itemId=flask.session["itemId"],
attachmentId=flask.session["attachmentId"],
submissionId=flask.session["submissionId"]).execute()
สุดท้าย ดึงข้อมูลไฟล์แนบจากฐานข้อมูลและแสดงแบบฟอร์มอินพุต แบบฟอร์มในตัวอย่างที่ให้ไว้ประกอบด้วยช่องป้อนสตริงและปุ่มส่ง แสดงภาพจุดสังเกตและแจ้งให้นักเรียนป้อนชื่อ เมื่อมีผู้ให้คำตอบแล้ว ให้บันทึกไว้ในฐานข้อมูลของเรา
Python
ในตัวอย่างที่เราให้ไว้ นี่คือความต่อเนื่องของเมธอด load_activity_attachment
ด้านบน
# Look up the attachment in the database.
attachment = Attachment.query.get(flask.session["attachmentId"])
message_str = f"I see that you're a {user_context}! "
message_str += (
f"I've loaded the attachment with ID {attachment.attachment_id}. "
if user_context == "teacher" else
"Please complete the activity below.")
form = activity_form_builder()
if form.validate_on_submit():
# Record the student's response in our database.
# Check if the student has already submitted a response.
# If so, update the response stored in the database.
student_submission = Submission.query.get(flask.session["submissionId"])
if student_submission is not None:
student_submission.student_response = form.student_response.data
else:
# Store the student's response by the submission ID.
new_submission = Submission(
submission_id=flask.session["submissionId"],
attachment_id=flask.session["attachmentId"],
student_response=form.student_response.data)
db.session.add(new_submission)
db.session.commit()
return flask.render_template(
"acknowledge-submission.html",
message="Your response has been recorded. You can close the " \
"iframe now.",
instructions="Please Turn In your assignment if you have " \
"completed all tasks."
)
# Show the activity.
return flask.render_template(
"show-activity-attachment.html",
message=message_str,
image_filename=attachment.image_filename,
image_caption=attachment.image_caption,
user_context=user_context,
form=form,
responses=response_strings)
เพื่อแยกความแตกต่างระหว่างผู้ใช้รายต่างๆ ให้พิจารณาปิดใช้ฟังก์ชันการส่งและแสดงคำตอบที่ถูกต้องในมุมมองของครูแทน
เพิ่มเส้นทางสำหรับ iframe การตรวจสอบงานของนักเรียน
สุดท้าย ให้เพิ่มเส้นทางเพื่อแสดง iframe การตรวจสอบงานของนักเรียน ชื่อของเส้นทางนี้ควรตรงกับชื่อสำหรับ studentWorkReviewUri
เมื่อสร้างไฟล์แนบ เส้นทางนี้จะเปิดขึ้นเมื่อครูดูงานที่นักเรียนส่งใน UI การให้คะแนนของ Classroom
คุณจะได้รับพารามิเตอร์การค้นหา submissionId
เมื่อ Classroom
เปิด iframe การตรวจสอบงานของนักเรียน ให้ใช้หน้านี้เพื่อเรียกงานของนักเรียนจากฐานข้อมูลในเครื่อง
Python
ในตัวอย่างที่เราให้ไว้ ไฟล์นี้อยู่ในไฟล์ webapp/attachment_routes.py
@app.route("/view-submission")
def view_submission():
"""
Render a student submission using the show-student-submission.html template.
"""
# Save the query parameters passed to the iframe in the session, just as we did
# in previous routes. Abbreviated here for readability.
add_iframe_query_parameters_to_session(flask.request.args)
# For the sake of brevity in this example, we'll skip the conditional logic
# to see if we need to authorize the user as we have done in previous steps.
# We can assume that the user that reaches this route is a teacher that has
# already authorized and created an attachment using the add-on.
# In production, we recommend fully validating the user's authorization at
# this stage as well.
# Look up the student's submission in our database.
student_submission = Submission.query.get(flask.session["submissionId"])
# Look up the attachment in the database.
attachment = Attachment.query.get(student_submission.attachment_id)
# Render the student's response alongside the correct answer.
return flask.render_template(
"show-student-submission.html",
message=f"Loaded submission {student_submission.submission_id} for "\
f"attachment {attachment.attachment_id}.",
student_response=student_submission.student_response,
correct_answer=attachment.image_caption)
ทดสอบส่วนเสริม
ทําซ้ำขั้นตอนทดสอบส่วนเสริมจากคําแนะนําแบบทีละขั้นก่อนหน้านี้ ซึ่งคุณควรมีไฟล์แนบที่นักเรียนเปิดได้
ทําตามขั้นตอนต่อไปนี้เพื่อทดสอบไฟล์แนบของกิจกรรม
- ลงชื่อเข้าใช้ Google Classroom เป็นหนึ่งในผู้ใช้ทดสอบของนักเรียนในชั้นเรียนเดียวกันกับผู้ใช้แบบทดสอบสำหรับครู
- ไปที่แท็บงานของชั้นเรียนและขยายการทดสอบงาน
- คลิกการ์ดไฟล์แนบของส่วนเสริมเพื่อเปิดมุมมองของนักเรียนและส่งคำตอบสำหรับกิจกรรม
- ปิด iframe หลังจากทำกิจกรรมเสร็จ คลิกปุ่มส่ง (ไม่บังคับ)
คุณไม่น่าจะเห็นการเปลี่ยนแปลงใน Classroom หลังจากที่ทำกิจกรรมเสร็จแล้ว ตอนนี้ให้ทดสอบ iframe การทบทวนงานของนักเรียน โดยทำดังนี้
- ลงชื่อเข้าใช้ Classroom ในฐานะผู้ใช้ทดสอบครู
- ค้นหาคอลัมน์สำหรับงานทดสอบในแท็บเกรด คลิกชื่องานทดสอบ
- ค้นหาการ์ดสำหรับผู้ใช้ที่เป็นนักเรียนทดสอบ คลิกไฟล์แนบในการ์ด
ยืนยันว่าข้อมูลที่ส่งนั้นปรากฏต่อนักเรียนอย่างถูกต้อง
ยินดีด้วย คุณพร้อมดำเนินการต่อในขั้นตอนถัดไปแล้ว นั่นคือ การซิงค์คะแนนไฟล์แนบ