活動類型附件

這是 Classroom 外掛程式的第 5 個逐步操作說明 這一系列的影片

在本逐步操作說明中,您將修改上一個逐步操作說明步驟中的範例 產生活動類型附件。這些是 要求學生繳交,例如書面回覆、測驗等 學生產生的成果。

請務必區分內容類型和活動類型附件。 活動類型附件與內容類型有以下差異:

  • 「繳交」學生檢視畫面 iframe 的右上方。
  • 這類 ID 會提供學生作業的專屬 ID。
  • 學生的附件卡會顯示在 Classroom 評分工具 UI 中。
  • 也可以設定作業成績。

請參閱下逐步操作說明,瞭解如何評分。課程中 請完成下列操作步驟:

  • 將先前的附件建立要求修改為 使用 Classroom API 建立活動類型的附件。
  • 為學生繳交的作業建立永久儲存空間。
  • 修改先前的「學生檢視」路徑,接受學生輸入的內容。
  • 提供提供學生工作回顧 iframe 的路線。

完成後,您可以透過操作,在作業上建立活動類型附件。 Google Classroom UI。課程學生可以 還要在 iframe 中完成活動並提交回應。老師可以 在 Classroom 評分 UI 中查看學生繳交的作業。

為了達成本例,請重複使用 先前的逐步操作說明,顯示知名地標的圖片和說明文字 替換為地標名稱活動包括提示學生 提供地標的名稱

修改連結建立要求

前往您在程式碼中建立內容類型的區段 附件。這裡的鍵是 AddOnAttachment 物件,也就是我們先前指定 teacherViewUri 的物件, studentViewUrititle 做為附件。

雖然所有外掛程式附件都需要以下三個欄位, 缺少 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:附件的專屬 ID。指派者 Classroom 會在建立 附件。
  • submission_id:學生繳交作業的 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 欄位中指定的路徑。 第一項變更是將 submissionIdgetAddOnContext 回應

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 提供的路徑相符 附加檔案。老師在以下位置查看學生繳交的作業後,系統就會開啟這個路徑: Classroom 評分工具 UI。

您會在 Classroom 中收到 submissionId 查詢參數 開啟學生作業檢閱 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。
  • 在「成績」分頁中,找到測試作業的資料欄。按一下 測試作業的名稱
  • 找出測試學生使用者的資訊卡。按一下卡片上的附件。

確認系統向學生顯示正確的作業。

恭喜!您可以進行下一個步驟:正在同步處理附件 成績